KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > TModelBagHandlerTests


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.apache.juddi.handler;
17
18 import org.apache.juddi.datatype.RegistryObject;
19 import org.apache.juddi.datatype.TModelBag;
20 import org.apache.juddi.datatype.TModelKey;
21 import org.apache.juddi.util.xml.XMLUtils;
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  * @author anou_mana@apache.org
26  */

27 public class TModelBagHandlerTests extends HandlerTestCase
28 {
29     private static final String JavaDoc TEST_ID = "juddi.handler.DeleteTModelBag.test";
30     private TModelBagHandler handler = null;
31
32   public TModelBagHandlerTests(String JavaDoc arg0)
33   {
34     super(arg0);
35   }
36
37   public static void main(String JavaDoc[] args)
38   {
39     junit.textui.TestRunner.run( TModelBagHandlerTests.class);
40   }
41
42   public void setUp()
43   {
44         HandlerMaker maker = HandlerMaker.getInstance();
45         handler = ( TModelBagHandler)maker.lookup( TModelBagHandler.TAG_NAME);
46   }
47
48     private RegistryObject getRegistryObject()
49     {
50
51         TModelBag object = new TModelBag();
52         object.addTModelKey("uuid:35d9793b-9911-4b85-9f0e-5d4c65b4f253");
53         object.addTModelKey(new TModelKey("uuid:c5ab113f-0d6b-4247-b3c4-8c012726acd8"));
54
55         return object;
56
57     }
58
59     private Element JavaDoc getMarshalledElement(RegistryObject regObject)
60     {
61         Element JavaDoc parent = XMLUtils.newRootElement();
62         Element JavaDoc child = null;
63
64         if(regObject == null)
65             regObject = this.getRegistryObject();
66
67         handler.marshal(regObject,parent);
68         child = (Element JavaDoc)parent.getFirstChild();
69         parent.removeChild(child);
70
71         return child;
72     }
73
74     public void testMarshal()
75     {
76         Element JavaDoc child = getMarshalledElement(null);
77
78         String JavaDoc marshalledString = this.getXMLString(child);
79
80         assertNotNull("Marshalled TModelBag ", marshalledString);
81
82     }
83
84     public void testUnMarshal()
85     {
86
87         Element JavaDoc child = getMarshalledElement(null);
88         RegistryObject regObject = handler.unmarshal(child);
89
90         assertNotNull("UnMarshalled TModelBag ", regObject);
91
92     }
93
94   public void testMarshUnMarshal()
95   {
96         Element JavaDoc child = getMarshalledElement(null);
97
98         String JavaDoc marshalledString = this.getXMLString(child);
99
100         assertNotNull("Marshalled TModelBag ", marshalledString);
101
102         RegistryObject regObject = handler.unmarshal(child);
103
104         child = getMarshalledElement(regObject);
105
106         String JavaDoc unMarshalledString = this.getXMLString(child);
107
108         assertNotNull("Unmarshalled TModelBag ", unMarshalledString);
109
110         boolean equals = marshalledString.equals(unMarshalledString);
111
112         assertEquals("Expected TModelBag: ", marshalledString, unMarshalledString );
113   }
114
115 }
116
Popular Tags