[jboss-svn-commits] JBL Code SVN: r5004 - labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 11 02:20:59 EDT 2006


Author: arvinder
Date: 2006-07-11 02:20:56 -0400 (Tue, 11 Jul 2006)
New Revision: 5004

Added:
   labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/PersonUnitTest.java
Modified:
   labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/AddressUnitTest.java
Log:
Test additions

Modified: labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/AddressUnitTest.java
===================================================================
--- labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/AddressUnitTest.java	2006-07-10 22:31:34 UTC (rev 5003)
+++ labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/AddressUnitTest.java	2006-07-11 06:20:56 UTC (rev 5004)
@@ -21,45 +21,78 @@
 */
 package org.jboss.soa.esb.tests.common.bizclasses;
 
-import junit.framework.TestCase;
 import org.jboss.soa.esb.tests.BaseTest;
 import org.jboss.soa.esb.common.bizclasses.Address;
 import org.jboss.soa.esb.common.bizclasses.Telephone;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
 
 /**
  * Unit test for the address class.
  *
  * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
  * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
- * @version <tt>$Revision$</tt>
- * $Id$
+ * @version <tt>$Revision:$</tt>
+ *          $Id:$
  */
 public class AddressUnitTest extends BaseTest {
 
 
-
-
-
-
     public void testAddress() throws Exception {
         Address address = getAddress();
         assertTrue("Expecting Address.strNum to be 50. Actual was " +
                 address.getField(Address.ATTRIB.strNum), address.getField(Address.ATTRIB.strNum).equals("50"));
         assertTrue("Expecting Address.strLine1 to be Balcarce. Actual was " +
-                        address.getField(Address.ATTRIB.strLine1), address.getField(Address.ATTRIB.strLine1).equals("Balcarce"));
+                address.getField(Address.ATTRIB.strLine1), address.getField(Address.ATTRIB.strLine1).equals("Balcarce"));
         assertTrue("Expecting Address.twnCty1 to be San Isidro. Actual was " +
-                        address.getField(Address.ATTRIB.twnCty1), address.getField(Address.ATTRIB.twnCty1).equals("San Isidro"));
+                address.getField(Address.ATTRIB.twnCty1), address.getField(Address.ATTRIB.twnCty1).equals("San Isidro"));
         assertTrue("Expecting Address.postalZip to be 1642. Actual was " +
-                        address.getField(Address.ATTRIB.postalZip), address.getField(Address.ATTRIB.postalZip).equals("1642"));
+                address.getField(Address.ATTRIB.postalZip), address.getField(Address.ATTRIB.postalZip).equals("1642"));
         assertTrue("Expecting Address.provSt to be Buenos Aires. Actual was " +
-                                address.getField(Address.ATTRIB.provSt), address.getField(Address.ATTRIB.provSt).equals("Buenos Aires"));
+                address.getField(Address.ATTRIB.provSt), address.getField(Address.ATTRIB.provSt).equals("Buenos Aires"));
         assertTrue("Expecting Address.cntry to be Argentina. Actual was " +
-                                address.getField(Address.ATTRIB.cntry), address.getField(Address.ATTRIB.cntry).equals("Argentina"));
+                address.getField(Address.ATTRIB.cntry), address.getField(Address.ATTRIB.cntry).equals("Argentina"));
 
+        // Phone
+        assertTrue("Expecting Address.phone[0].role to be torIP. Actual was " +
+                address.getPhoneAt(0).getRole(), address.getPhoneAt(0).getRole().equals("torIP"));
+        assertTrue("Expecting Address.phone[0].country to be null. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry) == null);
+        assertTrue("Expecting Address.phone[0].city to be 416. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.city), address.getPhoneAt(0).getField(Telephone.ATTRIB.city).equals("416"));
+        assertTrue("Expecting Address.phone[0].num to be 555-1212. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.num), address.getPhoneAt(0).getField(Telephone.ATTRIB.num).equals("555-1212"));
+        assertTrue("Expecting Address.phone[0].ext to be null. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.ext), address.getPhoneAt(0).getField(Telephone.ATTRIB.ext) == null);
+
+        assertTrue("Expecting Address.phone[1].role to be home. Actual was " +
+                address.getPhoneAt(1).getRole(), address.getPhoneAt(1).getRole().equals("home"));
+        assertTrue("Expecting Address.phone[1].country to be 54. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry).equals("54"));
+        assertTrue("Expecting Address.phone[1].city to be 11. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.city), address.getPhoneAt(1).getField(Telephone.ATTRIB.city).equals("11"));
+        assertTrue("Expecting Address.phone[1].num to be 4555-1111. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.num), address.getPhoneAt(1).getField(Telephone.ATTRIB.num).equals("4555-1111"));
+        assertTrue("Expecting Address.phone[1].ext to be 7. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.ext), address.getPhoneAt(1).getField(Telephone.ATTRIB.ext).equals("7"));
+
     }
 
 
+    public void testToDTO() throws Exception {
+        BaseBusinessObject addressA = getAddress();
+        addressA.setPackage();
 
+        BobjStdDTO oDto = addressA.toDTO();
+        System.out.println(oDto.toXml());
+
+        Address addressB = (Address) BaseBusinessObject.getFromDTO(oDto);
+        System.out.println(addressB.toDTO().toXml());
+
+        assertTrue("Expecting AddressA == AddressB", addressA.toDTO().toXml().equals(addressB.toDTO().toXml()));
+    }
+
+
     static Address getAddress() throws Exception {
         Address oP = new Address((String) null);
         oP.setField(Address.ATTRIB.strNum, "50");
@@ -77,12 +110,12 @@
 
     public static Telephone newPhone(String p_sRole, String p_sCtry, String p_sCity,
                                      String p_sNum, String p_sExt) {
-        Telephone oP = new Telephone((String)null);
+        Telephone oP = new Telephone((String) null);
         oP.setRole(p_sRole);
-        oP.setField(Telephone.ATTRIB.cntry,p_sCtry);
-        oP.setField(Telephone.ATTRIB.city,p_sCity);
-        oP.setField(Telephone.ATTRIB.num,p_sNum);
-        oP.setField(Telephone.ATTRIB.ext,p_sExt);
+        oP.setField(Telephone.ATTRIB.cntry, p_sCtry);
+        oP.setField(Telephone.ATTRIB.city, p_sCity);
+        oP.setField(Telephone.ATTRIB.num, p_sNum);
+        oP.setField(Telephone.ATTRIB.ext, p_sExt);
 
         return oP;
     }

Added: labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/PersonUnitTest.java
===================================================================
--- labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/PersonUnitTest.java	2006-07-10 22:31:34 UTC (rev 5003)
+++ labs/jbossesb/branches/refactor/ESBCore/tests/src/org/jboss/soa/esb/tests/common/bizclasses/PersonUnitTest.java	2006-07-11 06:20:56 UTC (rev 5004)
@@ -0,0 +1,204 @@
+/*
+* 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.tests.common.bizclasses;
+
+import org.jboss.soa.esb.tests.BaseTest;
+import org.jboss.soa.esb.common.bizclasses.Person;
+import org.jboss.soa.esb.common.bizclasses.OneValue;
+import org.jboss.soa.esb.common.bizclasses.Address;
+import org.jboss.soa.esb.common.bizclasses.Telephone;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * Unit test for the person class.
+ *
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ *          $Id:$
+ */
+public class PersonUnitTest extends BaseTest {
+
+
+    public void testPerson() throws Exception {
+
+        Person person = getPerson();
+
+        assertTrue("Expecting Person.pfx to be Mr. Actual was " +
+                person.getField(Person.ATTRIB.pfx), person.getField(Person.ATTRIB.pfx).equals("Mr."));
+        assertTrue("Expecting Person.fmlyN to be Brum. Actual was " +
+                person.getField(Person.ATTRIB.fmlyN), person.getField(Person.ATTRIB.fmlyN).equals("Brum"));
+        assertTrue("Expecting Person.givN to be Daniel. Actual was " +
+                person.getField(Person.ATTRIB.givN), person.getField(Person.ATTRIB.givN).equals("Daniel"));
+        assertTrue("Expecting Person.sfx to be the 1st.. Actual was " +
+                person.getField(Person.ATTRIB.sfx), person.getField(Person.ATTRIB.sfx).equals("the 1st."));
+
+    }
+
+    public void testPersonEmail() throws Exception {
+
+        Person person = getPerson();
+
+        String expectedEmail0 = "<OneValue rol=\"home\" v=\"myaddr at gmail.com\"/>";
+        assertTrue("Expecting Person.email[0] to be  Actual was " +
+                person.getEmailAt(0).toString(), person.getEmailAt(0).toString().equals(expectedEmail0));
+
+        String expectedEmail1 = "<OneValue rol=\"work\" v=\"john.smith at jboss.com\"/>";
+        assertTrue("Expecting Person.email[0] to be  Actual was " +
+                person.getEmailAt(1).toString(), person.getEmailAt(1).toString().equals(expectedEmail1));
+    }
+
+    public void testPersonTelephone() throws Exception {
+
+        Person person = getPerson();
+
+        assertTrue("Expecting Person.phone[0].role to be basement. Actual was " +
+                person.getPhoneAt(0).getRole(), person.getPhoneAt(0).getRole().equals("basement"));
+        assertTrue("Expecting Person.phone[0].country to be 1. Actual was " +
+                person.getPhoneAt(0).getField(Telephone.ATTRIB.cntry), person.getPhoneAt(0).getField(Telephone.ATTRIB.cntry).equals("1"));
+        assertTrue("Expecting Person.phone[0].city to be 416. Actual was " +
+                person.getPhoneAt(0).getField(Telephone.ATTRIB.city), person.getPhoneAt(0).getField(Telephone.ATTRIB.city).equals("416"));
+        assertTrue("Expecting Person.phone[0].num to be 555-1212. Actual was " +
+                person.getPhoneAt(0).getField(Telephone.ATTRIB.num), person.getPhoneAt(0).getField(Telephone.ATTRIB.num).equals("555-1212"));
+        assertTrue("Expecting Person.phone[0].ext to be null. Actual was " +
+                person.getPhoneAt(0).getField(Telephone.ATTRIB.ext), person.getPhoneAt(0).getField(Telephone.ATTRIB.ext) == null);
+
+        assertTrue("Expecting Person.phone[1].role to be basement. Actual was " +
+                person.getPhoneAt(1).getRole(), person.getPhoneAt(1).getRole().equals("cell"));
+        assertTrue("Expecting Person.phone[1].country to be null. Actual was " +
+                person.getPhoneAt(1).getField(Telephone.ATTRIB.cntry), person.getPhoneAt(1).getField(Telephone.ATTRIB.cntry) == null);
+        assertTrue("Expecting Person.phone[1].city to be 416. Actual was " +
+                person.getPhoneAt(1).getField(Telephone.ATTRIB.city), person.getPhoneAt(1).getField(Telephone.ATTRIB.city).equals("416"));
+        assertTrue("Expecting Person.phone[1].num to be 666-4444. Actual was " +
+                person.getPhoneAt(1).getField(Telephone.ATTRIB.num), person.getPhoneAt(1).getField(Telephone.ATTRIB.num).equals("666-4444"));
+        assertTrue("Expecting Person.phone[1].ext to be null. Actual was " +
+                person.getPhoneAt(1).getField(Telephone.ATTRIB.ext), person.getPhoneAt(1).getField(Telephone.ATTRIB.ext) == null);
+
+    }
+
+    public void testPersonAddress() throws Exception {
+
+        Address address = getPerson().getAddressAt(0);
+        assertTrue("Expecting Address.strNum to be 50. Actual was " +
+                address.getField(Address.ATTRIB.strNum), address.getField(Address.ATTRIB.strNum).equals("50"));
+        assertTrue("Expecting Address.strLine1 to be Balcarce. Actual was " +
+                address.getField(Address.ATTRIB.strLine1), address.getField(Address.ATTRIB.strLine1).equals("Balcarce"));
+        assertTrue("Expecting Address.twnCty1 to be San Isidro. Actual was " +
+                address.getField(Address.ATTRIB.twnCty1), address.getField(Address.ATTRIB.twnCty1).equals("San Isidro"));
+        assertTrue("Expecting Address.postalZip to be 1642. Actual was " +
+                address.getField(Address.ATTRIB.postalZip), address.getField(Address.ATTRIB.postalZip).equals("1642"));
+        assertTrue("Expecting Address.provSt to be Buenos Aires. Actual was " +
+                address.getField(Address.ATTRIB.provSt), address.getField(Address.ATTRIB.provSt).equals("Buenos Aires"));
+        assertTrue("Expecting Address.cntry to be Argentina. Actual was " +
+                address.getField(Address.ATTRIB.cntry), address.getField(Address.ATTRIB.cntry).equals("Argentina"));
+
+        // Phone
+        assertTrue("Expecting Address.phone[0].role to be torIP. Actual was " +
+                address.getPhoneAt(0).getRole(), address.getPhoneAt(0).getRole().equals("torIP"));
+        assertTrue("Expecting Address.phone[0].country to be null. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry) == null);
+        assertTrue("Expecting Address.phone[0].city to be 416. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.city), address.getPhoneAt(0).getField(Telephone.ATTRIB.city).equals("416"));
+        assertTrue("Expecting Address.phone[0].num to be 555-1212. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.num), address.getPhoneAt(0).getField(Telephone.ATTRIB.num).equals("555-1212"));
+        assertTrue("Expecting Address.phone[0].ext to be null. Actual was " +
+                address.getPhoneAt(0).getField(Telephone.ATTRIB.ext), address.getPhoneAt(0).getField(Telephone.ATTRIB.ext) == null);
+
+        assertTrue("Expecting Address.phone[1].role to be home. Actual was " +
+                address.getPhoneAt(1).getRole(), address.getPhoneAt(1).getRole().equals("home"));
+        assertTrue("Expecting Address.phone[1].country to be 54. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry).equals("54"));
+        assertTrue("Expecting Address.phone[1].city to be 11. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.city), address.getPhoneAt(1).getField(Telephone.ATTRIB.city).equals("11"));
+        assertTrue("Expecting Address.phone[1].num to be 4555-1111. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.num), address.getPhoneAt(1).getField(Telephone.ATTRIB.num).equals("4555-1111"));
+        assertTrue("Expecting Address.phone[1].ext to be 7. Actual was " +
+                address.getPhoneAt(1).getField(Telephone.ATTRIB.ext), address.getPhoneAt(1).getField(Telephone.ATTRIB.ext).equals("7"));
+
+
+    }
+
+
+
+
+
+    public void testToDTO() throws Exception {
+        BaseBusinessObject personA = getPerson();
+        personA.setPackage();
+
+        BobjStdDTO oDto = personA.toDTO();
+        System.out.println(oDto.toXml());
+
+        Person personB = (Person) BaseBusinessObject.getFromDTO(oDto);
+        System.out.println(personB.toDTO().toXml());
+
+        assertTrue("Expecting PersonA == PersonB", personA.toDTO().toXml().equals(personB.toDTO().toXml()));
+    }
+
+
+    static Person getPerson() throws Exception {
+        Person oP = new Person((String) null);
+        oP.setField(Person.ATTRIB.pfx, "Mr.");
+        oP.setField(Person.ATTRIB.fmlyN, "Brum");
+        oP.setField(Person.ATTRIB.givN, "Daniel");
+        oP.setField(Person.ATTRIB.sfx, "the 1st.");
+
+        oP.addAddress(getAddress());
+
+        oP.addEmail(OneValue.getStringValue("myaddr at gmail.com", "home"));
+        oP.addEmail(OneValue.getStringValue("john.smith at jboss.com", "work"));
+
+        oP.addPhone(newPhone("basement", "1", "416", "555-1212", null));
+        oP.addPhone(newPhone("cell", null, "416", "666-4444", null));
+
+        return oP;
+    }
+
+    static Address getAddress() throws Exception {
+        Address oP = new Address((String) null);
+        oP.setField(Address.ATTRIB.strNum, "50");
+        oP.setField(Address.ATTRIB.strLine1, "Balcarce");
+        oP.setField(Address.ATTRIB.twnCty1, "San Isidro");
+        oP.setField(Address.ATTRIB.postalZip, "1642");
+        oP.setField(Address.ATTRIB.provSt, "Buenos Aires");
+        oP.setField(Address.ATTRIB.cntry, "Argentina");
+
+        oP.addPhone(newPhone("torIP", null, "416", "555-1212", null));
+        oP.addPhone(newPhone("home", "54", "11", "4555-1111", "7"));
+
+        return oP;
+    }
+
+    public static Telephone newPhone(String p_sRole,
+                                     String p_sCtry, String p_sCity, String p_sNum, String p_sExt) {
+        Telephone oP = new Telephone((String) null);
+        oP.setRole(p_sRole);
+        oP.setField(Telephone.ATTRIB.cntry, p_sCtry);
+        oP.setField(Telephone.ATTRIB.city, p_sCity);
+        oP.setField(Telephone.ATTRIB.num, p_sNum);
+        oP.setField(Telephone.ATTRIB.ext, p_sExt);
+
+        return oP;
+    }
+
+}




More information about the jboss-svn-commits mailing list