KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > wsdlmodelext > PolicyTest


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 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext;
20
21 import java.io.File JavaDoc;
22 import java.util.Collection JavaDoc;
23 import junit.framework.*;
24 import org.netbeans.modules.websvc.wsitconf.util.TestCatalogModel;
25 import org.netbeans.modules.websvc.wsitconf.util.TestUtil;
26 import org.netbeans.modules.websvc.wsitmodelext.policy.All;
27 import org.netbeans.modules.websvc.wsitmodelext.policy.PolicyReference;
28 import org.netbeans.modules.xml.wsdl.model.Binding;
29 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
30 import org.netbeans.modules.xml.wsdl.model.Definitions;
31 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory;
32 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
33
34 /**
35  *
36  * @author Martin Grebac
37  */

38 public class PolicyTest extends TestCase {
39     
40     public PolicyTest(String JavaDoc testName) {
41         super(testName);
42     }
43
44     @Override JavaDoc
45     protected void setUp() throws Exception JavaDoc {
46     }
47
48     @Override JavaDoc
49     protected void tearDown() throws Exception JavaDoc {
50         TestCatalogModel.getDefault().setDocumentPooling(false);
51     }
52
53     public void testWrite() throws Exception JavaDoc {
54         TestCatalogModel.getDefault().setDocumentPooling(true);
55         WSDLModel model = TestUtil.loadWSDLModel("../wsdlmodelext/resources/policy.xml");
56         WSDLComponentFactory fact = model.getFactory();
57         
58         model.startTransaction();
59
60         Definitions d = model.getDefinitions();
61         Binding b = (Binding) d.getBindings().toArray()[0];
62         
63         PolicyModelHelper.createPolicy(b);
64         
65         Collection JavaDoc<BindingOperation> bindingops = b.getBindingOperations();
66         for (BindingOperation bo : bindingops) {
67             PolicyModelHelper.createPolicy(bo.getBindingInput());
68             PolicyModelHelper.createPolicy(bo.getBindingOutput());
69         }
70
71         model.endTransaction();
72
73         TestUtil.dumpToFile(model.getBaseDocument(), new File JavaDoc("C:\\HelloService.wsdl"));
74         readAndCheck(model);
75     }
76
77     private void readAndCheck(WSDLModel model) {
78         
79         // the model operation is not enclosed in transaction inorder to catch
80
// whether the operations do not try to create non-existing elements
81

82         Definitions d = model.getDefinitions();
83         Binding b = (Binding) d.getBindings().toArray()[0];
84         
85         All all = PolicyModelHelper.createPolicy(b);
86         assertNotNull("Top Level Policy", all);
87         
88         Collection JavaDoc<PolicyReference> polRefs = b.getExtensibilityElements(PolicyReference.class);
89         assertEquals("Top Level Policy Ref Size", 1, polRefs.size());
90         assertEquals("Top Level Policy Ref URI", "#NewWebServicePortBindingPolicy", polRefs.iterator().next().getPolicyURI());
91         
92         Collection JavaDoc<BindingOperation> bindingops = b.getBindingOperations();
93         for (BindingOperation bo : bindingops) {
94             all = PolicyModelHelper.createPolicy(bo.getBindingInput());
95             assertNotNull("Binding Input Policy", all);
96             
97             all = PolicyModelHelper.createPolicy(bo.getBindingOutput());
98             assertNotNull("Binding Output Policy", all);
99         }
100         
101     }
102
103     public String JavaDoc getTestResourcePath() {
104         return "../wsdlmodelext/resources/policy.xml";
105     }
106     
107 }
108
Popular Tags