Author: richard.opalka(a)jboss.com
Date: 2011-05-06 05:46:18 -0400 (Fri, 06 May 2011)
New Revision: 14265
Added:
common-tools/trunk/src/test/java/org/jboss/test/ws/
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntConsumeTestCase.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntProvideTestCase.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/BuildFileTest.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CalculatorBean.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTestCase.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTracker.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTrackerFactory.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTestCase.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTracker.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTrackerFactory.java
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CommandlineTestBase.java
Removed:
common-tools/trunk/src/test/java/org/jboss/test/wsf/
Modified:
common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSConsumeTask.java
common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSProvideTask.java
common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSConsume.java
common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSProvide.java
common-tools/trunk/src/test/resources/smoke/tools/provide-test.xml
Log:
[JBWS-3289] refactoring packages: org.jboss.wsf.spi.tools -> org.jboss.ws.api.tools
Modified: common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSConsumeTask.java
===================================================================
--- common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSConsumeTask.java 2011-05-06
09:43:46 UTC (rev 14264)
+++ common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSConsumeTask.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -38,7 +38,7 @@
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.CommandlineJava.SysProperties;
-import org.jboss.wsf.spi.tools.WSContractConsumer;
+import org.jboss.ws.api.tools.WSContractConsumer;
/**
* Ant task which consumes a Web Service contract.
Modified: common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSProvideTask.java
===================================================================
--- common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSProvideTask.java 2011-05-06
09:43:46 UTC (rev 14264)
+++ common-tools/trunk/src/main/java/org/jboss/ws/tools/ant/WSProvideTask.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -33,7 +33,7 @@
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.CommandlineJava.SysProperties;
import org.apache.tools.ant.types.Environment.Variable;
-import org.jboss.wsf.spi.tools.WSContractProvider;
+import org.jboss.ws.api.tools.WSContractProvider;
import java.io.File;
import java.io.PrintStream;
Modified: common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSConsume.java
===================================================================
--- common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSConsume.java 2011-05-06
09:43:46 UTC (rev 14264)
+++ common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSConsume.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -27,7 +27,7 @@
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
-import org.jboss.wsf.spi.tools.WSContractConsumer;
+import org.jboss.ws.api.tools.WSContractConsumer;
import java.io.File;
import java.io.PrintStream;
Modified: common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSProvide.java
===================================================================
--- common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSProvide.java 2011-05-06
09:43:46 UTC (rev 14264)
+++ common-tools/trunk/src/main/java/org/jboss/ws/tools/cmd/WSProvide.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -35,7 +35,7 @@
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
-import org.jboss.wsf.spi.tools.WSContractProvider;
+import org.jboss.ws.api.tools.WSContractProvider;
/**
* WSProvideTask is a cmd line tool that generates portable JAX-WS artifacts
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntConsumeTestCase.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntConsumeTestCase.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntConsumeTestCase.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+/**
+ * Test the WSConsumeTask.
+ * This test needs to be executed in 'SPI_HOME/output/tests',
+ * because it works with relative paths.
+ *
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class AntConsumeTestCase extends BuildFileTest
+{
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // cleanup events
+ CmdConsumeTracker.LAST_EVENT = "";
+
+ // enforce loading of the tracker implemenation
+ System.setProperty("org.jboss.ws.api.tools.ConsumerFactory",
"org.jboss.test.ws.tools.CmdConsumeTrackerFactory");
+
+ configureProject("src/test/resources/smoke/tools/consume-test.xml");
+ }
+
+ public void testPlainInvocation()
+ {
+ executeTarget("plainInvocation");
+ assertTrue("consume() not invoked",
CmdConsumeTracker.LAST_EVENT.indexOf("consume") != -1);
+ }
+
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntProvideTestCase.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntProvideTestCase.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/AntProvideTestCase.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class AntProvideTestCase extends BuildFileTest
+{
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // cleanup events
+ CmdProvideTracker.LAST_EVENT = "";
+
+ // enforce loading of the tracker implemenation
+ System.setProperty("org.jboss.ws.api.tools.ProviderFactory",
"org.jboss.test.ws.tools.CmdProvideTrackerFactory");
+
+ configureProject("src/test/resources/smoke/tools/provide-test.xml");
+ }
+
+ public void testPlainInvocation()
+ {
+ executeTarget("plainInvocation");
+ assertTrue("provide() not invoked",
CmdProvideTracker.LAST_EVENT.indexOf("provide") != -1);
+ }
+
+ public void testIncludeWSDL()
+ {
+ executeTarget("includeWSDL");
+ assertTrue("setGenerateWsdl() not invoked",
CmdProvideTracker.LAST_EVENT.indexOf("setGenerateWsdl") != -1);
+ }
+
+ public void testExtraClasspath()
+ {
+ executeTarget("extraClasspath");
+
+ }
+
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/BuildFileTest.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/BuildFileTest.java
(rev 0)
+++ common-tools/trunk/src/test/java/org/jboss/test/ws/tools/BuildFileTest.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,543 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.jboss.test.ws.tools;
+
+import junit.framework.TestCase;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectHelper;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.net.URL;
+
+/**
+ * A BuildFileTest is a TestCase which executes targets from an Ant buildfile
+ * for testing.
+ *
+ * This class provides a number of utility methods for particular build file
+ * tests which extend this class.
+ *
+ * @author Apache Ant contributors
+ */
+public abstract class BuildFileTest extends TestCase {
+
+ protected Project project;
+
+ private StringBuffer logBuffer;
+ private StringBuffer fullLogBuffer;
+ private StringBuffer outBuffer;
+ private StringBuffer errBuffer;
+ private BuildException buildException;
+
+ /**
+ * Default constructor for the BuildFileTest object.
+ */
+ public BuildFileTest() {
+ super();
+ }
+
+ /**
+ * Constructor for the BuildFileTest object.
+ *
+ * @param name string to pass up to TestCase constructor
+ */
+ public BuildFileTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Automatically calls the target called "tearDown"
+ * from the build file tested if it exits.
+ *
+ * This allows to use Ant tasks directly in the build file
+ * to clean up after each test. Note that no "setUp" target
+ * is automatically called, since it's trivial to have a
+ * test target depend on it.
+ */
+ protected void tearDown() throws Exception {
+ if (project == null) {
+ /*
+ * Maybe the BuildFileTest was subclassed and there is
+ * no initialized project. So we could avoid getting a
+ * NPE.
+ * If there is an initialized project getTargets() does
+ * not return null as it is initialized by an empty
+ * HashSet.
+ */
+ return;
+ }
+ final String tearDown = "tearDown";
+ if (project.getTargets().containsKey(tearDown)) {
+ project.executeTarget(tearDown);
+ }
+ }
+
+ /**
+ * run a target, expect for any build exception
+ *
+ * @param target target to run
+ * @param cause information string to reader of report
+ */
+ public void expectBuildException(String target, String cause) {
+ expectSpecificBuildException(target, cause, null);
+ }
+
+ /**
+ * Assert that only the given message has been logged with a
+ * priority <= INFO when running the given target.
+ */
+ public void expectLog(String target, String log) {
+ executeTarget(target);
+ String realLog = getLog();
+ assertEquals(log, realLog);
+ }
+
+ /**
+ * Assert that the given substring is in the log messages.
+ */
+ public void assertLogContaining(String substring) {
+ String realLog = getLog();
+ assertTrue("expecting log to contain \"" + substring + "\"
log was \""
+ + realLog + "\"",
+ realLog.indexOf(substring) >= 0);
+ }
+
+ /**
+ * Assert that the given substring is in the output messages.
+ * @since Ant1.7
+ */
+ public void assertOutputContaining(String substring) {
+ String realOutput = getOutput();
+ assertTrue("expecting output to contain \"" + substring
+ + "\" output was \"" + realOutput + "\"",
+ realOutput.indexOf(substring) >= 0);
+ }
+
+ /**
+ * Assert that the given message has been logged with a priority
+ * <= INFO when running the given target.
+ */
+ public void expectLogContaining(String target, String log) {
+ executeTarget(target);
+ assertLogContaining(log);
+ }
+
+ /**
+ * Gets the log the BuildFileTest object.
+ * Only valid if configureProject() has been called.
+ *
+ * @pre logBuffer!=null
+ * @return The log value
+ */
+ public String getLog() {
+ return logBuffer.toString();
+ }
+
+ /**
+ * Assert that the given message has been logged with a priority
+ * >= VERBOSE when running the given target.
+ */
+ public void expectDebuglog(String target, String log) {
+ executeTarget(target);
+ String realLog = getFullLog();
+ assertEquals(log, realLog);
+ }
+
+ /**
+ * Assert that the given substring is in the log messages.
+ */
+ public void assertDebuglogContaining(String substring) {
+ String realLog = getFullLog();
+ assertTrue("expecting debug log to contain \"" + substring
+ + "\" log was \""
+ + realLog + "\"",
+ realLog.indexOf(substring) >= 0);
+ }
+
+ /**
+ * Gets the log the BuildFileTest object.
+ *
+ * Only valid if configureProject() has been called.
+ *
+ * @pre fullLogBuffer!=null
+ * @return The log value
+ */
+ public String getFullLog() {
+ return fullLogBuffer.toString();
+ }
+
+ /**
+ * execute the target, verify output matches expectations
+ *
+ * @param target target to execute
+ * @param output output to look for
+ */
+ public void expectOutput(String target, String output) {
+ executeTarget(target);
+ String realOutput = getOutput();
+ assertEquals(output, realOutput.trim());
+ }
+
+ /**
+ * Executes the target, verify output matches expectations
+ * and that we got the named error at the end
+ *
+ * @param target target to execute
+ * @param output output to look for
+ * @param error Description of Parameter
+ */
+ public void expectOutputAndError(String target, String output, String error) {
+ executeTarget(target);
+ String realOutput = getOutput();
+ assertEquals(output, realOutput);
+ String realError = getError();
+ assertEquals(error, realError);
+ }
+
+ public String getOutput() {
+ return cleanBuffer(outBuffer);
+ }
+
+ public String getError() {
+ return cleanBuffer(errBuffer);
+ }
+
+ public BuildException getBuildException() {
+ return buildException;
+ }
+
+ private String cleanBuffer(StringBuffer buffer) {
+ StringBuffer cleanedBuffer = new StringBuffer();
+ boolean cr = false;
+ for (int i = 0; i < buffer.length(); i++) {
+ char ch = buffer.charAt(i);
+ if (ch == '\r') {
+ cr = true;
+ continue;
+ }
+
+ if (!cr) {
+ cleanedBuffer.append(ch);
+ } else {
+ cleanedBuffer.append(ch);
+ }
+ }
+ return cleanedBuffer.toString();
+ }
+
+ /**
+ * Sets up to run the named project
+ *
+ * @param filename name of project file to run
+ */
+ public void configureProject(String filename) throws BuildException {
+ configureProject(filename, Project.MSG_DEBUG);
+ }
+
+ /**
+ * Sets up to run the named project
+ *
+ * @param filename name of project file to run
+ */
+ public void configureProject(String filename, int logLevel)
+ throws BuildException {
+ logBuffer = new StringBuffer();
+ fullLogBuffer = new StringBuffer();
+ project = new Project();
+ project.init();
+ File antFile = new File(System.getProperty("root"), filename);
+ project.setUserProperty("ant.file" , antFile.getAbsolutePath());
+ project.addBuildListener(new AntTestListener(logLevel));
+ ProjectHelper.configureProject(project, antFile);
+ }
+
+ /**
+ * Executes a target we have set up
+ *
+ * @pre configureProject has been called
+ * @param targetName target to run
+ */
+ public void executeTarget(String targetName) {
+ PrintStream sysOut = System.out;
+ PrintStream sysErr = System.err;
+ try {
+ sysOut.flush();
+ sysErr.flush();
+ outBuffer = new StringBuffer();
+ PrintStream out = new PrintStream(new AntOutputStream(outBuffer));
+ System.setOut(out);
+ errBuffer = new StringBuffer();
+ PrintStream err = new PrintStream(new AntOutputStream(errBuffer));
+ System.setErr(err);
+ logBuffer = new StringBuffer();
+ fullLogBuffer = new StringBuffer();
+ buildException = null;
+ project.executeTarget(targetName);
+ } finally {
+ System.setOut(sysOut);
+ System.setErr(sysErr);
+ }
+
+ }
+
+ /**
+ * Get the project which has been configured for a test.
+ *
+ * @return the Project instance for this test.
+ */
+ public Project getProject() {
+ return project;
+ }
+
+ /**
+ * Gets the directory of the project.
+ *
+ * @return the base dir of the project
+ */
+ public File getProjectDir() {
+ return project.getBaseDir();
+ }
+
+ /**
+ * Runs a target, wait for a build exception.
+ *
+ * @param target target to run
+ * @param cause information string to reader of report
+ * @param msg the message value of the build exception we are waiting
+ * for set to null for any build exception to be valid
+ */
+ public void expectSpecificBuildException(String target, String cause, String msg) {
+ try {
+ executeTarget(target);
+ } catch (org.apache.tools.ant.BuildException ex) {
+ buildException = ex;
+ if ((null != msg) && (!ex.getMessage().equals(msg))) {
+ fail("Should throw BuildException because '" + cause
+ + "' with message '" + msg
+ + "' (actual message '" + ex.getMessage() + "'
instead)");
+ }
+ return;
+ }
+ fail("Should throw BuildException because: " + cause);
+ }
+
+ /**
+ * run a target, expect an exception string
+ * containing the substring we look for (case sensitive match)
+ *
+ * @param target target to run
+ * @param cause information string to reader of report
+ * @param contains substring of the build exception to look for
+ */
+ public void expectBuildExceptionContaining(String target, String cause, String
contains) {
+ try {
+ executeTarget(target);
+ } catch (org.apache.tools.ant.BuildException ex) {
+ buildException = ex;
+ if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) {
+ fail("Should throw BuildException because '" + cause +
"' with message containing '" + contains + "' (actual message
'" + ex.getMessage() + "' instead)");
+ }
+ return;
+ }
+ fail("Should throw BuildException because: " + cause);
+ }
+
+ /**
+ * call a target, verify property is as expected
+ *
+ * @param target build file target
+ * @param property property name
+ * @param value expected value
+ */
+ public void expectPropertySet(String target, String property, String value) {
+ executeTarget(target);
+ assertPropertyEquals(property, value);
+ }
+
+ /**
+ * assert that a property equals a value; comparison is case sensitive.
+ *
+ * @param property property name
+ * @param value expected value
+ */
+ public void assertPropertyEquals(String property, String value) {
+ String result = project.getProperty(property);
+ assertEquals("property " + property,value,result);
+ }
+
+ /**
+ * assert that a property equals "true".
+ *
+ * @param property property name
+ */
+ public void assertPropertySet(String property) {
+ assertPropertyEquals(property, "true");
+ }
+
+ /**
+ * assert that a property is null.
+ *
+ * @param property property name
+ */
+ public void assertPropertyUnset(String property) {
+ assertPropertyEquals(property, null);
+ }
+
+ /**
+ * call a target, verify named property is "true".
+ *
+ * @param target build file target
+ * @param property property name
+ */
+ public void expectPropertySet(String target, String property) {
+ expectPropertySet(target, property, "true");
+ }
+
+ /**
+ * Call a target, verify property is null.
+ *
+ * @param target build file target
+ * @param property property name
+ */
+ public void expectPropertyUnset(String target, String property) {
+ expectPropertySet(target, property, null);
+ }
+
+ /**
+ * Retrieve a resource from the caller classloader to avoid
+ * assuming a vm working directory. The resource path must be
+ * relative to the package name or absolute from the root path.
+ *
+ * @param resource the resource to retrieve its url.
+ * @throws junit.framework.AssertionFailedError if the resource is not found.
+ */
+ public URL getResource(String resource){
+ URL url = getClass().getResource(resource);
+ assertNotNull("Could not find resource :" + resource, url);
+ return url;
+ }
+
+ /**
+ * an output stream which saves stuff to our buffer.
+ */
+ private static class AntOutputStream extends java.io.OutputStream {
+ private StringBuffer buffer;
+
+ public AntOutputStream( StringBuffer buffer ) {
+ this.buffer = buffer;
+ }
+
+ public void write(int b) {
+ buffer.append((char)b);
+ }
+ }
+
+ /**
+ * Our own personal build listener.
+ */
+ private class AntTestListener implements BuildListener
+ {
+ private int logLevel;
+
+ /**
+ * Constructs a test listener which will ignore log events
+ * above the given level.
+ */
+ public AntTestListener(int logLevel) {
+ this.logLevel = logLevel;
+ }
+
+ /**
+ * Fired before any targets are started.
+ */
+ public void buildStarted(BuildEvent event) {
+ }
+
+ /**
+ * Fired after the last target has finished. This event
+ * will still be thrown if an error occurred during the build.
+ *
+ * @see BuildEvent#getException()
+ */
+ public void buildFinished(BuildEvent event) {
+ }
+
+ /**
+ * Fired when a target is started.
+ *
+ * @see BuildEvent#getTarget()
+ */
+ public void targetStarted(BuildEvent event) {
+ System.out.println("targetStarted " + event.getTarget().getName());
+ }
+
+ /**
+ * Fired when a target has finished. This event will
+ * still be thrown if an error occurred during the build.
+ *
+ * @see BuildEvent#getException()
+ */
+ public void targetFinished(BuildEvent event) {
+ System.out.println("targetFinished " + event.getTarget().getName());
+ }
+
+ /**
+ * Fired when a task is started.
+ *
+ * @see BuildEvent#getTask()
+ */
+ public void taskStarted(BuildEvent event) {
+ //System.out.println("taskStarted " + event.getTask().getTaskName());
+ }
+
+ /**
+ * Fired when a task has finished. This event will still
+ * be throw if an error occurred during the build.
+ *
+ * @see BuildEvent#getException()
+ */
+ public void taskFinished(BuildEvent event) {
+ //System.out.println("taskFinished " +
event.getTask().getTaskName());
+ }
+
+ /**
+ * Fired whenever a message is logged.
+ *
+ * @see BuildEvent#getMessage()
+ * @see BuildEvent#getPriority()
+ */
+ public void messageLogged(BuildEvent event) {
+ if (event.getPriority() > logLevel) {
+ // ignore event
+ return;
+ }
+
+ if (event.getPriority() == Project.MSG_INFO ||
+ event.getPriority() == Project.MSG_WARN ||
+ event.getPriority() == Project.MSG_ERR) {
+ logBuffer.append(event.getMessage());
+ }
+ fullLogBuffer.append(event.getMessage());
+ }
+ }
+
+}
+
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CalculatorBean.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CalculatorBean.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CalculatorBean.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+// We just need to load it, therefore we skip the JSR 181 annotations here
+public class CalculatorBean
+{
+ public int add(int a, int b)
+ {
+ return a+b;
+ }
+
+ public int subtract(int a, int b)
+ {
+ return a-b;
+ }
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTestCase.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTestCase.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTestCase.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import org.jboss.ws.tools.cmd.WSConsume;
+
+/**
+ * Test the command line interface to WSConsume.
+ *
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class CmdConsumeTestCase extends CommandlineTestBase
+{
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // cleanup events
+ CmdConsumeTracker.LAST_EVENT = "";
+
+ // enforce loading of the tracker implemenation
+ System.setProperty(
+ "org.jboss.ws.api.tools.ConsumerFactory",
+ "org.jboss.test.ws.tools.CmdConsumeTrackerFactory"
+ );
+ }
+
+ public void testInvalidBindingOption() throws Exception
+ {
+ executeCmd("-b", true);
+ }
+
+ public void testValidBindingOption() throws Exception
+ {
+ executeCmd("-b binding-file.xml Service.wsdl", false);
+ assertTrue("setBindingFiles() not invoked",
CmdConsumeTracker.LAST_EVENT.indexOf("setBindingFiles")!=-1);
+ }
+
+ public void testMissingOptions() throws Exception
+ {
+ executeCmd(null, true);
+ }
+
+ // TODO: add arbitrary combinations on a case by case basis
+
+
+ void runDelegate(String[] args) throws Exception
+ {
+ WSConsume.main(args);
+ }
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTracker.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTracker.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTracker.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import org.jboss.ws.api.tools.WSContractConsumer;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.util.List;
+import java.net.URL;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class CmdConsumeTracker extends WSContractConsumer
+{
+ public static String LAST_EVENT = "";
+
+ @Override
+ public void setBindingFiles(List<File> bindingFiles)
+ {
+ LAST_EVENT += "setBindingFiles";
+ }
+
+ @Override
+ public void setCatalog(File catalog)
+ {
+ LAST_EVENT += "setCatalog";
+ }
+
+ @Override
+ public void setOutputDirectory(File directory)
+ {
+ LAST_EVENT += "setOutputDirectory";
+ }
+
+ @Override
+ public void setSourceDirectory(File directory)
+ {
+ LAST_EVENT += "setSourceDirectory";
+ }
+
+ @Override
+ public void setGenerateSource(boolean generateSource)
+ {
+ LAST_EVENT += "setGenerateSource";
+ }
+
+ @Override
+ public void setTargetPackage(String targetPackage)
+ {
+ LAST_EVENT += "setTargetPackage";
+ }
+
+ @Override
+ public void setWsdlLocation(String wsdlLocation)
+ {
+ LAST_EVENT += "setWsdlLocation";
+ }
+
+ @Override
+ public void setMessageStream(PrintStream messageStream)
+ {
+ LAST_EVENT += "setMessageStream";
+ }
+
+ @Override
+ public void setAdditionalCompilerClassPath(List<String> classPath)
+ {
+ LAST_EVENT += "setAdditionalCompilerClassPath";
+ }
+
+ @Override
+ public void setAdditionalHeaders(boolean additionalHeaders)
+ {
+ LAST_EVENT += "setAdditionalHeaders";
+ }
+
+ @Override
+ public void setTarget(String target)
+ {
+ LAST_EVENT += "setTarget";
+ }
+
+ @Override
+ public void consume(URL wsdl)
+ {
+ LAST_EVENT += "consume";
+ }
+
+ @Override
+ public void setExtension(boolean extension)
+ {
+ LAST_EVENT += "setExtension";
+ }
+
+ @Override
+ public void setNoCompile(boolean nocompile)
+ {
+ LAST_EVENT += "setNoCompile";
+ }
+}
Added:
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTrackerFactory.java
===================================================================
---
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTrackerFactory.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdConsumeTrackerFactory.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import org.jboss.ws.api.tools.WSContractConsumerFactory;
+import org.jboss.ws.api.tools.WSContractConsumer;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class CmdConsumeTrackerFactory implements WSContractConsumerFactory
+{
+
+ public WSContractConsumer createConsumer()
+ {
+ return new CmdConsumeTracker();
+ }
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTestCase.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTestCase.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTestCase.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import org.jboss.ws.tools.cmd.WSProvide;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class CmdProvideTestCase extends CommandlineTestBase
+{
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // clear events
+ CmdProvideTracker.LAST_EVENT = "";
+
+ // enforce loading of the tracker implemenation
+ System.setProperty(
+ "org.jboss.ws.api.tools.ProviderFactory",
+ "org.jboss.test.ws.tools.CmdProvideTrackerFactory"
+ );
+ }
+
+ /** <pre>
+ * usage: WSProvideTask [options] <endpoint class name>
+ * options:
+ * -h, --help Show this help message
+ * -k, --keep Keep/Generate Java source
+ * -w, --wsdl Enable WSDL file generation
+ * -c, --classpath=<path< The classpath that contains the endpoint
+ * -o, --output=<directory> The directory to put generated artifacts
+ * -r, --resource=<directory> The directory to put resource artifacts
+ * -s, --source=<directory> The directory to put Java source
+ * -q, --quiet Be somewhat more quiet
+ * -t, --show-traces Show full exception stack traces
+ * -l, --load-provider Load the provider and exit (debug utility)
+ * </pre>
+ * */
+
+ public void testMissingOptions() throws Exception
+ {
+ executeCmd(null, true);
+ }
+
+ public void testValidOutputDir() throws Exception
+ {
+ executeCmd("-o outputDir org.jboss.test.ws.tools.CalculatorBean",
false);
+ assertTrue("setOutputDirectory() not invoked",
CmdProvideTracker.LAST_EVENT.indexOf("setOutputDirectory")!=-1);
+ }
+
+ void runDelegate(String[] args) throws Exception
+ {
+ WSProvide.main(args);
+ }
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTracker.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTracker.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTracker.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import org.jboss.ws.api.tools.WSContractProvider;
+
+import java.io.File;
+import java.io.PrintStream;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class CmdProvideTracker extends WSContractProvider
+{
+
+ public static String LAST_EVENT = "";
+
+ public void setGenerateWsdl(boolean generateWsdl)
+ {
+ LAST_EVENT += "setGenerateWsdl";
+ }
+
+ public void setExtension(boolean extension)
+ {
+ LAST_EVENT += "setExtension";
+ }
+
+ public void setGenerateSource(boolean generateSource)
+ {
+ LAST_EVENT += "setGenerateSource";
+ }
+
+ public void setOutputDirectory(File directory)
+ {
+ LAST_EVENT += "setOutputDirectory";
+ }
+
+ public void setResourceDirectory(File directory)
+ {
+ LAST_EVENT += "setResourceDirectory";
+ }
+
+ public void setSourceDirectory(File directory)
+ {
+ LAST_EVENT += "setSourceDirectory";
+ }
+
+ public void setClassLoader(ClassLoader loader)
+ {
+ LAST_EVENT += "setClassLoader";
+ }
+
+ public void provide(String endpointClass)
+ {
+ LAST_EVENT += "provide";
+ }
+
+ public void provide(Class<?> endpointClass)
+ {
+ LAST_EVENT += "provide";
+ }
+
+ public void setMessageStream(PrintStream messageStream)
+ {
+ LAST_EVENT += "setMessageStream";
+ }
+}
Added:
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTrackerFactory.java
===================================================================
---
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTrackerFactory.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CmdProvideTrackerFactory.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import org.jboss.ws.api.tools.WSContractProviderFactory;
+import org.jboss.ws.api.tools.WSContractProvider;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public class CmdProvideTrackerFactory implements WSContractProviderFactory
+{
+
+ public WSContractProvider createProvider(ClassLoader loader)
+ {
+ return new CmdProvideTracker();
+ }
+}
Added: common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CommandlineTestBase.java
===================================================================
--- common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CommandlineTestBase.java
(rev 0)
+++
common-tools/trunk/src/test/java/org/jboss/test/ws/tools/CommandlineTestBase.java 2011-05-06
09:46:18 UTC (rev 14265)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.tools;
+
+import junit.framework.TestCase;
+
+import java.security.Permission;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ */
+public abstract class CommandlineTestBase extends TestCase
+{
+ SecurityManager systemDefault = System.getSecurityManager();
+ SecurityManager interceptor = new InterceptedSecurity();
+
+ protected void swapSecurityManager()
+ {
+ if(System.getSecurityManager() instanceof InterceptedSecurity)
+ System.setSecurityManager(systemDefault);
+ else
+ System.setSecurityManager(interceptor);
+ }
+
+ class InterceptedSecurity extends SecurityManager
+ {
+ private final SecurityManager parent = systemDefault;
+
+ public void checkPermission(Permission perm)
+ {
+ if (parent != null)
+ {
+ parent.checkPermission(perm);
+ }
+ }
+
+ public void checkExit(int status)
+ {
+ String msg = (status == 0) ? "Delegate did exit without errors" :
"Delegate did exit with an error";
+ throw new InterceptedExit(msg, status);
+ }
+ }
+
+ static protected class InterceptedExit extends SecurityException
+ {
+ private static final long serialVersionUID = 1L;
+ private int exitCode;
+
+ public InterceptedExit(String s, int code)
+ {
+ super(s);
+ this.exitCode = code;
+ }
+
+
+ public int getExitCode()
+ {
+ return exitCode;
+ }
+ }
+
+ protected void executeCmd(String arguments, boolean expectedException) throws
Exception
+ {
+ swapSecurityManager();
+
+ String[] args = arguments!=null ? arguments.split("\\s"): new String[0];
+ try
+ {
+ runDelegate(args);
+ if(expectedException)
+ fail("Did expect exception on args: " +args);
+ }
+ catch (CommandlineTestBase.InterceptedExit e)
+ {
+ boolean positivStatus = (e.getExitCode() == 0);
+ if( (expectedException && positivStatus)
+ || (!expectedException && !positivStatus) )
+ {
+ String s = expectedException ? "Did expect an exception, but " :
"Did not expect an exception, but ";
+ String s2 = positivStatus ? "status was positiv" : "status was
negativ";
+ throw new Exception(s+s2);
+ }
+
+ }
+ finally
+ {
+ swapSecurityManager();
+ }
+ }
+
+ // the actual tools execution
+ abstract void runDelegate(String[] args) throws Exception;
+
+}
Modified: common-tools/trunk/src/test/resources/smoke/tools/provide-test.xml
===================================================================
--- common-tools/trunk/src/test/resources/smoke/tools/provide-test.xml 2011-05-06 09:43:46
UTC (rev 14264)
+++ common-tools/trunk/src/test/resources/smoke/tools/provide-test.xml 2011-05-06 09:46:18
UTC (rev 14265)
@@ -16,15 +16,15 @@
</taskdef>
<target name="plainInvocation">
- <wsprovide genwsdl="false"
sei="org.jboss.test.wsf.spi.smoke.tools.CalculatorBean"/>
+ <wsprovide genwsdl="false"
sei="org.jboss.test.ws.tools.CalculatorBean"/>
</target>
<target name="includeWSDL">
- <wsprovide genwsdl="true"
sei="org.jboss.test.wsf.spi.smoke.tools.CalculatorBean"/>
+ <wsprovide genwsdl="true"
sei="org.jboss.test.ws.tools.CalculatorBean"/>
</target>
<target name="extraClasspath">
- <wsprovide genwsdl="false"
sei="org.jboss.test.wsf.spi.smoke.tools.CalculatorBean">
+ <wsprovide genwsdl="false"
sei="org.jboss.test.ws.tools.CalculatorBean">
<classpath>
<pathelement location="${spi.dir}/output/test/classes"/>
</classpath>