KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > servicedesc > InternalEndpointTest


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.servicedesc;
18
19 import org.apache.servicemix.jbi.framework.ComponentNameSpace;
20 import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
21
22 import javax.xml.namespace.QName JavaDoc;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.ByteArrayOutputStream JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.io.ObjectOutputStream JavaDoc;
28
29 import junit.framework.TestCase;
30
31 public class InternalEndpointTest extends TestCase {
32
33     public void testSerializeDeserialize() throws Exception JavaDoc {
34         ComponentNameSpace cns = new ComponentNameSpace("myContainer", "myName");
35         InternalEndpoint e = new InternalEndpoint(cns, "myEndpoint", new QName JavaDoc("myService"));
36         
37         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
38         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
39         oos.writeObject(e);
40         oos.close();
41         
42         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
43         ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
44         Object JavaDoc out = ois.readObject();
45         
46         assertNotNull(out);
47         assertTrue(out instanceof InternalEndpoint);
48         InternalEndpoint outE = (InternalEndpoint) out;
49         assertNotNull(outE.getComponentNameSpace());
50         assertNotNull(outE.getServiceName());
51         assertNotNull(outE.getEndpointName());
52     }
53     
54     public void testEquals() throws Exception JavaDoc {
55         ComponentNameSpace cns = new ComponentNameSpace("myContainer", "myName");
56         InternalEndpoint e1 = new InternalEndpoint(cns, "myEndpoint1", new QName JavaDoc("myService"));
57         InternalEndpoint e2 = new InternalEndpoint(cns, "myEndpoint2", new QName JavaDoc("myService"));
58         assertFalse(e1.equals(e2));
59         e2 = new InternalEndpoint(cns, "myEndpoint", new QName JavaDoc("myService2"));
60         assertFalse(e1.equals(e2));
61         ComponentNameSpace cns2 = new ComponentNameSpace("myContainer2", "myId2");
62         e2 = new InternalEndpoint(cns2, "myEndpoint1", new QName JavaDoc("myService"));
63         assertTrue(e1.equals(e2));
64         cns2 = new ComponentNameSpace("myContainer", "myName");
65         e2 = new InternalEndpoint(cns2, "myEndpoint1", new QName JavaDoc("myService"));
66         assertTrue(e1.equals(e2));
67     }
68
69 }
70
Popular Tags