KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > impl > ChildComponentUpdateVisitorTest


1 /*
2  * ChildComponentUpdateVisitorTest.java
3  * JUnit based test
4  *
5  * Created on August 23, 2006, 10:55 AM
6  */

7
8 package org.netbeans.modules.xml.wsdl.model.impl;
9
10 import java.util.ArrayList JavaDoc;
11 import junit.framework.*;
12 import org.netbeans.modules.xml.wsdl.model.*;
13 import org.netbeans.modules.xml.wsdl.model.extensions.soap.impl.SOAPHeaderImpl;
14 import org.netbeans.modules.xml.wsdl.model.spi.GenericExtensibilityElement;
15
16 /**
17  *
18  * @author nn136682
19  */

20 public class ChildComponentUpdateVisitorTest extends TestCase {
21     private WSDLModel model;
22     private Definitions definitions;
23     
24     public ChildComponentUpdateVisitorTest(String JavaDoc testName) {
25         super(testName);
26     }
27
28     protected void setUp() throws Exception JavaDoc {
29     }
30
31     protected void tearDown() throws Exception JavaDoc {
32         TestCatalogModel.getDefault().clearDocumentPool();
33     }
34
35     public static Test suite() {
36         TestSuite suite = new TestSuite(ChildComponentUpdateVisitorTest.class);
37         return suite;
38     }
39
40     public void testRemoveAll_Travel() throws Exception JavaDoc {
41         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
42         definitions = model.getDefinitions();
43     }
44
45     public void testRemoveAll_Airline() throws Exception JavaDoc {
46         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE);
47         definitions = model.getDefinitions();
48     }
49
50     public void testRemoveAll_Hotel() throws Exception JavaDoc {
51         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.HOTEL);
52         definitions = model.getDefinitions();
53     }
54
55     public void testRemoveAll_Vehicle() throws Exception JavaDoc {
56         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE);
57         definitions = model.getDefinitions();
58     }
59
60     static void checkRemoveAll(WSDLComponent target) throws Exception JavaDoc {
61         target.getModel().startTransaction();
62         recursiveRemoveChildren(target);
63         assertEquals("children removed", 0, target.getChildren().size());
64         target.getModel().endTransaction();
65     }
66     
67     static void recursiveRemoveChildren(WSDLComponent target) {
68         WSDLModel model = target.getModel();
69         ArrayList JavaDoc<WSDLComponent> children = new ArrayList JavaDoc<WSDLComponent>(target.getChildren());
70         for (WSDLComponent child : children) {
71             recursiveRemoveChildren(child);
72         }
73         if (target.getParent() != null) {
74             model.removeChildComponent(target);
75         }
76     }
77
78     public void testCanPasteAll_Travel() throws Exception JavaDoc {
79         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
80         recursiveCanPasteChildren(model.getDefinitions());
81         recursiveCannotPasteChildren(model.getDefinitions());
82     }
83     
84     public void testCanPasteAll_Airline() throws Exception JavaDoc {
85         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE);
86         recursiveCanPasteChildren(model.getDefinitions());
87         recursiveCannotPasteChildren(model.getDefinitions());
88     }
89     
90     public void testCanPasteAll_Hotel() throws Exception JavaDoc {
91         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.HOTEL);
92         recursiveCanPasteChildren(model.getDefinitions());
93         recursiveCannotPasteChildren(model.getDefinitions());
94     }
95     
96     public void testCanPasteAll_Vehicle() throws Exception JavaDoc {
97         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE);
98         recursiveCanPasteChildren(model.getDefinitions());
99         recursiveCannotPasteChildren(model.getDefinitions());
100     }
101     
102     public static void recursiveCanPasteChildren(WSDLComponent target) {
103         WSDLModel model = target.getModel();
104         ArrayList JavaDoc<WSDLComponent> children = new ArrayList JavaDoc<WSDLComponent>(target.getChildren());
105         for (WSDLComponent child : children) {
106             recursiveCanPasteChildren(child);
107         }
108         if (target.getParent() != null) {
109             String JavaDoc msg = target.getParent().getClass().getName() + " cannot paste " + target.getClass().getName();
110             assertTrue(msg, target.getParent().canPaste(target));
111         }
112     }
113
114     public static void recursiveCannotPasteChildren(WSDLComponent target) {
115         WSDLModel model = target.getModel();
116         ArrayList JavaDoc<WSDLComponent> children = new ArrayList JavaDoc<WSDLComponent>(target.getChildren());
117         for (WSDLComponent child : children) {
118             recursiveCannotPasteChildren(child);
119         }
120         if (target.getParent() != null) {
121             String JavaDoc msg = target.getClass().getName() + " canPaste " + target.getParent().getClass().getName();
122             if (GenericExtensibilityElement.class.isAssignableFrom(target.getParent().getClass())) {
123                 assertTrue(msg, target.canPaste(target.getParent()));
124             } else {
125                 assertFalse(msg, target.canPaste(target.getParent()));
126             }
127         }
128     }
129
130     public void testCannotAddSoapExtensibilityElement() throws Exception JavaDoc {
131         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE);
132         assertFalse(model.getDefinitions().canPaste(new SOAPHeaderImpl(model)));
133     }
134 }
135
Popular Tags