[jbpm-commits] JBoss JBPM SVN: r3080 - in projects/gwt-console/trunk/war/src: test/java and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 25 09:35:27 EST 2008


Author: heiko.braun at jboss.com
Date: 2008-11-25 09:35:27 -0500 (Tue, 25 Nov 2008)
New Revision: 3080

Added:
   projects/gwt-console/trunk/war/src/test/java/HTTP.java
   projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/AbstractConsoleTC.java
Removed:
   projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/ChainedTimer.java
Modified:
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessDefinitionList.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:
Further enhancement to the GWT test coverage. Added a bunch of FIXME's

Modified: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessDefinitionList.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessDefinitionList.java	2008-11-25 11:54:02 UTC (rev 3079)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/process/ProcessDefinitionList.java	2008-11-25 14:35:27 UTC (rev 3080)
@@ -85,10 +85,10 @@
    public void onExamine(int row)
    {
       ProcessDefinitionRef proc = row2ProcessMap.get(row);
-      lauchEditor(proc);
+      launchEditor(proc);
    }
 
-   public void lauchEditor(ProcessDefinitionRef proc)
+   public void launchEditor(ProcessDefinitionRef proc)
    {
       String editorId = ProcessInstanceListEditor.createWidgetID(proc);
 

Added: projects/gwt-console/trunk/war/src/test/java/HTTP.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/HTTP.java	                        (rev 0)
+++ projects/gwt-console/trunk/war/src/test/java/HTTP.java	2008-11-25 14:35:27 UTC (rev 3080)
@@ -0,0 +1,166 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.UUID;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class HTTP
+{
+   public static String post(String urlString, InputStream inputStream)
+         throws Exception
+   {
+
+      String userPassword = "admin:admin";
+      String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
+
+      HttpURLConnection conn = null;
+      BufferedReader br = null;
+      DataOutputStream dos = null;
+      DataInputStream inStream = null;
+
+      InputStream is = null;
+      OutputStream os = null;
+      boolean ret = false;
+      String StrMessage = "";
+
+
+      String lineEnd = "\r\n";
+      String twoHyphens = "--";
+      String boundary =  "*****";
+
+
+      int bytesRead, bytesAvailable, bufferSize;
+
+      byte[] buffer;
+
+      int maxBufferSize = 1*1024*1024;
+
+      String responseFromServer = "";
+
+      try
+      {
+         //------------------ CLIENT REQUEST
+
+         // open a URL connection to the Servlet
+
+         URL url = new URL(urlString);
+
+
+         // Open a HTTP connection to the URL
+
+         conn = (HttpURLConnection) url.openConnection();
+         conn.setRequestProperty ("Authorization", "Basic " + encoding);
+
+         // Allow Inputs
+         conn.setDoInput(true);
+
+         // Allow Outputs
+         conn.setDoOutput(true);
+
+         // Don't use a cached copy.
+         conn.setUseCaches(false);
+
+         // Use a post method.
+         conn.setRequestMethod("POST");
+
+         conn.setRequestProperty("Connection", "Keep-Alive");
+
+         conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
+
+         dos = new DataOutputStream( conn.getOutputStream() );
+
+         dos.writeBytes(twoHyphens + boundary + lineEnd);
+         dos.writeBytes("Content-Disposition: form-data; name=\"upload\";"
+               + " filename=\"" + UUID.randomUUID().toString() +"\"" + lineEnd);
+         dos.writeBytes(lineEnd);
+
+         // create a buffer of maximum size
+         bytesAvailable = inputStream.available();
+         bufferSize = Math.min(bytesAvailable, maxBufferSize);
+         buffer = new byte[bufferSize];
+
+         // read file and write it into form...
+         bytesRead = inputStream.read(buffer, 0, bufferSize);
+
+         while (bytesRead > 0)
+         {
+            dos.write(buffer, 0, bufferSize);
+            bytesAvailable = inputStream.available();
+            bufferSize = Math.min(bytesAvailable, maxBufferSize);
+            bytesRead = inputStream.read(buffer, 0, bufferSize);
+         }
+
+         // send multipart form data necesssary after file data...
+
+         dos.writeBytes(lineEnd);
+         dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
+
+         // close streams
+
+         inputStream.close();
+         dos.flush();
+         dos.close();
+
+      }
+      catch (MalformedURLException ex)
+      {
+         throw ex;
+      }
+
+      catch (IOException ioe)
+      {
+         throw ioe;
+      }
+
+
+      //------------------ read the SERVER RESPONSE
+
+      StringBuffer sb = new StringBuffer();
+
+      try
+      {
+         inStream = new DataInputStream ( conn.getInputStream() );
+         String str;
+         while (( str = inStream.readLine()) != null)
+         {
+            sb.append(str).append("");
+         }
+         inStream.close();
+
+      }
+      catch (IOException ioex)
+      {
+         System.out.println("From (ServerResponse): "+ioex);
+
+      }
+
+
+      return sb.toString();
+
+   }
+}

Modified: projects/gwt-console/trunk/war/src/test/java/PreparationTest.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/PreparationTest.java	2008-11-25 11:54:02 UTC (rev 3079)
+++ projects/gwt-console/trunk/war/src/test/java/PreparationTest.java	2008-11-25 14:35:27 UTC (rev 3080)
@@ -24,10 +24,8 @@
 import junit.framework.TestCase;
 import org.jboss.bpm.console.client.URLBuilder;
 
-import java.io.*;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.io.File;
+import java.io.FileInputStream;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
@@ -52,9 +50,9 @@
          throw new RuntimeException("Failed to load sample process: " +pathname);
       
       URLBuilder urlBuilder = new URLBuilder("http://localhost:8080", "gwt-console-server");
-      String response = doHttpPost(
+      String response = HTTP.post(
             urlBuilder.getUploadDefinitionURL(),
-            samplePar
+            new FileInputStream(samplePar)
       );
 
       System.out.println("HTTP response: " + response);
@@ -66,141 +64,6 @@
       Assert.assertTrue(true);
    }
 
-   private String doHttpPost(String urlString, File data)
-         throws Exception
-   {
-
-      String userPassword = "admin:admin";
-      String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
-
-      HttpURLConnection conn = null;
-      BufferedReader br = null;
-      DataOutputStream dos = null;
-      DataInputStream inStream = null;
-
-      InputStream is = null;
-      OutputStream os = null;
-      boolean ret = false;
-      String StrMessage = "";
-
-
-      String lineEnd = "\r\n";
-      String twoHyphens = "--";
-      String boundary =  "*****";
-
-
-      int bytesRead, bytesAvailable, bufferSize;
-
-      byte[] buffer;
-
-      int maxBufferSize = 1*1024*1024;
-
-      String responseFromServer = "";
-
-      try
-      {
-         //------------------ CLIENT REQUEST
-
-         FileInputStream fileInputStream = new FileInputStream( data );
-
-         // open a URL connection to the Servlet
-
-         URL url = new URL(urlString);
-
-
-         // Open a HTTP connection to the URL
-
-         conn = (HttpURLConnection) url.openConnection();
-         conn.setRequestProperty ("Authorization", "Basic " + encoding);
-
-         // Allow Inputs
-         conn.setDoInput(true);
-
-         // Allow Outputs
-         conn.setDoOutput(true);
-
-         // Don't use a cached copy.
-         conn.setUseCaches(false);
-
-         // Use a post method.
-         conn.setRequestMethod("POST");
-
-         conn.setRequestProperty("Connection", "Keep-Alive");
-
-         conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
-
-         dos = new DataOutputStream( conn.getOutputStream() );
-
-         dos.writeBytes(twoHyphens + boundary + lineEnd);
-         dos.writeBytes("Content-Disposition: form-data; name=\"upload\";"
-               + " filename=\"" + data.getName() +"\"" + lineEnd);
-         dos.writeBytes(lineEnd);
-
-         // create a buffer of maximum size
-         bytesAvailable = fileInputStream.available();
-         bufferSize = Math.min(bytesAvailable, maxBufferSize);
-         buffer = new byte[bufferSize];
-
-         // read file and write it into form...
-         bytesRead = fileInputStream.read(buffer, 0, bufferSize);
-
-         while (bytesRead > 0)
-         {
-            dos.write(buffer, 0, bufferSize);
-            bytesAvailable = fileInputStream.available();
-            bufferSize = Math.min(bytesAvailable, maxBufferSize);
-            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
-         }
-
-         // send multipart form data necesssary after file data...
-
-         dos.writeBytes(lineEnd);
-         dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
-
-         // close streams
-
-         fileInputStream.close();
-         dos.flush();
-         dos.close();
-
-      }
-      catch (MalformedURLException ex)
-      {
-         throw ex;
-      }
-
-      catch (IOException ioe)
-      {
-         throw ioe;
-      }
-
-
-      //------------------ read the SERVER RESPONSE
-
-      StringBuffer sb = new StringBuffer();
-
-      try
-      {
-         inStream = new DataInputStream ( conn.getInputStream() );
-         String str;
-         while (( str = inStream.readLine()) != null)
-         {
-            sb.append(str).append("");
-         }
-         inStream.close();
-
-      }
-      catch (IOException ioex)
-      {
-         System.out.println("From (ServerResponse): "+ioex);
-
-      }
-
-
-      return sb.toString();
-
-   }
-
    public static String getJSON()
    {
       return JSON;

Added: projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/AbstractConsoleTC.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/AbstractConsoleTC.java	                        (rev 0)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/AbstractConsoleTC.java	2008-11-25 14:35:27 UTC (rev 3080)
@@ -0,0 +1,87 @@
+/*
+ * 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.client;
+
+import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.Timer;
+import com.google.gwt.core.client.GWT;
+
+import java.util.Map;
+
+/**
+ * Base class for console tests
+ * 
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class AbstractConsoleTC extends GWTTestCase
+{
+
+   protected static Application application = null;
+   protected static final String GWT_TEST_HARNESS = "GWT_Test_Harness";
+   protected URLBuilder urlBuilder;
+
+   public String getModuleName()
+   {
+      return "org.jboss.bpm.console.Application";
+   }
+
+   protected void gwtSetUp() throws Exception
+   {
+      super.gwtSetUp();
+
+      if(null==application)
+      {
+         application = new Application();
+         application.onModuleLoad2();
+      }
+
+      urlBuilder = new URLBuilder(GWT.getModuleBaseURL(), "xhp");
+   }
+
+   protected abstract class ChainedTimer extends Timer
+   {
+      protected Map<String,Object> context;
+
+      protected ChainedTimer(Map<String, Object> context)
+      {
+         this.context = context;
+      }
+
+      protected void proceedOrFinish()
+      {
+
+         ChainedTimer next = getNext();
+         if(next !=null)
+         {
+            next.schedule(500);
+            delayTestFinish(1000);
+         }
+         else
+         {
+            finishTest();
+         }
+      }
+
+      public abstract ChainedTimer getNext();
+
+   }
+}

Deleted: projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/ChainedTimer.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/ChainedTimer.java	2008-11-25 11:54:02 UTC (rev 3079)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/ChainedTimer.java	2008-11-25 14:35:27 UTC (rev 3080)
@@ -1,48 +0,0 @@
-/*
- * 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.client;
-
-import com.google.gwt.user.client.Timer;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-abstract class ChainedTimer extends Timer
-{
-
-   private Timer next;
-
-
-   protected ChainedTimer(Timer next)
-   {
-      this.next = next;
-   }
-
-   public abstract void run();
-
-   protected void scheduleNext(int after)
-   {
-      if(null==next)
-         throw new IllegalArgumentException("No next timer given");
-      next.schedule(after);
-   }
-}

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 11:54:02 UTC (rev 3079)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestProcessManagement.java	2008-11-25 14:35:27 UTC (rev 3080)
@@ -22,15 +22,15 @@
 package org.jboss.bpm.console.client;
 
 import com.google.gwt.http.client.Request;
+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.junit.client.GWTTestCase;
 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;
 import org.jboss.bpm.console.client.process.ProcessDefinitionListEditor;
 import org.jboss.bpm.console.client.process.ProcessInstanceListEditor;
-import org.jboss.bpm.console.client.util.ConsoleLog;
 
 import java.util.HashMap;
 import java.util.List;
@@ -39,70 +39,28 @@
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
-public class GwtTestProcessManagement extends GWTTestCase
+public class GwtTestProcessManagement extends AbstractConsoleTC
 {
-   private static Application application = null;
-  
-   public String getModuleName()
+   public void testAuthentication()
    {
-      return "org.jboss.bpm.console.Application";
-   }
+      System.out.println("=== testAuthentication ===");
 
-   protected void gwtSetUp() throws Exception
-   {
-      super.gwtSetUp();
-
-      if(null==application)
-      {
-         System.out.println("=========");
-         System.out.println("Setup console application");
-         System.out.println("=========");
-
-         application = new Application();
-         application.onModuleLoad2();
-
-      }
-
-   }
-
-   public void testAuthentication()
-   {
       final MainView view = application.getConsoleView();
       assertNotNull("View not initialized", view);
 
-      Timer timer = new Timer()
-      {
-         public void run()
-         {
+      HashMap<String, Object> context = new HashMap<String, Object>();
 
-            String inRoleURL = view.getUrlBuilder().getUserInRoleURL(MainView.KNOWN_ROLES);
-            final Authentication auth = new Authentication(inRoleURL);
-            auth.setCallback(
-                  new Authentication.AuthCallback() {
-
-                     public void onLoginSuccess(Request request, Response response) {
-                        System.out.println("Assigned roles: " + auth.getRolesAssigned() );
-                     }
-
-                     public void onLoginFailed(Request request, Throwable t) {
-
-                        throw new RuntimeException("Login failed", t);
-                     }
-                  }
-            );
-            auth.doLogin();
-            finishTest();
-         }
-
-
-      };
-
-      timer.schedule(300);
-      delayTestFinish(500);
+      Timer authTimer = new AuthenticationTimer(context,"admin", "admin");
+     
+      // launch first timer      
+      authTimer.schedule(500);
+      delayTestFinish(1000);
    }
 
    public void testProcessDefEditor()
    {
+      System.out.println("=== testProcessDefEditor ===");
+
       final MainView view = application.getConsoleView();
       assertNotNull("View not initialized", view);
 
@@ -119,6 +77,10 @@
                   list.getAvailableProcessDefinitions().size() != 0
             );
 
+            ProcessDefinitionRef testPd =
+                  getTestProcessDefinition(list.getAvailableProcessDefinitions());
+            assertNotNull("Unable to find test process definition", testPd);
+
             finishTest();
          }
       };
@@ -157,32 +119,40 @@
 
    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);
-      
-      LoadTestHarnessTimer loading = new LoadTestHarnessTimer(context);
-      InstanceEditorTimer instances = new InstanceEditorTimer(context);
-      context.put("secondTimer", instances);
-      
-      loading.schedule(500);
+
+      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 Timer
+   class LoadTestHarnessTimer extends ChainedTimer
    {
 
-      Map<String, Object> context;
-      
       public LoadTestHarnessTimer(Map<String, Object> context)
       {
-         super();
-         this.context = context;
+         super(context);
       }
 
+      public ChainedTimer getNext()
+      {
+         return (ChainedTimer)context.get("loadFollow");
+      }
+
       public void run()
       {
          ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor) context.get("editor");
@@ -192,37 +162,35 @@
          List<ProcessDefinitionRef> defs = list.getAvailableProcessDefinitions();
          assertFalse(defs.isEmpty());
 
-         for(ProcessDefinitionRef pd : defs)
-         {
-            if(pd.getName().equals("GWT_Test_Harness"))
-            {
-               context.put("def", pd);
-               break;
-            }
-         }
+         ProcessDefinitionRef testPd = getTestProcessDefinition(defs);
+         assertNotNull("No test PD found", testPd);
+         context.put("def", testPd);
 
-         Timer next = (Timer)context.get("secondTimer");
-         next.schedule(500);
-         delayTestFinish(1000);
+         proceedOrFinish();
       }
    }
 
-   class InstanceEditorTimer extends Timer
+   class InstanceEditorTimer extends ChainedTimer
    {
-      Map<String, Object> context;
-
       public InstanceEditorTimer(Map<String, Object> context)
       {
-         super();
-         this.context = context;
+         super(context);      
       }
 
+
+      public ChainedTimer getNext()
+      {
+         return (ChainedTimer)context.get("instanceFollow");
+      }
+
       public void run()
-      {         
+      {
          ProcessDefinitionListEditor editor = (ProcessDefinitionListEditor)context.get("editor");
-         ProcessDefinitionRef def = (ProcessDefinitionRef)context.get("def");    
+         ProcessDefinitionRef def = (ProcessDefinitionRef)context.get("def");
+         assertNotNull("No test definition given: " +context, def);
+         
          ProcessDefinitionList list = editor.getProcessDefinitionList();
-         list.lauchEditor(def);  // will create an instance editor
+         list.launchEditor(def);  // will create an instance editor
 
          // lookup instance editor
          String editorId = ProcessInstanceListEditor.createWidgetID(def);
@@ -230,11 +198,124 @@
                ComponentMgr.getComponent(editorId);
          assertNotNull("Failed to create instance editor for process", instanceEditor);
 
-        // todo: start new instance
+         // todo: start new instance
+         System.out.println("FIXME: Implement instance creation test");
 
-         // finish
-         finishTest();
+         List<ProcessDefinitionRef> defs = list.getAvailableProcessDefinitions();
+         assertFalse(defs.isEmpty());
+         
+         ProcessDefinitionRef testPd = getTestProcessDefinition(list.getAvailableProcessDefinitions());
+         CleanupTimer cleanup = new CleanupTimer(context, testPd);
+         cleanup.schedule(500);
+         delayTestFinish(1000);
+      }
+   }
 
+   private ProcessDefinitionRef getTestProcessDefinition(List<ProcessDefinitionRef> list)
+   {
+      ProcessDefinitionRef def =null;
+      for(ProcessDefinitionRef pd : list)
+      {
+         if(pd.getName().equals(GWT_TEST_HARNESS))
+         {
+            def=pd;
+            break;
+         }
       }
+      return def;
    }
+
+   class CleanupTimer extends ChainedTimer
+   {
+      ProcessDefinitionRef pd;
+
+      public CleanupTimer(Map<String, Object> context, ProcessDefinitionRef pd)
+      {
+         super(context);
+         this.pd = pd;
+      }
+
+
+      public ChainedTimer getNext()
+      {
+         return null;  
+      }
+
+      public void run()
+      {
+         String deleteUrl = urlBuilder.getRemoveDefinitionURL(pd.getProcessId());
+         RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, deleteUrl);
+         try
+         {
+            System.out.println("FIXME: Schedule " + pd + " for removal");
+            
+            /*rb.sendRequest("",
+                  new RequestCallback()
+                  {
+
+                     public void onResponseReceived(Request request, Response response)
+                     {
+                        if(response.getStatusCode()!=200)
+                           throw new RuntimeException("HTTP status " + response.getStatusCode());
+                     }
+
+                     public void onError(Request request, Throwable t)
+                     {
+                        throw new RuntimeException("Connection problem", t);
+                     }
+                  }
+            );*/
+         }
+         catch (Throwable e)
+         {
+            throw new RuntimeException("Failed to remove process definition", e);
+         }
+
+         proceedOrFinish();
+      }
+   }
+
+   class AuthenticationTimer extends ChainedTimer
+   {
+      String user;
+      String pass;
+
+      public AuthenticationTimer(Map<String,Object> context, String user, String pass)
+      {
+         super(context);
+         
+         this.user = user;
+         this.pass = pass;
+      }
+
+
+      public ChainedTimer getNext()
+      {
+         return (ChainedTimer)context.get("authFollow");  
+      }
+
+      public void run()
+      {
+
+         String inRoleURL = urlBuilder.getUserInRoleURL(MainView.KNOWN_ROLES);
+         final Authentication auth = new Authentication(inRoleURL);
+         auth.setCallback(
+               new Authentication.AuthCallback() {
+
+                  public void onLoginSuccess(Request request, Response response) {
+                     System.out.println("Assigned roles: " + auth.getRolesAssigned() );                     
+
+                     // only proceed when authentication was successfull
+                     proceedOrFinish();
+                  }
+
+                  public void onLoginFailed(Request request, Throwable t) {
+
+                     throw new RuntimeException("Login failed", t);
+                  }
+               }
+         );
+         auth.doLogin(user,pass);
+      }
+   }
 }




More information about the jbpm-commits mailing list