[jboss-svn-commits] JBL Code SVN: r5307 - in labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo: . banks banks/lib banks/src banks/src/org banks/src/org/jboss banks/src/org/jboss/soa banks/src/org/jboss/soa/esb banks/src/org/jboss/soa/esb/samples banks/src/org/jboss/soa/esb/samples/loanbroker banks/src/org/jboss/soa/esb/samples/loanbroker/banks banks/test banks/test/org banks/test/org/jboss banks/test/org/jboss/soa banks/test/org/jboss/soa/esb banks/test/org/jboss/soa/esb/samples banks/test/org/jboss/soa/esb/samples/loanbroker banks/test/org/jboss/soa/esb/samples/loanbroker/banks

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 27 09:31:20 EDT 2006


Author: kurt.stam at jboss.com
Date: 2006-07-27 09:31:10 -0400 (Thu, 27 Jul 2006)
New Revision: 5307

Added:
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/junit-4.1.jar
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/xstream-1.1.3.jar
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/Bank.java
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReply.java
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequest.java
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java
   labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java
Log:
adding bank code for the loan broker example

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/junit-4.1.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/junit-4.1.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/xstream-1.1.3.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/lib/xstream-1.1.3.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/Bank.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/Bank.java	2006-07-27 13:30:22 UTC (rev 5306)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/Bank.java	2006-07-27 13:31:10 UTC (rev 5307)
@@ -0,0 +1,116 @@
+/*
+* 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 java.math.BigDecimal;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+/**
+ * This Bank is pretty well focussed on doing one thing, which is giving out loans. On the 
+ * reception of a BankQuoteRequest it will compute the interest rate it will return
+ * in the BankQuoteReply.
+ * 
+ * Each bank instance can be customized using the parameters bankName, RatePremium and MaxLoanTerm.
+ * 
+ * @author kstam
+ *
+ */
+public class Bank 
+{
+	private Logger logger = Logger.getLogger(this.getClass());
+	
+	private static final BigDecimal PRIME_RATE            = BigDecimal.valueOf(8.0);
+	private static final BigDecimal DEFAULT_RATE_PREMIUM  = BigDecimal.valueOf(0.5);
+	private static final int        DEFAULT_MAX_LOAN_TERM = 30;
+	private static final String     DEFAULT_BANK_NAME     = "DefaultBank";
+	private static int _quoteCounter                      = 0;
+	
+	//Default values for bank
+	private String bankName                               = DEFAULT_BANK_NAME;
+	private BigDecimal ratePremium                        = DEFAULT_RATE_PREMIUM;
+	private int maxLoanTerm                               = DEFAULT_MAX_LOAN_TERM;
+
+	/** 
+	 * The Bank's constructor.
+	 * 
+	 * @param bankName    - the name of the bank
+	 * @param ratePremium - the premium it charges for the loan
+	 * @param maxLoanTerm - the maximum loan term
+	 */
+	public Bank(String bankName, BigDecimal ratePremium, int maxLoanTerm) {
+		super();
+		if (bankName!=null) {
+			this.bankName=bankName;
+		}
+		if (ratePremium!=null) {
+			this.ratePremium=ratePremium;
+		}
+		if (maxLoanTerm > 0) {
+			this.maxLoanTerm=maxLoanTerm;
+		}
+	}
+	/**
+	 * The bank computes the interest rate based on configuration parameters of the bank and
+	 * the information in the {@link BankQuoteRequest.
+	 * @param bankQuoteRequest - the bank quote request containing requests parameters
+	 * @return bankQuoteReply  - the bank quote replay contaning the interest rate
+	 */
+	private BankQuoteReply computeBankQuoteReply(BankQuoteRequest bankQuoteRequest)
+	{
+		BankQuoteReply bankQuoteReply = new BankQuoteReply();
+		if (bankQuoteRequest.loanTerm <= maxLoanTerm) {
+			BigDecimal interestRate=BigDecimal.valueOf((bankQuoteRequest.loanTerm/12.0)/10.0);
+			interestRate=PRIME_RATE.add(ratePremium).add(interestRate);
+			bankQuoteReply.interestRate=interestRate.setScale(2, BigDecimal.ROUND_HALF_UP);
+			bankQuoteReply.errorCode=0;
+		} else {
+			bankQuoteReply.interestRate=BigDecimal.valueOf(0.00).setScale(2, BigDecimal.ROUND_HALF_UP);
+			bankQuoteReply.errorCode=1;
+		}
+		String quoteId=bankName + "-" + _quoteCounter++;
+		bankQuoteReply.quoteId=quoteId;
+		return bankQuoteReply;
+	}
+	/**
+	 * Processes the Loan Quote request and returns the banks reply.
+	 * 
+	 * @param bankQuoteRequest - the bank quote request
+	 * @return bankQuoteReply  - the bank quote reply
+	 */
+	protected BankQuoteReply processMessage(BankQuoteRequest bankQuoteRequest)
+	{
+		logger.log(Priority.INFO, "Bank '" + bankName + "' received a request for SSN=" 
+				+ bankQuoteRequest.getSsn()
+				+ " for $" + bankQuoteRequest.loanAmount 
+				+ " over " + bankQuoteRequest.loanTerm + " months.");
+		logger.log(Priority.DEBUG, bankQuoteRequest);
+		
+		BankQuoteReply bankQuoteReply = computeBankQuoteReply(bankQuoteRequest);
+		logger.log(Priority.INFO, "Bank '" + bankName + " offers SSN=" 
+				+ bankQuoteRequest.getSsn() + " " + bankQuoteReply);
+		
+		return bankQuoteReply;
+	}
+}

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReply.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReply.java	2006-07-27 13:30:22 UTC (rev 5306)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReply.java	2006-07-27 13:31:10 UTC (rev 5307)
@@ -0,0 +1,105 @@
+/*
+* 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 java.io.Serializable;
+import java.math.BigDecimal;
+
+
+public class BankQuoteReply implements Serializable 
+{
+	private static final long serialVersionUID = 1L;
+	
+	public BigDecimal interestRate;
+	public String quoteId;
+	public int errorCode;
+	/**
+	 * Gets the SerialVersionUID.
+	 * @return serialVersionUID
+	 */
+	public static long getSerialVersionUID() {
+		return serialVersionUID;
+	}
+	/**
+	 * Gets the errorCode.
+	 * 	<li>0 - success
+	 *  <li>1 - loan term exceeds the maximum available loan term
+	 *  <li>2 - invalid SSN
+	 *  <li>3 - invalid credit score
+	 *  <li>4 - invalid credit history length
+	 *  <li>5 - invalid loan term
+	 * @return errorCode
+	 */
+	public int getErrorCode() {
+		return errorCode;
+	}
+	/**
+	 * Sets the errorCode.
+	 *  <li>0 - success
+	 *  <li>1 - loan term exceeds the maximum available loan term
+	 *  <li>2 - invalid SSN
+	 *  <li>3 - invalid credit score
+	 *  <li>4 - invalid credit history length
+	 *  <li>5 - invalid loan term
+	 * @param errorCode
+	 */
+	public void setErrorCode(int errorCode) {
+		this.errorCode = errorCode;
+	}
+	/**
+	 * Gets the quoted interest rate.
+	 * @return interestRate
+	 */
+	public BigDecimal getInterestRate() {
+		return interestRate;
+	}
+	/**
+	 * Sets the quoted interest rate.
+	 * @param interestRate
+	 */
+	public void setInterestRate(BigDecimal interestRate) {
+		this.interestRate = interestRate;
+	}
+	/**
+	 * Gets the Quote ID.
+	 * @return quoteId
+	 */
+	public String getQuoteId() {
+		return quoteId;
+	}
+	/**
+	 * Sets the quoteId.
+	 * @param quoteId
+	 */
+	public void setQuoteId(String quoteId) {
+		this.quoteId = quoteId;
+	}
+	/**
+	 * Returns a human readable string representation of this object.
+	 * @return toString
+	 */
+	public String toString() {
+		return this.getClass().getSimpleName() + "=["
+			+ "interestRate=" + interestRate
+			+ ", quoteId=" + quoteId
+			+ ", errorCode=" + errorCode + "]";
+	}
+}

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequest.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequest.java	2006-07-27 13:30:22 UTC (rev 5306)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequest.java	2006-07-27 13:31:10 UTC (rev 5307)
@@ -0,0 +1,117 @@
+/*
+* 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 java.io.Serializable;
+
+
+public class BankQuoteRequest implements Serializable 
+{
+	private static final long serialVersionUID = 1L;
+	public int ssn;
+	public int creditScore;
+	public int historyLength;
+	public int loanAmount;
+	public int loanTerm;
+	/**
+	 * Gets for the credit score.
+	 * @return credit score
+	 */
+	public int getCreditScore() {
+		return creditScore;
+	}
+	/**
+	 * Sets the credit score.
+	 * @param creditScore
+	 */
+	public void setCreditScore(int creditScore) {
+		this.creditScore = creditScore;
+	}
+	/**
+	 * Gets the credit history length (in years).
+	 * @return credit history length
+	 */
+	public int getHistoryLength() {
+		return historyLength;
+	}
+	/**
+	 * Sets the credit history length (in years).
+	 * @param historyLength
+	 */
+	public void setHistoryLength(int historyLength) {
+		this.historyLength = historyLength;
+	}
+	/**
+	 * Gets the requested loan amount (in dollar).
+	 * @return the loan amount
+	 */
+	public int getLoanAmount() {
+		return loanAmount;
+	}
+	/** 
+	 * Sets the loan amount.
+	 * @param loanAmount - the loan amount (in dollar).
+	 */
+	public void setLoanAmount(int loanAmount) {
+		this.loanAmount = loanAmount;
+	}
+	/**
+	 * Gets the duration of the loan, the term, (in months).
+	 * @return loanTerm
+	 */
+	public int getLoanTerm() {
+		return loanTerm;
+	}
+	/**
+	 * Sets the term (duration) of the loan (in months)
+	 * @param loanTerm
+	 */
+	public void setLoanTerm(int loanTerm) {
+		this.loanTerm = loanTerm;
+	}
+	/** 
+	 * Sets the Social Security Number (SSN).
+	 * @return ssn
+	 */
+	public int getSsn() {
+		return ssn;
+	}
+	/**
+	 * Sets the Social Security Number (SSN).
+	 * @param ssn
+	 */
+	public void setSsn(int ssn) {
+		this.ssn = ssn;
+	}
+	/**
+	 * Returns a human readable string representation of this object.
+	 * @return toString
+	 */
+	public String toString() {
+		return this.getClass().getSimpleName() + "=["
+			+ "ssn=" + ssn
+		    + ", creditScore=" + creditScore
+			+ ", historyLength=" + historyLength
+			+ ", loanAmount=" + loanAmount
+			+ ", loanTerm=" + loanTerm + "]";	
+	}
+}

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java	2006-07-27 13:30:22 UTC (rev 5306)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteReplyTest.java	2006-07-27 13:31:10 UTC (rev 5307)
@@ -0,0 +1,57 @@
+/*
+* 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.*;
+
+import java.math.BigDecimal;
+
+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.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"
+            + "</org.jboss.soa.esb.samples.loanbroker.banks.BankQuoteReply>";
+		assertTrue(expectedXml.equals(bankQuoteReplyXml));
+	}
+}

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java	2006-07-27 13:30:22 UTC (rev 5306)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankQuoteRequestTest.java	2006-07-27 13:31:10 UTC (rev 5307)
@@ -0,0 +1,59 @@
+/*
+* 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.*;
+
+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);
+		
+		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"
+			+ "</org.jboss.soa.esb.samples.loanbroker.banks.BankQuoteRequest>";
+		assertTrue(expectedXml.equals(bankQuoteRequestXml));
+	}
+}

Added: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java	2006-07-27 13:30:22 UTC (rev 5306)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/test/org/jboss/soa/esb/samples/loanbroker/banks/BankTest.java	2006-07-27 13:31:10 UTC (rev 5307)
@@ -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.*;
+
+import java.math.BigDecimal;
+
+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 obtainExampleXML(){
+		
+		//Building a BankQuoteRequest
+		BankQuoteRequest bankQuoteRequest = new BankQuoteRequest();
+		bankQuoteRequest.setSsn(123456890);
+		bankQuoteRequest.setCreditScore(3);
+		bankQuoteRequest.setHistoryLength(4);
+		bankQuoteRequest.setLoanTerm(72);
+		bankQuoteRequest.setLoanAmount(20000);
+		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));
+	}
+}




More information about the jboss-svn-commits mailing list