1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import static org.junit.Assert.assertFalse;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.junit.Test;
25 import org.kuali.rice.ksb.api.bus.support.JavaServiceDefinition;
26 import org.kuali.rice.ksb.api.bus.support.RestServiceDefinition;
27 import org.kuali.rice.ksb.test.KSBTestCase;
28
29
30
31
32
33
34
35
36 public class RestServiceDefinitionTest extends KSBTestCase {
37
38 private RestServiceDefinition restDefinition;
39 private RestServiceDefinition sameExactRestDefinition;
40 private RestServiceDefinition otherRestDefinition;
41 private RestServiceDefinition otherNameRestDefinition;
42 private RestServiceDefinition otherServiceRestDefinition;
43 private RestServiceDefinition singleResourceDefinition;
44 private JavaServiceDefinition javaServiceDefinition;
45
46 public void setUp() throws Exception {
47 super.setUp();
48
49 String a = "a";
50 String b = "b";
51 String c = "c";
52 Long l = Long.valueOf(123l);
53
54 List<Object> restResources = new ArrayList<Object>();
55 restResources.add(a);
56 restResources.add(b);
57
58 List<Object> sameExactRestResources = new ArrayList<Object>();
59 sameExactRestResources.add(a);
60 sameExactRestResources.add(b);
61
62
63 List<Object> functionallySameResources = new ArrayList<Object>();
64 functionallySameResources.add(b);
65 functionallySameResources.add(c);
66
67 List<Object> otherRestResources = new ArrayList<Object>();
68 otherRestResources.add(l);
69 otherRestResources.add(b);
70
71 Object service = new ArrayList<Object>();
72
73 this.restDefinition = new RestServiceDefinition();
74 this.restDefinition.setLocalServiceName("restServiceName");
75 this.restDefinition.setResources(restResources);
76 this.restDefinition.validate();
77
78 this.sameExactRestDefinition = new RestServiceDefinition();
79 this.sameExactRestDefinition.setLocalServiceName("restServiceName");
80 this.sameExactRestDefinition.setResources(sameExactRestResources);
81 this.sameExactRestDefinition.validate();
82
83 this.otherRestDefinition = new RestServiceDefinition();
84 this.otherRestDefinition.setLocalServiceName("restServiceName");
85 this.otherRestDefinition.setResources(otherRestResources);
86 this.otherRestDefinition.validate();
87
88 this.otherNameRestDefinition = new RestServiceDefinition();
89 this.otherNameRestDefinition.setLocalServiceName("anotherRestServiceName");
90 this.otherNameRestDefinition.setResources(sameExactRestResources);
91 this.otherNameRestDefinition.validate();
92
93 this.otherServiceRestDefinition = new RestServiceDefinition();
94 this.otherServiceRestDefinition.setLocalServiceName("restServiceName");
95 this.otherServiceRestDefinition.setService(service);
96 this.otherServiceRestDefinition.setResources(restResources);
97 this.otherServiceRestDefinition.validate();
98
99 this.singleResourceDefinition = new RestServiceDefinition();
100 this.singleResourceDefinition.setLocalServiceName("restServiceName");
101 this.singleResourceDefinition.setService(service);
102 this.singleResourceDefinition.validate();
103
104 javaServiceDefinition = new JavaServiceDefinition();
105 javaServiceDefinition.setBusSecurity(Boolean.FALSE);
106 javaServiceDefinition.setLocalServiceName("restServiceName");
107 javaServiceDefinition.setService(service);
108 javaServiceDefinition.validate();
109 }
110
111 @Test
112 public void testIsSameSuccessWithSameDefinition() {
113 assertTrue(this.restDefinition.equals(this.restDefinition));
114 }
115
116 @Test
117 public void testIsSameSuccessWithDifferentDefinition() throws Exception {
118 assertTrue(this.restDefinition.equals(sameExactRestDefinition));
119 }
120
121 @Test
122 public void testIsSameFailureWithDifferentServiceClass() throws Exception {
123 assertFalse(this.restDefinition.equals(otherRestDefinition));
124 }
125
126 @Test
127 public void testIsSameFailureWithDifferentDefinitionOfSameResources() throws Exception {
128 assertFalse(this.restDefinition.equals(otherNameRestDefinition));
129 }
130
131 @Test
132 public void testIsSameFailureWithDifferentService() throws Exception {
133 assertFalse(this.restDefinition.equals(otherServiceRestDefinition));
134 }
135
136 @Test
137 public void testIsSameFailureWithSingleResourceService() throws Exception {
138 assertFalse(this.restDefinition.equals(singleResourceDefinition));
139 }
140
141 @Test
142 public void testIsSameFailureWithDifferentServiceDefinitionType() throws Exception {
143 assertFalse(this.otherServiceRestDefinition.equals(javaServiceDefinition));
144 }
145
146 }