Author: heiko.braun(a)jboss.com
Date: 2007-08-01 09:27:00 -0400 (Wed, 01 Aug 2007)
New Revision: 4052
Modified:
trunk/testsuite/src/java/org/jboss/test/ws/jaxws/tools/WSProvideTestCase.java
Log:
Complete WSProvideTestCase
Modified: trunk/testsuite/src/java/org/jboss/test/ws/jaxws/tools/WSProvideTestCase.java
===================================================================
---
trunk/testsuite/src/java/org/jboss/test/ws/jaxws/tools/WSProvideTestCase.java 2007-08-01
13:10:40 UTC (rev 4051)
+++
trunk/testsuite/src/java/org/jboss/test/ws/jaxws/tools/WSProvideTestCase.java 2007-08-01
13:27:00 UTC (rev 4052)
@@ -22,13 +22,20 @@
package org.jboss.test.ws.jaxws.tools;
import junit.framework.TestCase;
+import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.spi.tools.WSContractProvider;
+import org.w3c.dom.Element;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.PrintStream;
+import java.net.URL;
+import java.net.URLClassLoader;
-import org.jboss.wsf.spi.tools.WSContractConsumer;
-import org.jboss.wsf.spi.tools.WSContractProvider;
-
/**
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
@@ -38,8 +45,10 @@
// tools delegate
WSContractProvider provider;
- boolean toogleMessageOut;
+ // redirect tools message to System.out ?
+ boolean toogleMessageOut = false;
+ // relative to test execution
File outputDirectory;
protected void setUp() throws Exception
@@ -51,34 +60,64 @@
if(toogleMessageOut) provider.setMessageStream(System.out);
// shared output directory, relative to test execution
- outputDirectory = new File("wsprovide/java");
+ outputDirectory = new File("wsprovide/java");
}
+ private ClassLoader getArtefactClassLoader() throws Exception {
+ URLClassLoader loader = new URLClassLoader(new URL[] {
+ new
URL("file:"+System.getProperty("user.dir")+"/wsprovide/java/")
}
+ );
+
+ return loader;
+ }
+
/**
* Enables/Disables WSDL generation.
*
*/
- public void testGenerateWsdl()
+ public void testGenerateWsdl() throws Exception
{
-
+ provider.setGenerateWsdl(true);
+ provide();
+
+ verifyWSDL(outputDirectory);
}
/**
* Enables/Disables Java source generation.
*
*/
- public void testGenerateSource()
+ public void testGenerateSource() throws Exception
{
-
+ provider.setGenerateSource(true);
+ provide();
+
+ verifyJavaSource(outputDirectory);
+
}
+ private void verifyJavaSource(File directory)
+ {
+ File javaSource = new File(
+ directory.getAbsolutePath()+
+ "/org/jboss/test/ws/jaxws/tools/jaxws/AddResponse.java"
+ );
+
+ assertTrue("Source not generated", javaSource.exists());
+ }
+
/**
* Sets the main output directory.
* If the directory does not exist, it will be created.
*/
- public void testOutputDirectory()
+ public void testOutputDirectory() throws Exception
{
-
+ provide();
+ ClassLoader loader = getArtefactClassLoader();
+ Class responseWrapper =
loader.loadClass("org.jboss.test.ws.jaxws.tools.jaxws.AddResponse");
+ XmlRootElement rootElement = (XmlRootElement)
responseWrapper.getAnnotation(XmlRootElement.class);
+ assertNotNull("@XmlRootElement missing form response wrapper",
rootElement);
+ assertEquals("Wrong namespace", rootElement.namespace(),
"http://foo.bar.com/calculator");
}
/**
@@ -87,20 +126,42 @@
* If not specified, the output directory will be used instead.
*
*/
- public void testResourceDirectory()
+ public void testResourceDirectory() throws Exception
{
-
+ File directory = new File("wsprovide/resources");
+ provider.setResourceDirectory(directory);
+ provide();
+
+ verifyWSDL(directory);
}
+ private void verifyWSDL(File directory) throws Exception
+ {
+ File wsdl = new File(
+ outputDirectory.getAbsolutePath()+
+ "/WSProvideTestCase$CalculatorBeanService.wsdl"
+ );
+
+ assertTrue("WSDL not generated", wsdl.exists());
+ Element root = DOMUtils.parse( new FileInputStream(wsdl));
+ Element serviceElement = DOMUtils.getFirstChildElement(root, "service");
+ assertEquals(serviceElement.getAttribute("name"),
"WSProvideTestCase$CalculatorBeanService");
+ }
+
/**
* Sets the source directory. This directory will contain any generated Java source.
* If the directory does not exist, it will be created. If not specified,
* the output directory will be used instead.
*
*/
- public void testSourceDirectory()
+ public void testSourceDirectory() throws Exception
{
+ File sourceDir = new File("wsprovide/sources");
+ provider.setSourceDirectory(sourceDir);
+ provider.setGenerateSource(true);
+ provide();
+ verifyJavaSource(sourceDir);
}
/**
@@ -110,7 +171,7 @@
*/
public void testClassLoader()
{
-
+ System.out.println("FIXME [JBWS-1776]: Verify isolated classloading with
WSProvide");
}
/**
@@ -118,14 +179,44 @@
* would be to use System.out.
*
*/
- public void testMessageStream()
+ public void testMessageStream() throws Exception
{
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ PrintStream pout = new PrintStream(bout);
+ provider.setMessageStream(pout);
+ provide();
+
+ String messageOut = new String(bout.toByteArray());
+
+ System.out.println("-- Begin captured output --");
+ System.out.println(messageOut);
+ System.out.println("-- End captured output --");
+
+ assertTrue("Provider messages not correctly redirected",
+ messageOut.indexOf("org/jboss/test/ws/jaxws/tools/jaxws/Add.class") !=
-1 );
}
private void provide() throws Exception
{
+ //provider.setGenerateSource(true);
+ provider.setOutputDirectory(outputDirectory);
+ provider.provide(CalculatorBean.class);
+ }
+ @WebService(targetNamespace = "http://foo.bar.com/calculator")
+ public class CalculatorBean
+ {
+ @WebMethod
+ public int add(int a, int b)
+ {
+ return a+b;
+ }
+
+ @WebMethod
+ public int subtract(int a, int b)
+ {
+ return a-b;
+ }
}
-
}
Show replies by date