servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r773479 - in /servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file: FilePollerEndpointTest.java FileSenderEndpointTest.java
Date Mon, 11 May 2009 06:48:29 GMT
Author: gertv
Date: Mon May 11 06:48:29 2009
New Revision: 773479

URL: http://svn.apache.org/viewvc?rev=773479&view=rev
Log:
SMXCOMP-525: Improve test coverage for servicemix-file

Added:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FileSenderEndpointTest.java
  (with props)
Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java?rev=773479&r1=773478&r2=773479&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
Mon May 11 06:48:29 2009
@@ -24,7 +24,7 @@
 import junit.framework.TestCase;
 
 public class FilePollerEndpointTest extends TestCase {
-    
+
     private static final File DATA = new File("target/test/data");
     private static final File ARCHIVE = new File("target/test/archive");
     private FilePollerEndpoint endpoint;
@@ -34,13 +34,13 @@
         endpoint = new FilePollerEndpoint();
         endpoint.setTargetService(new QName("urn:test", "service"));
     }
-    
+
     public void testValidateNoFile() throws Exception {
         try {
             endpoint.validate();
             fail("validate() should throw an exception when file has not been set");
         } catch (DeploymentException e) {
-            //test succeeds
+            // test succeeds
         }
     }
 
@@ -53,14 +53,14 @@
             endpoint.validate();
             fail("validate() should throw an exception when archive doesn't refer to a directory");
         } catch (DeploymentException e) {
-            //test succeeds
+            // test succeeds
         } finally {
             if (archive != null) {
                 archive.delete();
             }
         }
     }
-    
+
     public void testValidateArchiveWithoutDelete() throws Exception {
         endpoint.setFile(DATA);
         endpoint.setArchive(ARCHIVE);
@@ -69,7 +69,7 @@
             endpoint.validate();
             fail("validate() should throw an exception when archive was set without delete");
         } catch (DeploymentException e) {
-            //test succeeds
+            // test succeeds
         }
     }
 }

Added: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FileSenderEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FileSenderEndpointTest.java?rev=773479&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FileSenderEndpointTest.java
(added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FileSenderEndpointTest.java
Mon May 11 06:48:29 2009
@@ -0,0 +1,135 @@
+/*
+ * 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.file;
+
+import java.io.File;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.framework.ComponentNameSpace;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
+import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.servicemix.tck.mock.MockExchangeFactory;
+
+public class FileSenderEndpointTest extends TestCase {
+
+    public static final String FILE_NAME_PROPERTY = "org.apache.servicemix.file.name";
+    public static final String FILE_PATH_PROPERTY = "org.apache.servicemix.file.path";
+    private static final File OUT_DIR = new File("target/file-test");
+    private FileSenderEndpoint endpoint;
+    private FileComponent component;
+    private ComponentNameSpace cns;
+    private InternalEndpoint ie;
+
+    public FileSenderEndpointTest(final String name) {
+        super(name);
+    }
+
+    protected final void setUp() throws Exception {
+        super.setUp();
+        component = new FileComponent();
+        cns = new ComponentNameSpace("myContainer", "myName");
+        ie = new InternalEndpoint(cns, "myEndpoint", new QName("myService"));
+        endpoint = new FileSenderEndpoint(component, ie);
+    }
+
+    protected final void tearDown() throws Exception {
+        super.tearDown();
+
+        component = null;
+        cns = null;
+        ie = null;
+        endpoint = null;
+    }
+
+    // Test when no directory has been set on the endpoint.
+    public final void testValidateNoDirectory() throws Exception {
+        try {
+            endpoint.validate();
+            fail("validate() should fail when no directory is specified.");
+        } catch (DeploymentException de) {
+            // test succeeds
+        }
+    }
+
+    // Test when directory specified is not a directory.
+    public final void testValidateIsNotDirectory() throws Exception {
+        File tempFile = null;
+        try {
+            tempFile = File.createTempFile("servicemix", "test");
+            endpoint.setDirectory(tempFile);
+            endpoint.validate();
+            fail("validate() should fail when setDirectory is set to a file.");
+        } catch (DeploymentException de) {
+            // test succeeds
+        } finally {
+            if (tempFile != null) {
+                tempFile.delete();
+            }
+        }
+    }
+
+    // Test when the output file does not exist.
+    public final void testProcessInOnlyNewFile() throws Exception {
+        MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOnlyExchange();
+        me.setOperation(new QName("uri", "op"));
+        me.setProperty("myProp", "myValue");
+        NormalizedMessage msg = me.createMessage();
+        msg.setProperty("myMsgProp", "myMsgValue");
+        msg.setContent(new StringSource("<input>input message</input>"));
+        endpoint.setDirectory(OUT_DIR);
+        endpoint.setAutoCreateDirectory(true);
+        endpoint.validate();
+
+        endpoint.processInOnly(me, msg);
+
+        // Check to see if a file was written to the directory.
+        File[] fileList = endpoint.getDirectory().listFiles();
+        assertTrue("Directory should not be empty", fileList != null);
+
+        // cleanup
+        FileUtil.deleteFile(endpoint.getDirectory());
+    }
+
+    // Test when calling processInOut - not supported.
+    public final void testProcessInOutNotSupported() throws Exception {
+        MockExchangeFactory mef = new MockExchangeFactory();
+        MessageExchange me = mef.createInOutExchange();
+        me.setOperation(new QName("uri", "op"));
+        me.setProperty("myProp", "myValue");
+        NormalizedMessage inMsg = me.createMessage();
+        inMsg.setProperty("myMsgProp", "myMsgValue");
+        inMsg.setContent(new StringSource("<input>input message</input>"));
+        NormalizedMessage outMsg = me.createMessage();
+        outMsg.setContent(new StringSource("<output>output message</output>"));
+        endpoint.setDirectory(new File("target/test"));
+
+        try {
+            endpoint.processInOut(me, inMsg, outMsg);
+            fail("processInOut is an unsupported operation");
+        } catch (UnsupportedOperationException uoe) {
+            // test succeeds
+        }
+    }
+}

Propchange: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-file/src/test/java/org/apache/servicemix/file/FileSenderEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message