[jbpm-commits] JBoss JBPM SVN: r3032 - in projects/gwt-console/trunk: war/src/main/java/org/jboss/bpm/console/client/model and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 21 09:25:17 EST 2008


Author: heiko.braun at jboss.com
Date: 2008-11-21 09:25:17 -0500 (Fri, 21 Nov 2008)
New Revision: 3032

Added:
   projects/gwt-console/trunk/war/src/test/java/PreparationTest.java
   projects/gwt-console/trunk/war/src/test/resources/SampleProcess.par
Removed:
   projects/gwt-console/trunk/war/src/test/java/BlankTest.java
   projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/DeferredExecution.java
   projects/gwt-console/trunk/war/src/test/resources/org/
Modified:
   projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/JBPM3MgmtFacade.java
   projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/model/DTOParser.java
   projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java
Log:
Implement process deployment from within test case

Modified: projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/JBPM3MgmtFacade.java
===================================================================
--- projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/JBPM3MgmtFacade.java	2008-11-21 13:27:50 UTC (rev 3031)
+++ projects/gwt-console/trunk/server/src/main/java/org/jboss/bpm/console/server/JBPM3MgmtFacade.java	2008-11-21 14:25:17 UTC (rev 3032)
@@ -29,9 +29,11 @@
 import org.apache.commons.logging.LogFactory;
 import org.jboss.bpm.console.client.model.jbpm3.ActiveNodeInfo;
 import org.jboss.bpm.console.client.model.jbpm3.DiagramInfo;
+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 org.jboss.bpm.console.server.gson.GsonFactory;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.*;
@@ -40,6 +42,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import com.google.gson.Gson;
+
 /**
  * REST server module for accessing proprietary jbpm data.
  * 
@@ -87,6 +91,8 @@
          HttpServletRequest request
    )
    {
+      ProcessDefinitionRef processRef = null;
+
       try
       {
          FileItemFactory factory = new DiskFileItemFactory();
@@ -114,7 +120,7 @@
                // Process a file upload in memory
                byte[] data = item.get();
 
-               getManagementExtension().deployNewDefinition(data);
+               processRef = getManagementExtension().deployNewDefinition(data);
 
                // Process stream
                //InputStream uploadedStream = item.getInputStream();
@@ -129,7 +135,7 @@
          throw new WebApplicationException(e);
       }
 
-      return Response.ok().build();
+      return createJsonResponse(processRef);
 
    }
 
@@ -199,4 +205,11 @@
       return Response.ok().type("application/json").build();
    }
 
+   private Response createJsonResponse(Object wrapper)
+   {
+      Gson gson = GsonFactory.createInstance();
+      String json = gson.toJson(wrapper);
+      return Response.ok(json).type("application/json").build();
+   }
+
 }

Modified: projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/model/DTOParser.java
===================================================================
--- projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/model/DTOParser.java	2008-11-21 13:27:50 UTC (rev 3031)
+++ projects/gwt-console/trunk/war/src/main/java/org/jboss/bpm/console/client/model/DTOParser.java	2008-11-21 14:25:17 UTC (rev 3032)
@@ -39,6 +39,15 @@
  */
 public class DTOParser
 {
+   public static ProcessDefinitionRef parseProcessDefinition(String json)
+   {
+      JSONValue root = JSONParser.parse(json);
+      long id = JSONWalk.on(root).next("processId").asLong();
+      String version = JSONWalk.on(root).next("version").asString();
+      String name = JSONWalk.on(root).next("name").asString();
+
+      return new ProcessDefinitionRef(id, name, version);
+   }
    public static List<String> parseRolesAssigned(String json)
    {
       // parse roles

Deleted: projects/gwt-console/trunk/war/src/test/java/BlankTest.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/BlankTest.java	2008-11-21 13:27:50 UTC (rev 3031)
+++ projects/gwt-console/trunk/war/src/test/java/BlankTest.java	2008-11-21 14:25:17 UTC (rev 3032)
@@ -1,35 +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.
- */
-
-import junit.framework.TestCase;
-import junit.framework.Assert;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class BlankTest extends TestCase
-{
-   public void testSuccess()
-   {
-      Assert.assertTrue(true);
-   }
-}

Copied: projects/gwt-console/trunk/war/src/test/java/PreparationTest.java (from rev 3021, projects/gwt-console/trunk/war/src/test/java/BlankTest.java)
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/PreparationTest.java	                        (rev 0)
+++ projects/gwt-console/trunk/war/src/test/java/PreparationTest.java	2008-11-21 14:25:17 UTC (rev 3032)
@@ -0,0 +1,210 @@
+/*
+ * 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 junit.framework.Assert;
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.bpm.console.client.URLBuilder;
+import org.jboss.bpm.console.client.GwtTestApplication;
+
+/**
+ * @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 = doHttpPost(
+            urlBuilder.getUploadDefinitionURL(),
+            samplePar
+      );
+
+      System.out.println("HTTP response: " + response);
+
+   }
+
+   public void testSuccess()
+   {
+      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;
+   }
+}


Property changes on: projects/gwt-console/trunk/war/src/test/java/PreparationTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Deleted: projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/DeferredExecution.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/DeferredExecution.java	2008-11-21 13:27:50 UTC (rev 3031)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/DeferredExecution.java	2008-11-21 14:25:17 UTC (rev 3032)
@@ -1,26 +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;
-
-public interface DeferredExecution {
-    void execute(); 
-}

Modified: projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java
===================================================================
--- projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java	2008-11-21 13:27:50 UTC (rev 3031)
+++ projects/gwt-console/trunk/war/src/test/java/org/jboss/bpm/console/client/GwtTestApplication.java	2008-11-21 14:25:17 UTC (rev 3032)
@@ -25,16 +25,12 @@
 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.process.ProcessDefinitionList;
-import org.jboss.bpm.console.client.process.ProcessDefinitionListEditor;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
  */
 public class GwtTestApplication extends GWTTestCase
 {
-
    private static Application application = null;
 
    public String getModuleName()
@@ -46,6 +42,7 @@
    protected void gwtSetUp() throws Exception
    {
       super.gwtSetUp();
+
       if(null==application)
       {
          application = new Application();

Copied: projects/gwt-console/trunk/war/src/test/resources/SampleProcess.par (from rev 3021, projects/gwt-console/trunk/war/src/test/resources/org/jboss/bpm/console/client/SampleProcess.par)
===================================================================
(Binary files differ)


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




More information about the jbpm-commits mailing list