[jbpm-commits] JBoss JBPM SVN: r3083 - in projects/gwt-console/trunk: server/src/main/resources and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 25 11:11:56 EST 2008


Author: heiko.braun at jboss.com
Date: 2008-11-25 11:11:56 -0500 (Tue, 25 Nov 2008)
New Revision: 3083

Added:
   projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TestFacade.java
   projects/gwt-console/trunk/server/src/main/resources/SampleProcess.par
Modified:
   projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ConsoleServerApplication.java
   projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java
   projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TaskMgmtFacade.java
   projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/URLBuilder.java
   projects/gwt-console/trunk/war/src/test/java/PreparationTest.java
   projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestProcessManagement.java
Log:
More work on test coverage: Added /test resources to console server to simplify GWT tests

Modified: projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ConsoleServerApplication.java
===================================================================
--- projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ConsoleServerApplication.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ConsoleServerApplication.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -40,6 +40,7 @@
       singletons.add(new TaskMgmtFacade());
       singletons.add(new UserMgmtFacade());
       singletons.add(new JBPM3MgmtFacade());
+      singletons.add(new TestFacade());
    }
 
    @Override

Modified: projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java
===================================================================
--- projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/ProcessMgmtFacade.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -52,7 +52,7 @@
    private ProcessManagement processManagement;
    private JBPM3Extension managementExtension;
 
-   private ProcessManagement getProcessDAO()
+   private ProcessManagement getProcessManagement()
    {
       if(null==this.processManagement)
       {
@@ -83,7 +83,7 @@
    public Response getDefinitionsJSON()
    {
       ProcessDefinitionRefWrapper wrapper =
-            new ProcessDefinitionRefWrapper(getProcessDAO().getAllDefinitions());
+            new ProcessDefinitionRefWrapper(getProcessManagement().getAllDefinitions());
       return createJsonResponse(wrapper);
    }
 
@@ -96,7 +96,7 @@
    )
    {
       ProcessDefinitionRefWrapper wrapper =
-            new ProcessDefinitionRefWrapper( getProcessDAO().removeDefinition(processId));
+            new ProcessDefinitionRefWrapper( getProcessManagement().removeDefinition(processId));
       return createJsonResponse(wrapper);
    }
 
@@ -110,7 +110,7 @@
    {
 
       ProcessInstanceRefWrapper wrapper =
-            new ProcessInstanceRefWrapper(getProcessDAO().getInstancesByDefinitionId(processId));
+            new ProcessInstanceRefWrapper(getProcessManagement().getInstancesByDefinitionId(processId));
       return createJsonResponse(wrapper);
    }
 
@@ -122,7 +122,7 @@
          long processId)
    {
 
-      ProcessInstanceRef instance = getProcessDAO().newInstance(processId);
+      ProcessInstanceRef instance = getProcessManagement().newInstance(processId);
       return createJsonResponse(instance);
    }
 

Modified: projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TaskMgmtFacade.java
===================================================================
--- projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TaskMgmtFacade.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TaskMgmtFacade.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -69,7 +69,7 @@
       return this.taskManagement;
    }
 
-   private JBPM3Extension getExtensionDAO()
+   private JBPM3Extension getManagementExtension()
    {
       if(null==this.JBPM3Extension)
       {
@@ -103,7 +103,7 @@
    )
    {
       Map<String,String> formMapping =
-            getExtensionDAO().getAvailableTaskForms(processId);
+            getManagementExtension().getAvailableTaskForms(processId);
 
       List<MapEntry> entries = new ArrayList<MapEntry>();
       for(String s : formMapping.keySet())
@@ -180,7 +180,7 @@
 
    )
    {
-      byte[] form = getExtensionDAO().getTaskFormByTaskName(processId, taskId);
+      byte[] form = getManagementExtension().getTaskFormByTaskName(processId, taskId);
       JBPM3FormParser parser = new JBPM3FormParser();
       final FormDef formDef = new FormDef("taskform-"+taskId);
       try

Added: projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TestFacade.java
===================================================================
--- projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TestFacade.java	                        (rev 0)
+++ projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/TestFacade.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.bpm.console.server;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.bpm.console.client.model.ProcessDefinitionRef;
+import org.jboss.bpm.console.server.integration.JBPM3Extension;
+import org.jboss.bpm.console.server.integration.ManagementFactory;
+import org.jboss.bpm.console.server.integration.ProcessManagement;
+
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * Test utility to simplify GWT tests.
+ * 
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+ at Path("test")
+public class TestFacade
+{
+   private static final Log log = LogFactory.getLog(TaskMgmtFacade.class);
+   
+   private JBPM3Extension JBPM3Extension;
+   private ProcessManagement processManagement;      
+
+   private JBPM3Extension getManagementExtension()
+   {
+      if(null==this.JBPM3Extension)
+      {
+         ManagementFactory factory = ManagementFactory.newInstance();
+         this.JBPM3Extension = factory.createExtensionManagement();
+      }
+
+      return this.JBPM3Extension;
+
+   }
+
+   private ProcessManagement getProcessManagement()
+   {
+      if(null==this.processManagement)
+      {
+         ManagementFactory factory = ManagementFactory.newInstance();
+         this.processManagement = factory.createProcessManagement();
+         log.debug("Using ManagementFactory impl:" + factory.getClass().getName());
+      }
+
+      return this.processManagement;
+   }
+
+   @POST
+   @Path("deploy/harness")   
+   public Response deployTestHarness()
+   {
+      try
+      {
+         InputStream in = getClass().getResourceAsStream("/WEB-INF/classes/SampleProcess.par");
+
+         ByteArrayOutputStream out = new ByteArrayOutputStream();
+         final int BUF_SIZE = 1 << 8;
+         byte[] buffer = new byte[BUF_SIZE];
+         int bytesRead = -1;
+         while((bytesRead = in.read(buffer)) > -1) {
+               out.write(buffer, 0, bytesRead);
+         }
+         in.close();
+         byte[] data = out.toByteArray();
+
+         ProcessDefinitionRef def = getManagementExtension().deployNewDefinition(data);
+         log.info("Deployed test process definition " + def);
+         
+         return Response.ok().build();
+      }
+      catch (IOException e)
+      {
+         throw new WebApplicationException(e, 500);
+      }     
+
+   }
+
+   @POST
+   @Path("undeploy/harness")
+   public Response undeployTestHarness()
+   {
+      List<ProcessDefinitionRef> defs = getProcessManagement().getAllDefinitions();
+      
+      for(ProcessDefinitionRef pd : defs)
+      {
+         if(pd.getName().equals("GWT_Test_Harness"))
+         {
+            log.info("Remove test harness " +pd);
+            getProcessManagement().removeDefinition(pd.getProcessId());
+         }
+      }
+      return Response.ok().build();
+   }
+}

Added: projects/gwt-console/trunk/server/src/main/resources/SampleProcess.par
===================================================================
(Binary files differ)


Property changes on: projects/gwt-console/trunk/server/src/main/resources/SampleProcess.par
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/war/src/main/java/jmaki/xhp/XmlHttpProxyServlet.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -470,6 +470,11 @@
    public Logger getLogger() {
       if (logger == null) {
          logger = Logger.getLogger("jmaki.services.xhp.Log");
+
+         // TODO: the logger breaks the GWT tests, because it writes to stderr
+         // we'll turn it off for now.
+         System.out.println("WARN: XHP proxy logging is turned off");
+         logger.setLevel(Level.OFF);
       }
       return logger;
    }

Modified: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/URLBuilder.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/URLBuilder.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/URLBuilder.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -161,4 +161,14 @@
    {
       return getBaseUrl() + "/rs/process/definitions/"+name;
    }
+
+   public String getDeployTestHarnessUrl()
+   {
+      return getBaseUrl()+ "/rs/test/deploy/harness";
+   }
+
+   public String getUndeployTestHarnessUrl()
+   {
+      return getBaseUrl()+ "/rs/test/undeploy/harness";
+   }
 }

Modified: projects/gwt-console/trunk/war/src/test/java/PreparationTest.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/PreparationTest.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/war/src/test/java/PreparationTest.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -22,41 +22,16 @@
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
-import org.jboss.bpm.console.client.URLBuilder;
 
-import java.io.File;
-import java.io.FileInputStream;
-
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
 public class PreparationTest extends TestCase
 {
 
-   private static String JSON = null;
-
    protected void setUp() throws Exception
    {
-      File workDir = new File(".");
 
-      System.out.println("===================" );
-      System.out.println("Test execution in " + workDir.getAbsolutePath() );
-      System.out.println("===================" );
-
-      // deploy a sample process
-      String pathname = workDir.getAbsolutePath() + "/src/test/resources/SampleProcess.par";
-      File samplePar = new File(pathname);
-      if(!samplePar.exists())
-         throw new RuntimeException("Failed to load sample process: " +pathname);
-      
-      URLBuilder urlBuilder = new URLBuilder("http://localhost:8080", "gwt-console-server");
-      String response = HTTP.post(
-            urlBuilder.getUploadDefinitionURL(),
-            new FileInputStream(samplePar)
-      );
-
-      System.out.println("HTTP response: " + response);
-
    }
 
    public void testSuccess()
@@ -64,8 +39,4 @@
       Assert.assertTrue(true);
    }
 
-   public static String getJSON()
-   {
-      return JSON;
-   }
 }

Modified: projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestProcessManagement.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestProcessManagement.java	2008-11-25 15:41:56 UTC (rev 3082)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestProcessManagement.java	2008-11-25 16:11:56 UTC (rev 3083)
@@ -25,7 +25,6 @@
 import com.google.gwt.http.client.RequestBuilder;
 import com.google.gwt.http.client.RequestCallback;
 import com.google.gwt.http.client.Response;
-import com.google.gwt.user.client.Timer;
 import com.gwtext.client.widgets.ComponentMgr;
 import org.jboss.bpm.console.client.model.ProcessDefinitionRef;
 import org.jboss.bpm.console.client.process.ProcessDefinitionList;
@@ -41,105 +40,77 @@
  */
 public class GwtTestProcessManagement extends AbstractConsoleTC
 {
-   public void testAuthentication()
+   public void testProcessManagement()
    {
-      System.out.println("=== testAuthentication ===");
+      System.out.println("=== testProcessInstanceEditor ===");
 
-      final MainView view = application.getConsoleView();
-      assertNotNull("View not initialized", view);
+      final ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)
+            ComponentMgr.getComponent(ProcessDefinitionListEditor.ID);
+      
+      Map<String, Object> context = new HashMap<String, Object>();
+      context.put("editor", editor);
 
-      HashMap<String, Object> context = new HashMap<String, Object>();
+      DeployTestHarnessTimer deployTimer = new DeployTestHarnessTimer(context);
+      AuthenticationTimer authTimer = new AuthenticationTimer(context,"admin", "admin");
+      LoadTestHarnessTimer loadingTimer = new LoadTestHarnessTimer(context);
+      InstanceEditorTimer instanceTimer = new InstanceEditorTimer(context);
+      UndeployTimer undeployTimer = new UndeployTimer(context);
 
-      Timer authTimer = new AuthenticationTimer(context,"admin", "admin");
-     
-      // launch first timer      
-      authTimer.schedule(500);
+      context.put("deployFollow", authTimer);
+      context.put("authFollow", loadingTimer);
+      context.put("loadFollow", instanceTimer);
+      context.put("instanceFollow", undeployTimer);
+      
+      // trigger first timer
+      deployTimer.schedule(500);
       delayTestFinish(1000);
+
    }
 
-   public void testProcessDefEditor()
+   class DeployTestHarnessTimer extends ChainedTimer
    {
-      System.out.println("=== testProcessDefEditor ===");
 
-      final MainView view = application.getConsoleView();
-      assertNotNull("View not initialized", view);
+      protected DeployTestHarnessTimer(Map<String, Object> context)
+      {
+         super(context);
+      }
 
-      Timer verification = new Timer(){
-
-         public void run()
+      public void run()
+      {
+         String url = urlBuilder.getDeployTestHarnessUrl();
+         RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url);
+         try
          {
-            System.out.println("Verify process definition list");
-            ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)
-                  ComponentMgr.getComponent(ProcessDefinitionListEditor.ID);
+            rb.sendRequest("",
+                  new RequestCallback()
+                  {
 
-            ProcessDefinitionList list = editor.getProcessDefinitionList();
-            assertTrue("No process definitions loaded",
-                  list.getAvailableProcessDefinitions().size() != 0
-            );
+                     public void onResponseReceived(Request request, Response response)
+                     {
+                        if(response.getStatusCode()!=200)
+                           throw new RuntimeException("HTTP status " + response.getStatusCode());
 
-            ProcessDefinitionRef testPd =
-                  getTestProcessDefinition(list.getAvailableProcessDefinitions());
-            assertNotNull("Unable to find test process definition", testPd);
+                        proceedOrFinish();
+                     }
 
-            finishTest();
+                     public void onError(Request request, Throwable t)
+                     {
+                        throw new RuntimeException("Connection problem", t);
+                     }
+                  }
+            ); 
          }
-      };
-
-      Timer loading = new Timer(){
-
-         public void run()
+         catch (Throwable e)
          {
-            System.out.println("Fetch process definitions");
-            ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)
-                  ComponentMgr.getComponent(ProcessDefinitionListEditor.ID);
-
-            ProcessDefinitionList list = editor.getProcessDefinitionList();
-            list.reloadStore();
+            throw new RuntimeException("Failed to remove process definition", e);
          }
-      };
+      }
 
-      Timer authentication = new Timer()
+      public ChainedTimer getNext()
       {
-         public void run()
-         {
-            System.out.println("Do authentication");
-            String inRoleURL = view.getUrlBuilder().getUserInRoleURL(MainView.KNOWN_ROLES);
-            final Authentication auth = new Authentication(inRoleURL);
-            auth.doLogin();
-
-         }
-      };
-
-      authentication.schedule(500);
-      loading.schedule(1000);
-      verification.schedule(1500);
-
-      delayTestFinish(2000);
+         return (ChainedTimer)context.get("deployFollow");
+      }
    }
-
-   public void testProcessInstanceEditor()
-   {
-      System.out.println("=== testProcessInstanceEditor ===");
-
-      final ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)
-            ComponentMgr.getComponent(ProcessDefinitionListEditor.ID);
-
-      Map<String, Object> context = new HashMap<String, Object>();
-      context.put("editor", editor);
-
-      AuthenticationTimer authTimer = new AuthenticationTimer(context,"admin", "admin");
-      LoadTestHarnessTimer loadingTimer = new LoadTestHarnessTimer(context);
-      InstanceEditorTimer instanceTimer = new InstanceEditorTimer(context);
-
-      context.put("authFollow", loadingTimer);
-      context.put("loadFollow", instanceTimer);
-
-      // trigger first timer
-      authTimer.schedule(500);
-      delayTestFinish(1000);
-
-   }
-
    class LoadTestHarnessTimer extends ChainedTimer
    {
 
@@ -157,15 +128,7 @@
       {
          ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor) context.get("editor");
          ProcessDefinitionList list = editor.getProcessDefinitionList();
-         list.reloadStore();
-
-         List<ProcessDefinitionRef> defs = list.getAvailableProcessDefinitions();
-         assertFalse(defs.isEmpty());
-
-         ProcessDefinitionRef testPd = getTestProcessDefinition(defs);
-         assertNotNull("No test PD found", testPd);
-         context.put("def", testPd);
-
+         list.reloadStore(); // trigger async load operation         
          proceedOrFinish();
       }
    }
@@ -186,14 +149,16 @@
       public void run()
       {
          ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)context.get("editor");
-         ProcessDefinitionRef def = (ProcessDefinitionRef)context.get("def");
-         assertNotNull("No test definition given: " +context, def);
-         
          ProcessDefinitionList list = editor.getProcessDefinitionList();
-         list.launchEditor(def);  // will create an instance editor
 
+         List<ProcessDefinitionRef> processDefinitions = list.getAvailableProcessDefinitions();
+         ProcessDefinitionRef testPd = getTestProcessDefinition(processDefinitions);
+         assertNotNull("No test definition given: " +processDefinitions, testPd);
+
+         list.launchEditor(testPd);  // will create an instance editor
+
          // lookup instance editor
-         String editorId = ProcessInstanceListEditor.createWidgetID(def);
+         String editorId = ProcessInstanceListEditor.createWidgetID(testPd);
          ProcessInstanceListEditor instanceEditor = (ProcessInstanceListEditor)
                ComponentMgr.getComponent(editorId);
          assertNotNull("Failed to create instance editor for process", instanceEditor);
@@ -203,11 +168,8 @@
 
          List<ProcessDefinitionRef> defs = list.getAvailableProcessDefinitions();
          assertFalse(defs.isEmpty());
-         
-         ProcessDefinitionRef testPd = getTestProcessDefinition(list.getAvailableProcessDefinitions());
-         CleanupTimer cleanup = new CleanupTimer(context, testPd);
-         cleanup.schedule(500);
-         delayTestFinish(1000);
+
+         proceedOrFinish();
       }
    }
 
@@ -225,31 +187,26 @@
       return def;
    }
 
-   class CleanupTimer extends ChainedTimer
+   class UndeployTimer extends ChainedTimer
    {
-      ProcessDefinitionRef pd;
-
-      public CleanupTimer(Map<String, Object> context, ProcessDefinitionRef pd)
+      public UndeployTimer(Map<String, Object> context)
       {
-         super(context);
-         this.pd = pd;
+         super(context);         
       }
 
-
       public ChainedTimer getNext()
       {
-         return null;  
+         return (ChainedTimer)context.get("undeployFollow");  
       }
 
       public void run()
       {
-         String deleteUrl = urlBuilder.getRemoveDefinitionURL(pd.getProcessId());
+         String deleteUrl = urlBuilder.getUndeployTestHarnessUrl();
          RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, deleteUrl);
          try
          {
-            System.out.println("FIXME: Schedule " + pd + " for removal");
-            
-            /*rb.sendRequest("",
+
+            rb.sendRequest("",
                   new RequestCallback()
                   {
 
@@ -264,7 +221,7 @@
                         throw new RuntimeException("Connection problem", t);
                      }
                   }
-            );*/
+            ); 
          }
          catch (Throwable e)
          {




More information about the jbpm-commits mailing list