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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039: package org.netbeans.modules.visualweb.websvcmgr.consumer;
040:
041: import java.awt.datatransfer.DataFlavor;
042: import java.awt.datatransfer.Transferable;
043: import java.io.File;
044: import java.util.HashMap;
045: import org.netbeans.junit.NbTestCase;
046: import org.netbeans.modules.websvc.manager.WebServiceManager;
047: import org.netbeans.modules.websvc.manager.api.WebServiceDescriptor;
048: import org.netbeans.modules.websvc.manager.model.WebServiceData;
049: import org.netbeans.modules.websvc.manager.model.WebServiceListModel;
050: import org.netbeans.modules.websvc.manager.test.SetupData;
051: import org.netbeans.modules.websvc.manager.test.SetupUtil;
052: import org.netbeans.modules.websvc.saas.model.Saas;
053: import org.netbeans.modules.websvc.saas.model.SaasGroup;
054: import org.netbeans.modules.websvc.saas.model.SaasServicesModel;
055: import org.netbeans.modules.websvc.saas.model.SaasServicesModelTest;
056: import org.netbeans.modules.websvc.saas.model.WsdlSaas;
057: import org.netbeans.modules.websvc.saas.util.SaasTransferable;
058: import org.openide.util.datatransfer.ExTransferable;
059:
060: /**
061: *
062: * @author quynguyen
063: */
064: public class DesignerWebServiceTransferManagerTest extends NbTestCase {
065:
066: private WebServiceData wsData;
067: private WsdlSaas saas;
068: private SetupData data;
069:
070: public DesignerWebServiceTransferManagerTest(String testName) {
071: super (testName);
072: }
073:
074: @Override
075: protected void setUp() throws Exception {
076: super .setUp();
077:
078: data = SetupUtil.commonSetUp(getWorkDir());
079: wsData = new WebServiceData(data.getLocalWsdlFile()
080: .getAbsolutePath(), data.getLocalOriginalWsdl().toURI()
081: .toURL().toExternalForm(),
082: WebServiceListModel.DEFAULT_GROUP);
083:
084: wsData.setPackageName("websvc");
085: wsData.setCatalog(data.getLocalCatalogFile().getAbsolutePath());
086: WebServiceManager.getInstance().addWebService(wsData, false);
087:
088: wsData.setCompiled(true);
089: wsData.setState(WebServiceData.State.WSDL_SERVICE_COMPILED);
090:
091: File jarsDir = new File(data.getWebsvcHome(), "USZip/jaxws");
092: jarsDir.mkdirs();
093:
094: File clientJar = new File(jarsDir, "USZip.jar");
095: File srcJar = new File(jarsDir, "USZip-src.jar");
096:
097: SetupUtil
098: .retrieveURL(
099: clientJar,
100: DesignerWebServiceExtImplTest.class
101: .getResource(DesignerWebServiceExtImplTest.CLIENT_JAR_PATH));
102: SetupUtil
103: .retrieveURL(
104: srcJar,
105: DesignerWebServiceExtImplTest.class
106: .getResource(DesignerWebServiceExtImplTest.SRC_JAR_PATH));
107:
108: assertTrue("JAX-WS proxy jar was not copied", clientJar
109: .exists());
110: assertTrue("JAX-WS source jar was not copied", srcJar.exists());
111:
112: WebServiceDescriptor descriptor = new WebServiceDescriptor(
113: wsData.getName(), wsData.getPackageName(),
114: WebServiceDescriptor.JAX_WS_TYPE, new File(wsData
115: .getWsdlFile()).toURI().toURL(), new File(
116: jarsDir, "descriptor.xml"), wsData
117: .getWsdlService());
118:
119: descriptor.addJar("USZip.jar",
120: WebServiceDescriptor.JarEntry.PROXY_JAR_TYPE);
121: descriptor.addJar("USZip-src.jar",
122: WebServiceDescriptor.JarEntry.SRC_JAR_TYPE);
123:
124: wsData.setJaxWsDescriptor(descriptor);
125: wsData.setJaxWsDescriptorPath(descriptor.getXmlDescriptor());
126: SaasGroup group = SaasServicesModel.getInstance()
127: .getRootGroup();
128: saas = new WsdlSaas(group, "test", data.getLocalOriginalWsdl()
129: .toURL().toExternalForm(), "websvc");
130: SaasServicesModelTest.setWsdlData(saas, wsData);
131: saas.toStateReady(true);
132: assertTrue(wsData.isReady());
133: assertEquals(Saas.State.READY, saas.getState());
134: }
135:
136: @Override
137: protected void tearDown() throws Exception {
138: super .tearDown();
139:
140: SetupUtil.commonTearDown();
141: }
142:
143: /**
144: * Test of addDataFlavors method, of class DesignerWebServiceTransferManager.
145: */
146: public void testPortAddDataFlavors() throws Exception {
147: System.out.println("addDataFlavors(port)");
148:
149: Transferable t = new SaasTransferable(saas.getPorts().get(0),
150: SaasTransferable.WSDL_PORT_FLAVORS);
151: Transferable transferable = ExTransferable.create(t);
152:
153: HashMap<DataFlavor, Object> origMappings = new HashMap<DataFlavor, Object>();
154: DataFlavor[] flavors = transferable.getTransferDataFlavors();
155: for (int i = 0; i < flavors.length; i++) {
156: origMappings.put(flavors[i], transferable
157: .getTransferData(flavors[i]));
158: }
159:
160: DesignerWebServiceTransferManager instance = new DesignerWebServiceTransferManager();
161: Transferable result = instance.addDataFlavors(transferable);
162:
163: assertTrue(
164: "Port display item flavor not added to transferable",
165: result
166: .isDataFlavorSupported(DesignerWebServiceTransferManager.FLAVOR_PORT_DISPLAY_ITEM));
167:
168: Object transferData = result
169: .getTransferData(DesignerWebServiceTransferManager.FLAVOR_PORT_DISPLAY_ITEM);
170: assertTrue(
171: "Transferable did not return value of type PortBeanCreateInfo",
172: transferData instanceof DesignerWebServiceTransferManager.PortBeanCreateInfo);
173:
174: for (DataFlavor flavor : origMappings.keySet()) {
175: Object updatedData = result.getTransferData(flavor);
176: Object origData = origMappings.get(flavor);
177: assertEquals("DataFlavor was modified: "
178: + flavor.getHumanPresentableName(), updatedData,
179: origData);
180: }
181: }
182:
183: public void testMethodAddDataFlavors() throws Exception {
184: Transferable t = new SaasTransferable(saas.getPorts().get(0)
185: .getWsdlMethods().get(0),
186: SaasTransferable.WSDL_METHOD_FLAVORS);
187: Transferable transferable = ExTransferable.create(t);
188:
189: HashMap<DataFlavor, Object> origMappings = new HashMap<DataFlavor, Object>();
190: DataFlavor[] flavors = transferable.getTransferDataFlavors();
191: for (int i = 0; i < flavors.length; i++) {
192: origMappings.put(flavors[i], transferable
193: .getTransferData(flavors[i]));
194: }
195:
196: DesignerWebServiceTransferManager instance = new DesignerWebServiceTransferManager();
197: Transferable result = instance.addDataFlavors(transferable);
198:
199: assertTrue(
200: "Method display item flavor not added to transferable",
201: result
202: .isDataFlavorSupported(DesignerWebServiceTransferManager.FLAVOR_METHOD_DISPLAY_ITEM));
203:
204: Object transferData = result
205: .getTransferData(DesignerWebServiceTransferManager.FLAVOR_METHOD_DISPLAY_ITEM);
206: assertTrue(
207: "Transferable did not return value of type MethodBeanCreateInfo",
208: transferData instanceof DesignerWebServiceTransferManager.MethodBeanCreateInfo);
209:
210: for (DataFlavor flavor : origMappings.keySet()) {
211: Object updatedData = result.getTransferData(flavor);
212: Object origData = origMappings.get(flavor);
213: assertEquals("DataFlavor was modified: "
214: + flavor.getHumanPresentableName(), updatedData,
215: origData);
216: }
217: }
218: }
|