[jboss-svn-commits] JBL Code SVN: r8127 - in labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src: . org org/jboss org/jboss/soa org/jboss/soa/esb org/jboss/soa/esb/samples org/jboss/soa/esb/samples/loanbroker org/jboss/soa/esb/samples/loanbroker/banks

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 7 14:45:51 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-12-07 14:45:48 -0500 (Thu, 07 Dec 2006)
New Revision: 8127

Added:
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/FlatFileProcessorTest.java
   labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/JmsProcessorTest.java
Log:
adding unittests back in for the banks

Added: labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java	2006-12-07 19:07:44 UTC (rev 8126)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java	2006-12-07 19:45:48 UTC (rev 8127)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.soa.esb.samples.loanbroker.banks;
+
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+import com.thoughtworks.xstream.XStream;
+
+public class BankQuoteReplyTest {
+
+	private Logger logger = Logger.getLogger(this.getClass());
+	
+	/**
+	 * Testing the XML layout of a BankQuoteReply
+	 */
+	@Test public void obtainExampleXML(){
+		BankQuoteReply bankQuoteReply = new BankQuoteReply();
+		bankQuoteReply.setErrorCode(0);
+		bankQuoteReply.setCustomerUID("unique");
+		bankQuoteReply.setInterestRate(BigDecimal.valueOf(11.7));
+		bankQuoteReply.setQuoteId("JBBANK_1");
+		
+		XStream xstream = new XStream();
+		String bankQuoteReplyXml=xstream.toXML(bankQuoteReply);
+		logger.info("xml=\n" + bankQuoteReplyXml);
+		String expectedXml = 
+			  "<org.jboss.soa.esb.samples.loanbroker.banks.BankQuoteReply>\n"
+			+ "  <interestRate>11.7</interestRate>\n"
+            + "  <quoteId>JBBANK_1</quoteId>\n"
+            + "  <errorCode>0</errorCode>\n"
+            + "  <customerUID>unique</customerUID>\n"
+            + "</org.jboss.soa.esb.samples.loanbroker.banks.BankQuoteReply>";
+		assertTrue(expectedXml.equals(bankQuoteReplyXml));
+	}
+	
+	public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(BankQuoteReplyTest.class);
+    }
+}

Added: labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java	2006-12-07 19:07:44 UTC (rev 8126)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java	2006-12-07 19:45:48 UTC (rev 8127)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.soa.esb.samples.loanbroker.banks;
+
+import static org.junit.Assert.assertTrue;
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+import com.thoughtworks.xstream.XStream;
+
+public class BankQuoteRequestTest {
+
+	private Logger logger = Logger.getLogger(this.getClass());
+	
+	/**
+	 * Testing the XML layout of a BankQuoteRequest
+	 */
+	@Test public void obtainExampleXML(){
+		BankQuoteRequest bankQuoteRequest = new BankQuoteRequest();
+		bankQuoteRequest.setSsn(123456890);
+		bankQuoteRequest.setCreditScore(3);
+		bankQuoteRequest.setHistoryLength(4);
+		bankQuoteRequest.setLoanTerm(5);
+		bankQuoteRequest.setLoanAmount(20000);
+		bankQuoteRequest.setCustomerUID("unique");
+		
+		XStream xstream = new XStream();
+		String bankQuoteRequestXml=xstream.toXML(bankQuoteRequest);
+		logger.info("xml=\n" + bankQuoteRequestXml);
+		String expectedXml = 
+			  "<org.jboss.soa.esb.samples.loanbroker.banks.BankQuoteRequest>\n"
+			+ "  <ssn>123456890</ssn>\n"
+			+ "  <creditScore>3</creditScore>\n"
+			+ "  <historyLength>4</historyLength>\n"
+			+ "  <loanAmount>20000</loanAmount>\n"
+			+ "  <loanTerm>5</loanTerm>\n"
+		    + "  <customerUID>unique</customerUID>\n"
+			+ "</org.jboss.soa.esb.samples.loanbroker.banks.BankQuoteRequest>";
+		assertTrue(expectedXml.equals(bankQuoteRequestXml));
+	}
+	
+	public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(BankQuoteRequestTest.class);
+    }
+}

Added: labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java	2006-12-07 19:07:44 UTC (rev 8126)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java	2006-12-07 19:45:48 UTC (rev 8127)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.soa.esb.samples.loanbroker.banks;
+
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.junit.Test;
+
+public class BankTest {
+
+	private Logger logger = Logger.getLogger(this.getClass());
+	
+	/**
+	 * Tests the computation of the interestRate for the TestBank.
+	 *
+	 */
+	@Test public void processLoanRequest(){
+		
+		//Building a BankQuoteRequest
+		BankQuoteRequest bankQuoteRequest = new BankQuoteRequest();
+		bankQuoteRequest.setSsn(123456890);
+		bankQuoteRequest.setCreditScore(3);
+		bankQuoteRequest.setHistoryLength(4);
+		bankQuoteRequest.setLoanTerm(72);
+		bankQuoteRequest.setLoanAmount(20000);
+		bankQuoteRequest.setCustomerUID("unique");
+		logger.log(Priority.INFO, bankQuoteRequest);
+		
+		//Getting a Bank Instance
+		String bankName        = "TestBank";
+		BigDecimal ratePrimium = BigDecimal.valueOf(0.25);
+		int maxLoanTerm        = 120;
+		Bank bank = new Bank(bankName, ratePrimium, maxLoanTerm);
+		
+		//Getting a quote from this bank
+		BankQuoteReply bankQuoteReply = bank.processMessage(bankQuoteRequest);
+		logger.log(Priority.INFO, bankQuoteReply);
+		
+		//Checking for validity
+		BigDecimal expectedInterestRate = BigDecimal.valueOf(8.85);
+		assertTrue(bankQuoteReply.getInterestRate().equals(expectedInterestRate));
+	}
+	
+	public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(BankTest.class);
+    }
+}

Added: labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/FlatFileProcessorTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/FlatFileProcessorTest.java	2006-12-07 19:07:44 UTC (rev 8126)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/FlatFileProcessorTest.java	2006-12-07 19:45:48 UTC (rev 8127)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.soa.esb.samples.loanbroker.banks;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.junit.Test;
+
+public class FlatFileProcessorTest {
+
+	private Logger logger = Logger.getLogger(this.getClass());
+	private static String FLAT_FILE = "FlatFileProcessorTest.txt";
+	/**
+	 * Tests the processing of flat file containing a loan quote request. First
+	 * we try to find a temporary directory. When this succeeds we drop a
+	 * loan request file in there and try to process it.
+	 *
+	 */
+	@Test public void processRequest()
+	{
+		File writableDir=null;
+		logger.log(Priority.INFO, "Check to see if I can write to /tmp");
+		File tmpDir = new File("/tmp");
+		if (tmpDir.exists() && tmpDir.canWrite()) {
+			writableDir=tmpDir;
+		} else {
+			File tempDir = new File("C:/temp");
+			if (tempDir.exists() && tempDir.canWrite()) {
+				writableDir=tempDir;
+			} else {
+				logger.log(Priority.ERROR, "Could not find either /tmp or C:\\Temp for a temporary " 
+						+ "writing space.");
+			    assertTrue(false);
+			}
+		}
+//		We found a temp space so now we can drop in a load request file.
+		try {
+			logger.log(Priority.INFO, "Creating " + FLAT_FILE + " file in " + writableDir.getAbsolutePath());
+			File loanRequestFile = new File(writableDir.getAbsolutePath() + "/"+ FLAT_FILE);
+			if (loanRequestFile.exists()) {
+				loanRequestFile.delete();
+			}
+			loanRequestFile.createNewFile();
+			String str="23456890,3,4,20000,5,unique";
+			FileUtil.writeTextFile(loanRequestFile, str);
+			
+			logger.log(Priority.INFO, "Processing FlatFileProcessorTest.txt");
+			ManagerFlatFile pollManager = new ManagerFlatFile();
+			pollManager.processFile(loanRequestFile);
+			
+			//Check to see if the file is now moved.
+			assertFalse(loanRequestFile.exists());
+			
+			File processedFile = new File(writableDir.getAbsolutePath() + "/" 
+				+ ManagerFlatFile.PROCESSED_DIR + "/" + FLAT_FILE);
+			logger.log(Priority.INFO, "Check to see if " + processedFile.getAbsolutePath()
+					+ " exists");
+			assertTrue(processedFile.exists());
+			logger.log(Priority.INFO, "OK");
+			
+			File replyToFile = new File(writableDir.getAbsolutePath() + "/" 
+				+ ManagerFlatFile.OUTGOING_DIR + "/" + ManagerFlatFile.PREFIX
+				+ FLAT_FILE);
+			logger.log(Priority.INFO, "Check to see if " + replyToFile.getAbsolutePath()
+					+ " exists");
+			assertTrue(replyToFile.exists());
+			logger.log(Priority.INFO, "OK");
+			
+			//Checking the content of the reply
+			logger.log(Priority.INFO, "Check the reply, should be ('8.29,FileBasedBank-0,0,unique'");
+			assertTrue("8.29,FileBasedBank-0,0,unique".equals(FileUtil.readTextFile(replyToFile)));
+			logger.log(Priority.INFO, "OK");
+			//Cleaning up
+			processedFile.delete();
+			replyToFile.delete();
+			
+		} catch (Throwable e) {
+			logger.log(Priority.ERROR,e.getMessage(),e);
+			assertTrue(false);
+		}
+	}
+	
+	public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(FlatFileProcessorTest.class);
+    }
+}

Added: labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/JmsProcessorTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/JmsProcessorTest.java	2006-12-07 19:07:44 UTC (rev 8126)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/banks/test/src/org/jboss/soa/esb/samples/loanbroker/banks/JmsProcessorTest.java	2006-12-07 19:45:48 UTC (rev 8127)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.soa.esb.samples.loanbroker.banks;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.junit.Test;
+
+import com.thoughtworks.xstream.XStream;
+
+public class JmsProcessorTest {
+
+	private Logger logger = Logger.getLogger(this.getClass());
+
+	/**
+	 * This can be activate if the server is running and you want
+	 * to drop a message on the queue
+	 *
+	 */
+	@Test public void sendLoanRequestXML()
+	{
+
+		QueueSession sess;
+		Queue queue;
+		try {
+			Properties properties = new Properties();
+		    properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+		    properties.put(Context.URL_PKG_PREFIXES       , "org.jnp.interfaces");
+		    properties.put(Context.PROVIDER_URL           , "localhost");
+			InitialContext ctx = new InitialContext(properties);
+			queue = (Queue) ctx.lookup("queue/C");
+			QueueConnectionFactory factory = (QueueConnectionFactory) ctx
+					.lookup("ConnectionFactory");
+			QueueConnection cnn = factory.createQueueConnection();
+			sess = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+			String str="23456890,3,4,20000,5,unique,kurt.stam at jboss.com";
+			TextMessage msg = sess.createTextMessage(str);
+			QueueSender sender = sess.createSender(queue);
+			sender.send(msg);
+			//if the test gets here without errors it passes.
+			assertTrue(true);
+		} catch (Exception e) {
+			//if it fails it may be because the server is not up and the Queue is not found
+			//I'm not letting the test fail, since we may want to do nightly build/test runs
+			//which may not have the server up.
+			logger.log(Priority.ERROR, e.getMessage(), e);
+			logger.log(Priority.ERROR, "Is the server up and running?");
+		}
+	}
+
+	public static junit.framework.Test suite() {
+        return new JUnit4TestAdapter(JmsProcessorTest.class);
+    }
+}




More information about the jboss-svn-commits mailing list