View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests equality between RESTServiceDefinition objects
31   * 
32   * @author James Renfro
33   * @since 1.3
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      	// It's the type that matters, not the value
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 }