001/**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.messaging;
017
018import static org.junit.Assert.assertFalse;
019import static org.junit.Assert.assertTrue;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import org.junit.Test;
025import org.kuali.rice.ksb.api.bus.support.JavaServiceDefinition;
026import org.kuali.rice.ksb.api.bus.support.RestServiceDefinition;
027import org.kuali.rice.ksb.test.KSBTestCase;
028
029/**
030 * Tests equality between RESTServiceDefinition objects
031 * 
032 * @author James Renfro
033 * @since 1.3
034 *
035 */
036public class RestServiceDefinitionTest extends KSBTestCase {
037    
038    private RestServiceDefinition restDefinition;
039    private RestServiceDefinition sameExactRestDefinition;
040    private RestServiceDefinition otherRestDefinition;
041    private RestServiceDefinition otherNameRestDefinition;
042    private RestServiceDefinition otherServiceRestDefinition;
043    private RestServiceDefinition singleResourceDefinition;
044    private JavaServiceDefinition javaServiceDefinition;
045
046    public void setUp() throws Exception {
047        super.setUp();
048        
049        String a = "a";
050        String b = "b";
051        String c = "c";
052        Long l = Long.valueOf(123l);
053        
054        List<Object> restResources = new ArrayList<Object>();
055        restResources.add(a);
056        restResources.add(b);
057        
058        List<Object> sameExactRestResources = new ArrayList<Object>();
059        sameExactRestResources.add(a);
060        sameExactRestResources.add(b);
061        
062        // It's the type that matters, not the value
063        List<Object> functionallySameResources = new ArrayList<Object>();
064        functionallySameResources.add(b);
065        functionallySameResources.add(c);
066        
067        List<Object> otherRestResources = new ArrayList<Object>();
068        otherRestResources.add(l);
069        otherRestResources.add(b);
070        
071        Object service = new ArrayList<Object>();
072        
073        this.restDefinition = new RestServiceDefinition();
074        this.restDefinition.setLocalServiceName("restServiceName");
075        this.restDefinition.setResources(restResources);
076        this.restDefinition.validate();
077        
078        this.sameExactRestDefinition = new RestServiceDefinition();
079        this.sameExactRestDefinition.setLocalServiceName("restServiceName");
080        this.sameExactRestDefinition.setResources(sameExactRestResources);
081        this.sameExactRestDefinition.validate();
082                
083        this.otherRestDefinition = new RestServiceDefinition();
084        this.otherRestDefinition.setLocalServiceName("restServiceName");
085        this.otherRestDefinition.setResources(otherRestResources);
086        this.otherRestDefinition.validate();
087        
088        this.otherNameRestDefinition = new RestServiceDefinition();
089        this.otherNameRestDefinition.setLocalServiceName("anotherRestServiceName");
090        this.otherNameRestDefinition.setResources(sameExactRestResources);
091        this.otherNameRestDefinition.validate();
092        
093        this.otherServiceRestDefinition = new RestServiceDefinition();
094        this.otherServiceRestDefinition.setLocalServiceName("restServiceName");
095        this.otherServiceRestDefinition.setService(service);
096        this.otherServiceRestDefinition.setResources(restResources);
097        this.otherServiceRestDefinition.validate();
098        
099        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}