Author: veithen
Date: Thu Feb  9 22:27:18 2012
New Revision: 1242566

URL: http://svn.apache.org/viewvc?rev=1242566&view=rev
Log:
Process deployments/undeployments using maven-axis-server-plugin instead of 
executing AdminClient from within the unit tests.

Modified:
    
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java
    
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/Server.java
    
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/ServerManager.java
    
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java
    axis/axis1/java/trunk/samples/attachments-sample/pom.xml
    
axis/axis1/java/trunk/samples/attachments-sample/src/test/java/test/functional/TestAttachmentsSample.java

Modified: 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java?rev=1242566&r1=1242565&r2=1242566&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java
 (original)
+++ 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/DefaultServerManager.java
 Thu Feb  9 22:27:18 2012
@@ -44,7 +44,21 @@ public class DefaultServerManager implem
         this.logger = logger;
     }
 
-    public void startServer(String jvm, String[] classpath, int port, String[] 
vmArgs, File workDir, String[] wsddFiles, File[] jwsDirs, int timeout) throws 
Exception {
+    private void process(AdminClient adminClient, File[] wsddFiles) throws 
Exception {
+        for (int i=0; i<wsddFiles.length; i++) {
+            File wsddFile = wsddFiles[i];
+            if (logger.isDebugEnabled()) {
+                logger.debug("Starting to process " + wsddFile);
+            }
+            String result = adminClient.process(wsddFile.getPath());
+            if (logger.isDebugEnabled()) {
+                logger.debug("AdminClient result: " + result);
+            }
+            logger.info("Processed " + wsddFile);
+        }
+    }
+    
+    public void startServer(String jvm, String[] classpath, int port, String[] 
vmArgs, File workDir, File[] deployments, File[] undeployments, File[] jwsDirs, 
int timeout) throws Exception {
         AdminClient adminClient = new AdminClient(true);
         adminClient.setTargetEndpointAddress(new URL("http://localhost:"; + 
port + "/axis/services/AdminService"));
         List cmdline = new ArrayList();
@@ -65,7 +79,7 @@ public class DefaultServerManager implem
             logger.debug("Starting process with command line: " + cmdline);
         }
         Process process = 
Runtime.getRuntime().exec((String[])cmdline.toArray(new 
String[cmdline.size()]), null, workDir);
-        servers.put(Integer.valueOf(port), new Server(process, adminClient));
+        servers.put(Integer.valueOf(port), new Server(process, adminClient, 
undeployments));
         new Thread(new StreamPump(process.getInputStream(), System.out), 
"axis-server-" + port + "-stdout").start();
         new Thread(new StreamPump(process.getErrorStream(), System.err), 
"axis-server-" + port + "-stderr").start();
         
@@ -95,24 +109,14 @@ public class DefaultServerManager implem
         }
         
         // Deploy services
-        if (wsddFiles != null) {
-            for (int i=0; i<wsddFiles.length; i++) {
-                String wsddFile = wsddFiles[i];
-                if (logger.isDebugEnabled()) {
-                    logger.debug("Starting deployment of " + wsddFile);
-                }
-                String result = adminClient.process(wsddFile);
-                if (logger.isDebugEnabled()) {
-                    logger.debug("AdminClient result: " + result);
-                }
-                logger.info("Deployed " + wsddFile);
-            }
-        }
+        process(adminClient, deployments);
     }
     
     public void stopServer(int port) throws Exception {
         Server server = (Server)servers.remove(Integer.valueOf(port));
-        server.getAdminClient().quit();
+        AdminClient adminClient = server.getAdminClient();
+        process(adminClient, server.getUndeployments());
+        adminClient.quit();
         server.getProcess().waitFor();
         logger.info("Server on port " + port + " stopped");
     }

Modified: 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/Server.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/Server.java?rev=1242566&r1=1242565&r2=1242566&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/Server.java
 (original)
+++ 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/Server.java
 Thu Feb  9 22:27:18 2012
@@ -18,15 +18,19 @@
  */
 package org.apache.axis.maven;
 
+import java.io.File;
+
 import org.apache.axis.client.AdminClient;
 
 public class Server {
     private final Process process;
     private final AdminClient adminClient;
+    private final File[] undeployments;
 
-    public Server(Process process, AdminClient adminClient) {
+    public Server(Process process, AdminClient adminClient, File[] 
undeployments) {
         this.process = process;
         this.adminClient = adminClient;
+        this.undeployments = undeployments;
     }
 
     public Process getProcess() {
@@ -36,4 +40,8 @@ public class Server {
     public AdminClient getAdminClient() {
         return adminClient;
     }
+
+    public File[] getUndeployments() {
+        return undeployments;
+    }
 }

Modified: 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/ServerManager.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/ServerManager.java?rev=1242566&r1=1242565&r2=1242566&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/ServerManager.java
 (original)
+++ 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/ServerManager.java
 Thu Feb  9 22:27:18 2012
@@ -21,6 +21,6 @@ package org.apache.axis.maven;
 import java.io.File;
 
 public interface ServerManager {
-    void startServer(String jvm, String[] classpath, int port, String[] 
vmArgs, File workDir, String[] wsddFiles, File[] jwsDirs, int timeout) throws 
Exception;
+    void startServer(String jvm, String[] classpath, int port, String[] 
vmArgs, File workDir, File[] deployments, File[] undeployments, File[] jwsDirs, 
int timeout) throws Exception;
     void stopServer(int port) throws Exception;
 }

Modified: 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java?rev=1242566&r1=1242565&r2=1242566&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java
 (original)
+++ 
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/maven/StartServerMojo.java
 Thu Feb  9 22:27:18 2012
@@ -24,6 +24,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.axis.transport.http.SimpleAxisServer;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.execution.MavenSession;
@@ -35,6 +39,7 @@ import org.apache.maven.toolchain.Toolch
 import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
+import org.w3c.dom.Element;
 
 /**
  * Start a {@link SimpleAxisServer} instance in a separate JVM.
@@ -75,7 +80,9 @@ public class StartServerMojo extends Abs
     private File workDirBase;
     
     /**
-     * A set of WSDD files for services to deploy.
+     * A set of WSDD files for services to deploy. The WSDD files may be 
deployment or undeployment
+     * requests. Undeployment requests will be processed when the server is 
stopped. The primary use
+     * case for this is to test undeployment.
      * 
      * @parameter
      */
@@ -166,23 +173,49 @@ public class StartServerMojo extends Abs
         }
         
         // Select WSDD files
-        List wsddFiles;
+        List deployments = new ArrayList();
+        List undeployments = new ArrayList();
         if (wsdds != null && wsdds.length > 0) {
-            wsddFiles = new ArrayList();
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            DocumentBuilder documentBuilder;
+            try {
+                documentBuilder = dbf.newDocumentBuilder();
+            } catch (ParserConfigurationException ex) {
+                throw new MojoFailureException("Unable to initialize DOM 
parser", ex);
+            }
             for (int i=0; i<wsdds.length; i++) {
                 FileSet wsdd = wsdds[i];
                 DirectoryScanner scanner = wsdd.createScanner();
                 scanner.scan();
                 String[] includedFiles = scanner.getIncludedFiles();
                 for (int j=0; j<includedFiles.length; j++) {
-                    wsddFiles.add(new File(wsdd.getDirectory(), 
includedFiles[j]).getPath());
+                    File wsddFile = new File(wsdd.getDirectory(), 
includedFiles[j]);
+                    Element wsddElement;
+                    try {
+                        wsddElement = 
documentBuilder.parse(wsddFile).getDocumentElement();
+                    } catch (Exception ex) {
+                        log.warn("Skipping " + wsddFile + ": not an XML file", 
ex);
+                        continue;
+                    }
+                    if 
("http://xml.apache.org/axis/wsdd/".equals(wsddElement.getNamespaceURI())) {
+                        String type = wsddElement.getLocalName();
+                        if (type.equals("deployment")) {
+                            deployments.add(wsddFile);
+                        } else if (type.equals("undeployment")) {
+                            undeployments.add(wsddFile);
+                        } else {
+                            log.warn("Skipping " + wsddFile + ": unexpected 
WSDD type");
+                        }
+                    } else {
+                        log.warn("Skipping " + wsddFile + ": not a WSDD file");
+                    }
                 }
             }
             if (log.isDebugEnabled()) {
-                log.debug("WSDD files: " + wsddFiles);
+                log.debug("Deployments: " + deployments);
+                log.debug("Undeployments: " + undeployments);
             }
-        } else {
-            wsddFiles = null;
         }
         
         // Compute JVM arguments
@@ -235,7 +268,8 @@ public class StartServerMojo extends Abs
                     getPort(),
                     (String[])vmArgs.toArray(new String[vmArgs.size()]),
                     workDir,
-                    wsddFiles == null ? null : (String[])wsddFiles.toArray(new 
String[wsddFiles.size()]),
+                    (File[])deployments.toArray(new File[deployments.size()]),
+                    (File[])undeployments.toArray(new 
File[undeployments.size()]),
                     jwsDirs,
                     debug || foreground ? Integer.MAX_VALUE : 20000);
         } catch (Exception ex) {

Modified: axis/axis1/java/trunk/samples/attachments-sample/pom.xml
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/samples/attachments-sample/pom.xml?rev=1242566&r1=1242565&r2=1242566&view=diff
==============================================================================
--- axis/axis1/java/trunk/samples/attachments-sample/pom.xml (original)
+++ axis/axis1/java/trunk/samples/attachments-sample/pom.xml Thu Feb  9 
22:27:18 2012
@@ -67,6 +67,16 @@
                         <goals>
                             <goal>start-server</goal>
                         </goals>
+                        <configuration>
+                            <wsdds>
+                                <wsdd>
+                                    <directory>src/main/wsdd</directory>
+                                    <includes>
+                                        <include>**/*.wsdd</include>
+                                    </includes>
+                                </wsdd>
+                            </wsdds>
+                        </configuration>
                     </execution>
                     <execution>
                         <id>stop-server</id>

Modified: 
axis/axis1/java/trunk/samples/attachments-sample/src/test/java/test/functional/TestAttachmentsSample.java
URL: 
http://svn.apache.org/viewvc/axis/axis1/java/trunk/samples/attachments-sample/src/test/java/test/functional/TestAttachmentsSample.java?rev=1242566&r1=1242565&r2=1242566&view=diff
==============================================================================
--- 
axis/axis1/java/trunk/samples/attachments-sample/src/test/java/test/functional/TestAttachmentsSample.java
 (original)
+++ 
axis/axis1/java/trunk/samples/attachments-sample/src/test/java/test/functional/TestAttachmentsSample.java
 Thu Feb  9 22:27:18 2012
@@ -17,99 +17,48 @@
 package test.functional;
 
 import junit.framework.TestCase;
-import org.apache.axis.client.AdminClient;
-import org.apache.axis.components.logger.LogFactory;
 import org.apache.axis.utils.Options;
-import org.apache.commons.logging.Log;
 import samples.attachments.EchoAttachment;
 import samples.attachments.TestRef;
 
-
 /** Test the attachments sample code.
  */
 public class TestAttachmentsSample extends TestCase {
-    static Log log =
-            LogFactory.getLog(TestAttachmentsSample.class.getName());
-
-    public TestAttachmentsSample(String name) {
-        super(name);
-    }
-    
-    public void doTestDeploy () throws Exception {
-        AdminClient.main(new String[]{ System.getProperty("basedir") + 
"/src/main/wsdd/attachdeploy.wsdd" });
-        AdminClient.main(new String[]{ System.getProperty("basedir") + 
"/src/main/wsdd/testref.wsdd"});
-    }
-    
-    public void doTestAttachments1() throws Exception {
+    public void testAttachments1() throws Exception {
         Options opts = new Options( new String[]{});
         boolean res = new EchoAttachment(opts).echo(false, 
System.getProperty("basedir") + "/pom.xml");
        assertEquals("Didn't process attachment correctly", res, true) ;
     }
 
-    public void doTestAttachmentsD1() throws Exception {
+    public void testAttachmentsD1() throws Exception {
         Options opts = new Options( new String[]{});
         boolean res = new EchoAttachment(opts).echo(true, 
System.getProperty("basedir") + "/pom.xml");
        assertEquals("Didn't process attachment correctly", res, true) ;
     }
     
-    public void doTestAttachmentsDimeLeaveEmpty() throws Exception {
+    public void testAttachmentsDimeLeaveEmpty() throws Exception {
         Options opts = new Options( new String[]{});
         boolean res = new EchoAttachment(opts).echo(true, 
System.getProperty("basedir") + "/src/test/files/leaveempty.txt");
        assertEquals("Didn't process attachment correctly", res, true) ;
     }
 
-    public void doTestAttachments2() throws Exception {
+    public void testAttachments2() throws Exception {
         Options opts = new Options( new String[]{});
         boolean res = new EchoAttachment(opts).echoDir(false, 
System.getProperty("basedir") + "/src/main/java/samples/attachments");
         assertEquals("Didn't process attachments correctly", res, true);
     }
 
-    public void doTestAttachmentsD2() throws Exception {
+    public void testAttachmentsD2() throws Exception {
         Options opts = new Options( new String[]{});
         boolean res = new EchoAttachment(opts).echoDir(true, 
System.getProperty("basedir") + "/src/main/java/samples/attachments");
         assertEquals("Didn't process attachments correctly", res, true);
     }
 
-    public void doTestAttachmentsTestRef() throws Exception {
+    public void testAttachmentsTestRef() throws Exception {
         Options opts = new Options( new String[]{});
         boolean res = new TestRef(opts).testit();
         assertEquals("Didn't process attachments correctly", res, true);
     }
-    
-    public void doTestUndeploy () throws Exception {
-        AdminClient.main(new String[]{ System.getProperty("basedir") + 
"/src/main/wsdd/attachundeploy.wsdd" });
-        AdminClient.main(new String[]{ System.getProperty("basedir") + 
"/src/main/wsdd/testrefundeploy.wsdd" });
-    }
-
-    public static void main(String args[]) throws Exception {
-        TestAttachmentsSample tester = new TestAttachmentsSample("tester");
-        tester.testAttachmentsService();
-    }
-
-    public void testAttachmentsService () throws Exception {
-        try {
-            log.info("Testing deployment...");
-            doTestDeploy();
-            log.info("Testing single file attachment...");
-            doTestAttachments1();
-            log.info("Testing multiple file attachments...");
-            doTestAttachments2();
-            log.info("Testing single file DIME attachment...");
-            doTestAttachmentsD1();
-            log.info("Testing multiple file DIME attachments...");
-            doTestAttachmentsD2();
-            log.info("Testing attachment references...");
-            doTestAttachmentsTestRef();
-            log.info("Testing undeployment...");
-            doTestUndeploy();
-            log.info("Test complete.");
-        }
-        catch( Exception e ) {
-            e.printStackTrace();
-            throw new Exception("Fault returned from test: "+e);
-        }
-    }
-    
 }
 
 


Reply via email to