KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > framework > ComponentNameSpaceTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jbi.framework;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.ObjectInputStream JavaDoc;
22 import java.io.ObjectOutputStream JavaDoc;
23
24 import org.apache.servicemix.jbi.framework.ComponentNameSpace;
25
26 import junit.framework.TestCase;
27
28 public class ComponentNameSpaceTest extends TestCase {
29
30     /*
31      * Test method for 'org.apache.servicemix.jbi.framework.ComponentNameSpace.getComponentId()'
32      */

33     public void testAccessors() {
34         ComponentNameSpace cns = new ComponentNameSpace();
35         assertNull(cns.getContainerName());
36         assertNull(cns.getName());
37         cns.setContainerName("container");
38         assertEquals("container", cns.getContainerName());
39         cns.setName("name");
40         assertEquals("name", cns.getName());
41     }
42
43     /*
44      * Test method for 'org.apache.servicemix.jbi.framework.ComponentNameSpace.equals(Object)'
45      * Test method for 'org.apache.servicemix.jbi.framework.ComponentNameSpace.hashCode()'
46      */

47     public void testHashCodeEqualsObject() {
48         ComponentNameSpace cns1 = new ComponentNameSpace("container", "name");
49         ComponentNameSpace cns2 = new ComponentNameSpace("container", "name");
50         assertTrue(cns1.equals(cns2));
51         assertTrue(cns1.hashCode() == cns2.hashCode());
52
53         ComponentNameSpace cns3 = new ComponentNameSpace("container1", "name");
54         ComponentNameSpace cns4 = new ComponentNameSpace("container2", "name");
55         assertFalse(cns3.equals(cns4));
56         assertFalse(cns3.hashCode() == cns4.hashCode());
57
58         ComponentNameSpace cns5 = new ComponentNameSpace("container", "name1");
59         ComponentNameSpace cns6 = new ComponentNameSpace("container", "name2");
60         assertFalse(cns5.equals(cns6));
61         assertFalse(cns5.hashCode() == cns6.hashCode());
62     }
63
64     /*
65      * Test method for 'org.apache.servicemix.jbi.framework.ComponentNameSpace.writeExternal(ObjectOutput)'
66      * Test method for 'org.apache.servicemix.jbi.framework.ComponentNameSpace.readExternal(ObjectInput)'
67      */

68     public void testSerialize() throws Exception JavaDoc {
69         ComponentNameSpace cns = new ComponentNameSpace("container", "name");
70         
71         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
72         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
73         oos.writeObject(cns);
74         oos.close();
75         
76         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
77         ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
78         Object JavaDoc out = ois.readObject();
79         
80         assertNotNull(out);
81         assertTrue(out instanceof ComponentNameSpace);
82         ComponentNameSpace cnsOut = (ComponentNameSpace) out;
83         assertEquals(cns, cnsOut);
84         assertEquals(cns.getName(), cnsOut.getName());
85     }
86
87     /*
88      * Test method for 'org.apache.servicemix.jbi.framework.ComponentNameSpace.copy()'
89      */

90     public void testCopy() {
91         ComponentNameSpace cns1 = new ComponentNameSpace("container", "name");
92         ComponentNameSpace cns2 = cns1.copy();
93         assertEquals(cns1, cns1);
94         assertEquals(cns1.getName(), cns2.getName());
95     }
96
97 }
98
Popular Tags