You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2009/04/21 18:01:54 UTC
svn commit: r767198 - in
/servicemix/components/engines/servicemix-exec/trunk/src:
main/java/org/apache/servicemix/exec/
main/java/org/apache/servicemix/exec/utils/ test/ test/java/ test/java/org/
test/java/org/apache/ test/java/org/apache/servicemix/ ...
Author: jbonofre
Date: Tue Apr 21 16:01:53 2009
New Revision: 767198
URL: http://svn.apache.org/viewvc?rev=767198&view=rev
Log:
Add a first unit test on the Exec component.
Correct ExecMarshaler by adding space between args.
Added:
servicemix/components/engines/servicemix-exec/trunk/src/test/
servicemix/components/engines/servicemix-exec/trunk/src/test/java/
servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/
servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/
servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/
servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/
servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/ExecXBeanDeployerTest.java (with props)
servicemix/components/engines/servicemix-exec/trunk/src/test/resources/
servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/
servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/xbean.xml (with props)
Modified:
servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/ExecEndpoint.java
servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecMarshaler.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=767198&r1=767197&r2=767198&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 Tue Apr 21 16:01:53 2009
@@ -26,7 +26,6 @@
import org.apache.servicemix.common.endpoints.ProviderEndpoint;
import org.apache.servicemix.exec.utils.ExecMarshaler;
import org.apache.servicemix.exec.utils.ExecUtils;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
/**
@@ -39,8 +38,14 @@
private String command; // the command can be static (define in the descriptor) or provided in the incoming message
- private SourceTransformer transformer = new SourceTransformer();
-
+ public String getCommand() {
+ return command;
+ }
+
+ public void setCommand(String command) {
+ this.command = command;
+ }
+
@Override
public void process(MessageExchange exchange) throws Exception {
// The component acts as a provider, this means that another component has requested our service
Modified: servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecMarshaler.java?rev=767198&r1=767197&r2=767198&view=diff
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecMarshaler.java (original)
+++ servicemix/components/engines/servicemix-exec/trunk/src/main/java/org/apache/servicemix/exec/utils/ExecMarshaler.java Tue Apr 21 16:01:53 2009
@@ -59,7 +59,7 @@
NodeList argumentNodes = document.getElementsByTagName(TAG_ARGUMENT);
for (int i = 0; i < argumentNodes.getLength(); i++) {
- execString = execString + argumentNodes.item(i).getChildNodes().item(0).getNodeValue();
+ execString = execString + " " + argumentNodes.item(i).getChildNodes().item(0).getNodeValue();
}
} catch (Exception e) {
Added: servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/ExecXBeanDeployerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/ExecXBeanDeployerTest.java?rev=767198&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/ExecXBeanDeployerTest.java (added)
+++ servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/ExecXBeanDeployerTest.java Tue Apr 21 16:01:53 2009
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.exec;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * Test the Exec XBean descriptor.
+ *
+ * @author jbonofre
+ */
+public class ExecXBeanDeployerTest extends TestCase {
+
+ private static final String MSG_VALID = "<message>"
+ + "<command>ls</command>"
+ + "<arguments>"
+ + " <argument>-l</argument>"
+ + "</arguments>"
+ + "</message>";
+
+ private static final transient Log LOG = LogFactory.getLog(ExecXBeanDeployerTest.class);
+
+ protected JBIContainer container;
+
+ /*
+ * (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ container = new JBIContainer();
+ container.setUseMBeanServer(false);
+ container.setCreateMBeanServer(false);
+ container.setEmbedded(true);
+ container.init();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ if (container != null) {
+ container.shutDown();
+ }
+ }
+
+ /**
+ * <p>
+ * Exec component test that deploys a SU into the JBI container.
+ * </p>
+ *
+ * @throws Exception if an error occurs during the test.
+ */
+ public void test() throws Exception {
+ // creates exec component
+ ExecComponent component = new ExecComponent();
+ container.activateComponent(component, "ExecComponent");
+
+ // starts the JBI container
+ container.start();
+
+ // deploy SU
+ URL url = getClass().getClassLoader().getResource("xbean/xbean.xml");
+ File path = new File(new URI(url.toString()));
+ path = path.getParentFile();
+ component.getServiceUnitManager().deploy("xbean", path.getAbsolutePath());
+ component.getServiceUnitManager().init("xbean", path.getAbsolutePath());
+ component.getServiceUnitManager().start("xbean");
+
+ // test if the endpoint is present
+ assertNotNull("The endpoint http://test/service/exec is not found in the JBI container.", container.getRegistry().getEndpoint(new QName("http://test", "service"), "exec"));
+ // test if the endpoint descriptor contains something
+ // TODO add WSDLs support in the Exec component
+ // assertNotNull("The endpoint http://test/service/exec descriptor is null",
+ // container.getRegistry().getEndpointDescriptor(container.getRegistry().getEndpoint(new
+ // QName("http://test", "service"), "exec")));
+
+ // main test
+ DefaultServiceMixClient client = new DefaultServiceMixClient(container);
+ InOnly me = client.createInOnlyExchange();
+ me.setService(new QName("http://test", "service"));
+ me.getInMessage().setContent(new StringSource(MSG_VALID));
+ client.sendSync(me);
+
+ if (me.getStatus() == ExchangeStatus.ERROR) {
+ fail("Received ERROR status.");
+ } else if (me.getFault() != null) {
+ fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+ }
+ }
+
+}
Propchange: servicemix/components/engines/servicemix-exec/trunk/src/test/java/org/apache/servicemix/exec/ExecXBeanDeployerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/xbean.xml?rev=767198&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/xbean.xml (added)
+++ servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/xbean.xml Tue Apr 21 16:01:53 2009
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<beans xmlns:exec="http://servicemix.apache.org/exec/1.0"
+ xmlns:test="http://test">
+
+ <exec:endpoint service="test:service"
+ endpoint="exec"
+ command="date"/>
+
+</beans>
\ No newline at end of file
Propchange: servicemix/components/engines/servicemix-exec/trunk/src/test/resources/xbean/xbean.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain