1 19 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext; 20 21 import java.io.File ; 22 import java.util.Collection ; 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 38 public class PolicyTest extends TestCase { 39 40 public PolicyTest(String testName) { 41 super(testName); 42 } 43 44 @Override 45 protected void setUp() throws Exception { 46 } 47 48 @Override 49 protected void tearDown() throws Exception { 50 TestCatalogModel.getDefault().setDocumentPooling(false); 51 } 52 53 public void testWrite() throws Exception { 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 <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 ("C:\\HelloService.wsdl")); 74 readAndCheck(model); 75 } 76 77 private void readAndCheck(WSDLModel model) { 78 79 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 <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 <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 getTestResourcePath() { 104 return "../wsdlmodelext/resources/policy.xml"; 105 } 106 107 } 108 | Popular Tags |