001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.wsitmodelext;
043:
044: import java.io.File;
045: import java.util.HashSet;
046: import java.util.Set;
047: import javax.xml.namespace.QName;
048: import org.netbeans.junit.NbTestCase;
049: import org.netbeans.modules.websvc.wsitmodelext.addressing.Addressing10QName;
050: import org.netbeans.modules.websvc.wsitmodelext.addressing.Addressing10WsdlQName;
051: import org.netbeans.modules.websvc.wsitmodelext.addressing.AddressingQName;
052: import org.netbeans.modules.websvc.wsitmodelext.mtom.MtomQName;
053: import org.netbeans.modules.websvc.wsitmodelext.policy.PolicyQName;
054: import org.netbeans.modules.websvc.wsitmodelext.rm.RMMSQName;
055: import org.netbeans.modules.websvc.wsitmodelext.rm.RMQName;
056: import org.netbeans.modules.websvc.wsitmodelext.rm.RMSunClientQName;
057: import org.netbeans.modules.websvc.wsitmodelext.rm.RMSunQName;
058: import org.netbeans.modules.websvc.wsitmodelext.security.SecurityPolicyQName;
059: import org.netbeans.modules.websvc.wsitmodelext.security.SecurityQName;
060: import org.netbeans.modules.websvc.wsitmodelext.security.algosuite.AlgorithmSuiteQName;
061: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietaryPolicyQName;
062: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietarySCClientQName;
063: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietarySecurityPolicyQName;
064: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.ProprietaryTrustClientQName;
065: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ProprietarySCServiceQName;
066: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ProprietarySecurityPolicyServiceQName;
067: import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.ProprietaryTrustServiceQName;
068: import org.netbeans.modules.websvc.wsitmodelext.security.tokens.TokensQName;
069: import org.netbeans.modules.websvc.wsitmodelext.transport.FIQName;
070: import org.netbeans.modules.websvc.wsitmodelext.transport.TCPQName;
071: import org.netbeans.modules.websvc.wsitmodelext.trust.TrustQName;
072: import org.netbeans.modules.websvc.wsitmodelext.tx.TxQName;
073: import org.netbeans.modules.websvc.wsitmodelext.util.TestCatalogModel;
074: import org.netbeans.modules.websvc.wsitmodelext.util.Util;
075: import org.netbeans.modules.xml.wsdl.model.Definitions;
076: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
077: import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory;
078: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
079:
080: /**
081: *
082: * @author Martin Grebac
083: */
084: public class PolicyTest extends NbTestCase {
085:
086: public PolicyTest(String testName) {
087: super (testName);
088: }
089:
090: @Override
091: protected void setUp() throws Exception {
092: }
093:
094: @Override
095: protected void tearDown() throws Exception {
096: TestCatalogModel.getDefault().setDocumentPooling(false);
097: }
098:
099: public void testWrite() throws Exception {
100: TestCatalogModel.getDefault().setDocumentPooling(true);
101: WSDLModel model = Util.loadWSDLModel("../resources/policy.xml");
102: WSDLComponentFactory fact = model.getFactory();
103:
104: model.startTransaction();
105:
106: Definitions d = model.getDefinitions();
107: ExtensibilityElement e = null;
108: Set<QName> qnames = new HashSet<QName>();
109:
110: qnames.addAll(PolicyQName.getQNames());
111: qnames.addAll(MtomQName.getQNames());
112: qnames.addAll(FIQName.getQNames());
113: qnames.addAll(TCPQName.getQNames());
114: qnames.addAll(AddressingQName.getQNames());
115: qnames.addAll(Addressing10QName.getQNames());
116: qnames.addAll(Addressing10WsdlQName.getQNames());
117: qnames.addAll(RMQName.getQNames());
118: qnames.addAll(RMSunQName.getQNames());
119: qnames.addAll(RMSunClientQName.getQNames());
120: qnames.addAll(RMMSQName.getQNames());
121: qnames.addAll(SecurityQName.getQNames());
122: qnames.addAll(SecurityPolicyQName.getQNames());
123: qnames.addAll(AlgorithmSuiteQName.getQNames());
124: qnames.addAll(ProprietaryPolicyQName.getQNames());
125: qnames.addAll(ProprietarySCClientQName.getQNames());
126: qnames.addAll(ProprietarySecurityPolicyQName.getQNames());
127: qnames
128: .addAll(ProprietarySecurityPolicyServiceQName
129: .getQNames());
130: qnames.addAll(ProprietaryTrustClientQName.getQNames());
131: qnames.addAll(ProprietaryTrustServiceQName.getQNames());
132: qnames.addAll(ProprietarySCServiceQName.getQNames());
133: qnames.addAll(TokensQName.getQNames());
134: qnames.addAll(TrustQName.getQNames());
135: qnames.addAll(TxQName.getQNames());
136:
137: for (QName qname : qnames) {
138: e = (ExtensibilityElement) fact.create(d, qname);
139: d.addExtensibilityElement(e);
140: }
141:
142: model.endTransaction();
143:
144: File output = new File("WSITModelTestOutput.wsdl");
145:
146: System.out.println("Generating file: "
147: + output.getAbsolutePath());
148:
149: File golden = new File(getDataDir().getAbsolutePath()
150: + "/goldenfiles/" + "WSITModelTestOutput.wsdl");
151:
152: Util.dumpToFile(model.getBaseDocument(), output);
153:
154: System.out.println(getWorkDir().getAbsolutePath());
155: assertFile(output, golden, getWorkDir());
156: }
157:
158: public String getTestResourcePath() {
159: return "../resources/policy.xml";
160: }
161:
162: }
|