KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > extensions > bpel > ComponentUpdaterTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.extensions.bpel;
21
22 import java.util.ArrayList JavaDoc;
23 import junit.framework.*;
24 import org.netbeans.modules.xml.wsdl.model.*;
25 import org.netbeans.modules.xml.wsdl.model.extensions.NamespaceLocation;
26 import org.netbeans.modules.xml.wsdl.model.extensions.TestCatalogModel;
27 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.impl.CorrelationPropertyImpl;
28 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.impl.DocumentationImpl;
29 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.impl.QueryImpl;
30
31 /**
32  *
33  * @author Nam Nguyen
34  */

35 public class ComponentUpdaterTest extends TestCase {
36     private WSDLModel model;
37     private Definitions definitions;
38     
39     public ComponentUpdaterTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44     }
45
46     protected void tearDown() throws Exception JavaDoc {
47         TestCatalogModel.getDefault().clearDocumentPool();
48     }
49
50     public static Test suite() {
51         TestSuite suite = new TestSuite(ComponentUpdaterTest.class);
52         return suite;
53     }
54
55     public void testRemoveAll_Travel() throws Exception JavaDoc {
56         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
57         definitions = model.getDefinitions();
58     }
59
60     public void testRemoveAll_Airline() throws Exception JavaDoc {
61         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE);
62         definitions = model.getDefinitions();
63     }
64
65     public void testRemoveAll_Hotel() throws Exception JavaDoc {
66         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.HOTEL);
67         definitions = model.getDefinitions();
68     }
69
70     public void testRemoveAll_Vehicle() throws Exception JavaDoc {
71         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE);
72         definitions = model.getDefinitions();
73     }
74
75     static void checkRemoveAll(WSDLComponent target) throws Exception JavaDoc {
76         target.getModel().startTransaction();
77         recursiveRemoveChildren(target);
78         assertEquals("children removed", 0, target.getChildren().size());
79         target.getModel().endTransaction();
80     }
81     
82     static void recursiveRemoveChildren(WSDLComponent target) {
83         WSDLModel model = target.getModel();
84         ArrayList JavaDoc<WSDLComponent> children = new ArrayList JavaDoc<WSDLComponent>(target.getChildren());
85         for (WSDLComponent child : children) {
86             recursiveRemoveChildren(child);
87         }
88         if (target.getParent() != null) {
89             model.removeChildComponent(target);
90         }
91     }
92
93     public void NO_testCanPasteAll_Travel() throws Exception JavaDoc {
94         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.TRAVEL);
95         recursiveCanPasteChildren(model.getDefinitions());
96         recursiveCannotPasteChildren(model.getDefinitions());
97     }
98     
99     public void testCanNotPaste_Airline() throws Exception JavaDoc {
100         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE);
101         PartnerLinkType plt = model.getDefinitions().getExtensibilityElements(PartnerLinkType.class).get(0);
102         Role role1 = plt.getRole1();
103         assertFalse(role1.canPaste(plt));
104         assertFalse(model.getDefinitions().canPaste(new QueryImpl(model)));
105         assertFalse(model.getDefinitions().getTypes().canPaste(new CorrelationPropertyImpl(model)));
106     }
107     
108     public void NO_testCanPasteAll_Airline() throws Exception JavaDoc {
109         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.AIRLINE);
110         recursiveCanPasteChildren(model.getDefinitions());
111         recursiveCannotPasteChildren(model.getDefinitions());
112     }
113     
114     public void NO_testCanPasteAll_Hotel() throws Exception JavaDoc {
115         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.HOTEL);
116         recursiveCanPasteChildren(model.getDefinitions());
117         recursiveCannotPasteChildren(model.getDefinitions());
118     }
119     
120     public void NO_testCanPasteAll_Vehicle() throws Exception JavaDoc {
121         model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.VEHICLE);
122         recursiveCanPasteChildren(model.getDefinitions());
123         recursiveCannotPasteChildren(model.getDefinitions());
124     }
125     
126     public static void recursiveCanPasteChildren(WSDLComponent target) {
127         WSDLModel model = target.getModel();
128         ArrayList JavaDoc<WSDLComponent> children = new ArrayList JavaDoc<WSDLComponent>(target.getChildren());
129         for (WSDLComponent child : children) {
130             recursiveCanPasteChildren(child);
131         }
132         if (target.getParent() != null) {
133             assertTrue(target.getParent().canPaste(target));
134         }
135     }
136
137     public static void recursiveCannotPasteChildren(WSDLComponent target) {
138         WSDLModel model = target.getModel();
139         ArrayList JavaDoc<WSDLComponent> children = new ArrayList JavaDoc<WSDLComponent>(target.getChildren());
140         for (WSDLComponent child : children) {
141             recursiveCannotPasteChildren(child);
142         }
143         if (target.getParent() != null) {
144             String JavaDoc msg = target.getClass().getName() + " canPaste " + target.getParent().getClass().getName();
145             assertFalse(msg, target.canPaste(target.getParent()));
146         }
147     }
148 }
149
Popular Tags