001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.tools.wsdlto.frontend.jaxws.customization;
019:
020: import java.io.File;
021: import java.io.FileOutputStream;
022:
023: import org.w3c.dom.Document;
024: import org.w3c.dom.Element;
025: import org.w3c.dom.Node;
026:
027: import org.apache.cxf.helpers.XMLUtils;
028: import org.apache.cxf.tools.common.ProcessorTestBase;
029: import org.junit.Test;
030:
031: public class CustomizationParserTest extends ProcessorTestBase {
032: CustomizationParser parser = new CustomizationParser();
033: CustomNodeSelector selector = new CustomNodeSelector();
034:
035: @Test
036: public void testHasJaxbBindingDeclaration() throws Exception {
037: Element doc = getDocumentElement("resources/embeded_jaxb.xjb");
038:
039: Node jaxwsBindingNode = selector.queryNode(doc,
040: "//jaxws:bindings[@node]");
041:
042: assertNotNull(jaxwsBindingNode);
043:
044: assertTrue(parser.hasJaxbBindingDeclaration(jaxwsBindingNode));
045:
046: doc = getDocumentElement("resources/external_jaxws.xml");
047: jaxwsBindingNode = selector.queryNode(doc,
048: "//jaxws:bindings[@node]");
049: assertNotNull(jaxwsBindingNode);
050: assertFalse(parser.hasJaxbBindingDeclaration(jaxwsBindingNode));
051: }
052:
053: @Test
054: public void testCopyAllJaxbDeclarations() throws Exception {
055: Element schema = getDocumentElement("resources/test.xsd");
056: Element binding = getDocumentElement("resources/embeded_jaxb.xjb");
057:
058: String checkingPoint = "//xsd:annotation/xsd:appinfo/jaxb:schemaBindings/jaxb:package[@name]";
059: assertNull(selector.queryNode(schema, checkingPoint));
060:
061: Node jaxwsBindingNode = selector.queryNode(binding,
062: "//jaxws:bindings[@node]");
063: Node schemaNode = selector.queryNode(schema, "//xsd:schema");
064:
065: parser.copyAllJaxbDeclarations(schemaNode,
066: (Element) jaxwsBindingNode);
067:
068: File file = new File(output, "custom_test.xsd");
069: XMLUtils.writeTo(schemaNode, new FileOutputStream(file));
070: Document testNode = XMLUtils.parse(file);
071:
072: Node result = selector.queryNode(testNode, checkingPoint);
073: assertNotNull(result);
074: }
075:
076: @Test
077: public void testInternalizeBinding1() throws Exception {
078: Element wsdlDoc = getDocumentElement("resources/test.wsdl");
079: Element jaxwsBinding = getDocumentElement("resources/external_jaxws.xml");
080:
081: parser.setWSDLNode(wsdlDoc);
082: parser.internalizeBinding(jaxwsBinding, "");
083:
084: File file = new File(output, "custom_test.wsdl");
085: XMLUtils.writeTo(wsdlDoc, new FileOutputStream(file));
086: Document testNode = XMLUtils.parse(file);
087:
088: String[] checkingPoints = new String[] {
089: "wsdl:definitions/wsdl:portType/jaxws:bindings/jaxws:class",
090: "wsdl:definitions/jaxws:bindings/jaxws:package" };
091: checking(testNode, checkingPoints);
092: }
093:
094: @Test
095: public void testInternalizeBinding2() throws Exception {
096: Element wsdlDoc = getDocumentElement("resources/test.wsdl");
097: Element jaxwsBinding = getDocumentElement("resources/external_jaxws_embed_jaxb.xml");
098:
099: parser.setWSDLNode(wsdlDoc);
100: parser.internalizeBinding(jaxwsBinding, "");
101:
102: String base = "wsdl:definitions/wsdl:types/xsd:schema/xsd:annotation/xsd:appinfo/";
103: String[] checkingPoints = new String[] { base
104: + "jaxb:schemaBindings/jaxb:package" };
105:
106: File file = new File(output, "custom_test.wsdl");
107: XMLUtils.writeTo(wsdlDoc, new FileOutputStream(file));
108: Document testNode = XMLUtils.parse(file);
109:
110: checking(testNode, checkingPoints);
111: }
112:
113: @Test
114: public void testInternalizeBinding3() throws Exception {
115: Element wsdlDoc = getDocumentElement("resources/test.wsdl");
116: Element jaxwsBinding = getDocumentElement("resources/external_jaxws_embed_jaxb_date.xml");
117: parser.setWSDLNode(wsdlDoc);
118: parser.internalizeBinding(jaxwsBinding, "");
119:
120: String base = "wsdl:definitions/wsdl:types/xsd:schema/xsd:annotation/xsd:appinfo/";
121: String[] checkingPoints = new String[] { base
122: + "jaxb:globalBindings/jaxb:javaType" };
123:
124: File file = new File(output, "custom_test.wsdl");
125: XMLUtils.writeTo(wsdlDoc, new FileOutputStream(file));
126: Document testNode = XMLUtils.parse(file);
127:
128: checking(testNode, checkingPoints);
129: }
130:
131: @Test
132: public void testInternalizeBinding4() throws Exception {
133: Element wsdlDoc = getDocumentElement("resources/hello_world.wsdl");
134: Element jaxwsBinding = getDocumentElement("resources/binding2.xml");
135: parser.setWSDLNode(wsdlDoc);
136: parser.internalizeBinding(jaxwsBinding, "");
137:
138: String checkingPoint = "wsdl:definitions/wsdl:types/xsd:schema";
139: checkingPoint += "/xsd:element[@name='CreateProcess']/xsd:complexType/xsd:sequence";
140: checkingPoint += "/xsd:element[@name='MyProcess']/xsd:simpleType/xsd:annotation/xsd:appinfo";
141: checkingPoint += "/jaxb:typesafeEnumClass/jaxb:typesafeEnumMember[@name='BLUE']";
142:
143: String[] checkingPoints = new String[] { checkingPoint };
144:
145: File file = new File(output, "custom_test4.wsdl");
146: XMLUtils.writeTo(wsdlDoc, new FileOutputStream(file));
147: Document testNode = XMLUtils.parse(file);
148:
149: checking(testNode, checkingPoints);
150: }
151:
152: private Element getDocumentElement(final String resource)
153: throws Exception {
154: return XMLUtils.parse(getClass().getResourceAsStream(resource))
155: .getDocumentElement();
156: }
157:
158: private void checking(Node node, String[] checkingPoints) {
159: for (String checkingPoint : checkingPoints) {
160: assertNotNull(selector.queryNode(node, checkingPoint));
161: }
162: }
163: }
|