[jboss-svn-commits] JBL Code SVN: r14421 - labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 21 09:57:55 EDT 2007


Author: ldimaggi at redhat.com
Date: 2007-08-21 09:57:55 -0400 (Tue, 21 Aug 2007)
New Revision: 14421

Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldFileActionTest.java
   labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java
Log:
HelloWorldFileActionTest.java - Updated to include test validation as defined in Helpers.java

Helpers.java - added routines to support HelloWorldFileActionTest.java - put these in the Helper class in case they are useful to other (as yet unwritten) tests



Modified: labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldFileActionTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldFileActionTest.java	2007-08-21 13:27:51 UTC (rev 14420)
+++ labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldFileActionTest.java	2007-08-21 13:57:55 UTC (rev 14421)
@@ -1,10 +1,14 @@
 package org.jboss.soa.esb.quickstart.test;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Hashtable;
+
 import junit.framework.Test;
 
 import org.jboss.test.JBossTestCase;
 
-
 /**
  * Sample client for the jboss container.
  *
@@ -12,8 +16,17 @@
  */
 
 public class HelloWorldFileActionTest
-        extends JBossTestCase
-{
+        extends JBossTestCase {
+        
+     	private static final String FILE_NAME = "HelloWorldFileActionTest.log";
+    	private static final String LOG_FILE = Helpers.getTempDir(FILE_NAME) + FILE_NAME;
+    	private static final int EXPECTED_RECORD_COUNT = 1;
+    	private static final String INPUT_DIRECTORY = "../helloworld_file_action/build/dirs/input/";
+        private static final String INPUT_FILE_NAME = "MyInput.dat";
+    	private static final String OUTPUT_DIRECTORY = "../helloworld_file_action/build/dirs/output/";
+        private static final String OUTPUT_FILE_NAME = OUTPUT_DIRECTORY + "MyInput.dat.sentToEsb";
+       	private static final String FILE_CONTENTS = "Hello World In A File";       
+
 	public HelloWorldFileActionTest(String name)
 	{
 		super(name);
@@ -21,16 +34,62 @@
 
 	public void testMessage() throws Exception
 	{
-		sendMessage();
-		Thread.sleep(10000); // wait for message to post.
-	}
+		createFileAction();
+		
+		/* Verify that the output file is created */
+		boolean fileExists = Helpers.checkForFile(OUTPUT_FILE_NAME);
+		if (!fileExists) {
+			fail("File " + OUTPUT_FILE_NAME
+					+ " not created - test marked as failing");
+		}
+		
+		/* Verify that the message file is created */
+		fileExists = Helpers.checkForFile(LOG_FILE);
+		if (!fileExists) {
+			fail("Event file " + LOG_FILE
+					+ " not created - test marked as failing");
+		}
+		
+		/* Check the log file */
+		Hashtable theTable = Helpers.getFileActionMessageString(LOG_FILE);
+		String theMessage = (String) theTable.get("Message1");
+		assertEquals("The strings in the log file should match", theMessage + "\n", FILE_CONTENTS  + Helpers.START_TAG + FILE_NAME + Helpers.END_TAG);
+		File target = new File(LOG_FILE);
+		target.delete();
+		
+		/* Verify that the output file is complete */
+		boolean fileComplete = Helpers.checkFileContent(OUTPUT_FILE_NAME,
+				EXPECTED_RECORD_COUNT);
+		if (!fileComplete) {
+			Hashtable temp = Helpers.getMessageString(OUTPUT_FILE_NAME);
+			fail("File Action Output file " + OUTPUT_FILE_NAME + " not complete - expected "
+					+ EXPECTED_RECORD_COUNT + " records - found " + temp.size()
+					+ ", test marked as failing");
+		}
+		
+		theTable = Helpers.getMessageString(OUTPUT_FILE_NAME);
+		theMessage = (String) theTable.get("Message1");
+		assertEquals("The strings in output file should match", theMessage, FILE_CONTENTS);
+		
+	} /* method */
 
-	public void sendMessage() throws Exception
+	public void createFileAction() throws Exception
 	{
-	}
+		String tempStr = FILE_CONTENTS + Helpers.START_TAG + FILE_NAME + Helpers.END_TAG;	
+    	File x = new File(INPUT_DIRECTORY + "/" + INPUT_FILE_NAME);
+    	try {
+    		BufferedWriter out = new BufferedWriter(new FileWriter(x));
+    		out.write(tempStr.toCharArray());
+    		out.close();
+    	} catch (Exception e) {
+    		System.out.println("Error while writing the file: " + INPUT_DIRECTORY + "/" + INPUT_FILE_NAME);
+    		System.out.println(e.getMessage());
+    	}	
+	} /* method */
 
    public static Test suite() throws Exception
    {
       return getDeploySetup(HelloWorldFileActionTest.class, "Quickstart_helloworld_file_action.esb");
-   }
-}
+   } /* method */
+   
+} /*/class */

Modified: labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java	2007-08-21 13:27:51 UTC (rev 14420)
+++ labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java	2007-08-21 13:57:55 UTC (rev 14421)
@@ -38,7 +38,7 @@
 	public static final String START_TAG = "[jbesb-filename]";
 	public static final String END_TAG = "[/jbesb-filename]\n";
 	public static final int FILE_TIMER = 3000;
-	public static final int FILE_COUNTER = 3;
+	public static final int FILE_COUNTER = 5;
 
 	/* Read the message files into a hash */
 	public static Hashtable getMessageString(String fileName) {
@@ -59,6 +59,23 @@
 		return returnTable;
 	} /* method */
 
+	/* Read the message files into a hash- used by HelloWorldFileActionTest */
+	public static Hashtable getFileActionMessageString(String fileName) {
+		Hashtable<String,String> returnTable = new Hashtable<String,String>();
+		int theCounter = 1;
+		try {
+			BufferedReader in = new BufferedReader(new FileReader(fileName));
+			String str;
+			while ((str = in.readLine()) != null) {
+				returnTable.put("Message" + theCounter++, str);
+			}
+			in.close();
+		} catch (IOException e) {
+			Assert.fail("Cannot read file: " + fileName);
+		}
+		return returnTable;
+	} /* method */
+	
 	/* Determine if the event file has been written */
 	public static boolean checkForFile(String fileName) throws Exception {
 		boolean wasFileFound = false;




More information about the jboss-svn-commits mailing list