servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r806441 - in /servicemix/components/engines/servicemix-exec/trunk/src: main/java/org/apache/servicemix/exec/ExecEndpoint.java test/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshalerTest.java
Date Fri, 21 Aug 2009 07:54:48 GMT
Author: jbonofre
Date: Fri Aug 21 07:54:48 2009
New Revision: 806441

URL: http://svn.apache.org/viewvc?rev=806441&view=rev
Log:
Cleanup WSDL loading into the Exec endpoint.
Upgrade the exec marshaler unit test.

Modified:
    servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
    servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshalerTest.java

Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java?rev=806441&r1=806440&r2=806441&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
(original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
Fri Aug 21 07:54:48 2009
@@ -22,6 +22,7 @@
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
 
 import org.apache.servicemix.common.endpoints.ProviderEndpoint;
 import org.apache.servicemix.exec.marshaler.DefaultExecMarshaler;
@@ -107,20 +108,30 @@
 	@Override
 	public void validate() throws DeploymentException {
 	    try {
-	        if (wsdl != null) {
-	            // the user provides a WSDL
-	            description = DomUtil.parse(wsdl.getInputStream());
-	            definition = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader().readWSDL(null,
description);
-	        } else {
-	            // load the default abstract WSDL
-	            description = DomUtil.parse(new ClassPathResource(DEFAULT_WSDL).getInputStream());
-	            definition = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader().readWSDL(null,
description);
+	        if (wsdl == null) {
+	            // the user hasn't provide a WSDL, load the default abstract one
+	            wsdl = new ClassPathResource(DEFAULT_WSDL);
 	        }
+	        
+	        // load the WSDL
+	        description = DomUtil.parse(wsdl.getInputStream());
+	        definition = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader().readWSDL(null,
description);
+	        
+	        // cleanup WSDL to be sure thats it's an abstract one
+	        // cleanup services
+	        QName[] qnames = (QName[]) definition.getServices().keySet().toArray(new QName[0]);
+	        for (int i = 0; i < qnames.length; i++) {
+	            definition.removeService(qnames[i]);
+	        }
+	        // cleanup binding
+	        qnames = (QName[]) definition.getBindings().keySet().toArray(new QName[0]);
+	        for (int i = 0; i < qnames.length; i++) {
+	            definition.removeBinding(qnames[i]);
+	        }
+	        
 	    } catch (Exception e) {
 	        throw new DeploymentException("Can't load the WSDL.", e);
 	    }
-	    
-	    // TODO define the WSDL for the marshaler
 	}
 
 	/*

Modified: servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshalerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshalerTest.java?rev=806441&r1=806440&r2=806441&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshalerTest.java
(original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/marshaler/DefaultExecMarshalerTest.java
Fri Aug 21 07:54:48 2009
@@ -31,24 +31,14 @@
 import org.apache.servicemix.jbi.messaging.MessageExchangeFactoryImpl;
 
 /**
+ * <p>
  * Unit tests on the default exec marshaler.
+ * </p>
  * 
  * @author jbonofre
  */
 public class DefaultExecMarshalerTest extends TestCase {
     
-    private static final String COMMAND = "ls";
-    private static final String FIRST_ARG = "-lt";
-    private static final String SECOND_ARG = "/tmp";
-    
-    private static final String MSG_VALID = "<message>"
-        + "<command>" + COMMAND + "</command>"
-        + "<arguments>"
-        + "<argument>" + FIRST_ARG + "</argument>"
-        + "<argument>" + SECOND_ARG + "</argument>"
-        + "</arguments>"
-        + "</message>";
-    
     private ExecMarshalerSupport marshaler;
     private MessageExchangeFactory factory;
     
@@ -61,17 +51,65 @@
         this.factory = new MessageExchangeFactoryImpl(new IdGenerator(), new AtomicBoolean(false));
     }
     
-    public void testValidMessage() throws Exception {
+    /**
+     * <p>
+     * Test the unmarshalling of a valid message content.
+     * </p>
+     * 
+     * @throws Exception if the unmarshalling fails.
+     */
+    public void testUnmarshalling() throws Exception {
         MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
         NormalizedMessage message = exchange.createMessage();
-        message.setContent(new StringSource(MSG_VALID));
+        message.setContent(new StringSource(
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                "<exec:execRequest xmlns:exec=\"http://servicemix.apache.org/exec\">"
+
+                "<command>ls</command>" +
+                "<arguments>" +
+                "<argument>-lt</argument>" +
+                "<argument>/tmp</argument>" +
+                "</arguments>" +
+                "</exec:execRequest>"));
+                
         exchange.setMessage(message, "in");
-        SourceTransformer transformer = new SourceTransformer();
-        //String execCommand = marshaler.constructExecCommand(transformer.toDOMDocument(message));
         
-        //assertEquals("ls -lt /tmp", execCommand);
+        ExecRequest execRequest = marshaler.unmarshal(message);
+        
+        assertEquals("ls", execRequest.getCommand());
+        assertEquals("-lt", execRequest.getArguments().get(0));
+        assertEquals("/tmp", execRequest.getArguments().get(1));
     }
     
+    /**
+     * <p>
+     * Test the marshalling of a ExecResponse.
+     * </p>
+     * 
+     * @throws Exception if the marshalling fails.
+     */
+    public void testMarshalling() throws Exception {
+        // construct an ExecResponse
+        ExecResponse execResponse = new ExecResponse();
+        execResponse.setExitCode(0);
+        execResponse.setStartTime(1000000);
+        execResponse.setEndTime(1000000);
+        execResponse.setExecutionDuration(1000000);
+        execResponse.setErrorData(new StringBuffer("TEST"));
+        execResponse.setOutputData(new StringBuffer("TEST"));
+        
+        // create an exchange/normalized message
+        MessageExchange exchange = this.factory.createExchange(MessageExchangePattern.IN_ONLY);
+        NormalizedMessage message = exchange.createMessage();
+        
+        // marshal the exec response
+        marshaler.marshal(execResponse, message);
+        
+        // get the message content
+        SourceTransformer transformer = new SourceTransformer();
+        String content = transformer.contentToString(message);
+        
+        assertEquals(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns2:execResponse
xmlns:ns2=\"http://servicemix.apache.org/exec\"><endTime>1000000</endTime><errorData/><executionDuration>1000000</executionDuration><exitCode>0</exitCode><outputData/><startTime>1000000</startTime></ns2:execResponse>");
+    }
     
 
 }



Mime
View raw message