User: salborini
  Date: 00/10/09 11:07:18

  Added:       src/main/org/jboss/test/dbtest/test Main.java
  Log:
  This test is intended for people to test their database settings.
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/dbtest/test/Main.java
  
  Index: Main.java
  ===================================================================
  package org.jboss.test.dbtest.test;
  
  import java.rmi.*;
  
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.ejb.DuplicateKeyException;
  import javax.ejb.Handle;
  import javax.ejb.EJBMetaData;
  import javax.ejb.FinderException;
  
  import java.util.Date;
  import java.util.Properties;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Enumeration;
  
  import org.jboss.test.dbtest.interfaces.AllTypes;
  import org.jboss.test.dbtest.interfaces.AllTypesHome;
  import org.jboss.test.dbtest.interfaces.MyObject;
  import org.jboss.test.dbtest.interfaces.Record;
  import org.jboss.test.dbtest.interfaces.RecordHome;
  
  
  public class Main {
        
        static boolean deployed = false;
        
        public static void main(String arg[]) {
                Main main = new Main();
                
                try {
                        main.setUp();
                
                } catch (Exception e) {
                        System.out.println("Setup failed:");
                        e.printStackTrace();
                }
                
                try {
                        main.testAllTypesBean();
                        System.out.println();
                        
System.out.println("_____________________________________________");
                        System.out.println("Congratulations!  Test completed");
                        System.out.println("Please report success to the mailing 
list:");
                        System.out.println("   [EMAIL PROTECTED]");
                        System.out.println();
                        System.out.println("Don't forget to mention:");
                        System.out.println("   OS                      :");
                        System.out.println("   JDK vendor/version      :");
                        System.out.println();
                        System.out.println("   jBoss version           :");
                        System.out.println();
                        System.out.println("   Database name/version   :");
                        System.out.println("   JDBC driver version     :");
                        System.out.println();
                        System.out.println("And please include:");
                        System.out.println("   Your setup: relevant parts of 
jboss.properties, jboss.conf and jboss.jcml");
                        System.out.println("   The type-mappings from jaws.xml if you 
changed them");
                        System.out.println();
                        System.out.println("Thanks very much!");
                        System.out.println();
                
                } catch (Exception e) {
                        System.out.println();
                        
System.out.println("_____________________________________________");
                        System.out.println("Sorry, test failed.  Try again with 
different settings!");
                        System.out.println("Thanks for your time...");
                        System.out.println();
                
                }
        }
        
        
        public void testAllTypesBean() throws Exception {
                int test = 0;
                
                Context ctx = new InitialContext();
                
                System.out.println();
                System.out.print(++test+"- "+"Looking up the home AllTypes...");
                
                AllTypesHome allTypesHome;
                
                try {
                        allTypesHome = (AllTypesHome) ctx.lookup("AllTypes");
                        
                        if (allTypesHome == null) throw new Exception("abort");
                                System.out.println("OK");
                
                } catch (Exception e) {
                        System.out.println();
                        System.out.println("Could not lookup the context:  the beans 
are probably not deployed");
                        System.out.println("Check the server trace for details");
                        
                        throw new Exception();
                }
                
                System.out.print(++test+"- "+"Calling findByPrimaryKey on AllTypesHome 
with name seb...");
                
                AllTypes allTypes = null;
                
                try {
                        allTypes = allTypesHome.findByPrimaryKey("seb");
                } catch (Exception e) {System.out.println(e.getMessage());}
                
                if (allTypes == null) {
                        
                        System.out.println("not found OK");
                        System.out.print(++test+"- "+"Calling create on AllTypesHome 
with name seb...");
                        allTypes = allTypesHome.create("seb");
                }
                
                if (allTypes != null) System.out.println("OK"); else {
                        System.out.println();
                        System.out.println("Could not find or create the alltypes 
bean");
                        System.out.println("Check the server trace for details");
                        
                        throw new Exception();
                }
                
                
                System.out.println("Getting all the fields");
                System.out.println(++test+"- "+"boolean " + allTypes.getBoolean() + " 
OK");
                System.out.println(++test+"- "+"byte " + allTypes.getByte() + " OK");
                System.out.println(++test+"- "+"short " + allTypes.getShort() + " OK");
                System.out.println(++test+"- "+"int " + allTypes.getInt() + " OK");
                System.out.println(++test+"- "+"long " + allTypes.getLong() + " OK");
                System.out.println(++test+"- "+"float " + allTypes.getFloat() + " OK");
                System.out.println(++test+"- "+"double " + allTypes.getDouble() + " 
OK");
                System.out.println("No char test yet, bug in jdk");
                System.out.println(++test+"- "+"String " + allTypes.getString() + " 
OK");
                System.out.println(++test+"- "+"Date " + allTypes.getDate() + " OK");
                System.out.println(++test+"- "+"Timestamp " + allTypes.getTimestamp() 
+ " OK");
                
                System.out.print(++test+"- "+"MyObject ");
                MyObject obj = allTypes.getObject();
                System.out.println("OK");
                
                System.out.print(++test+"- "+"Creating Record beans and adding them to 
the Collection in Alltypes..");
                RecordHome recordHome = (RecordHome) ctx.lookup("Record");
                
                Record[] record = new Record[3];
                int i;
                for (i=0; i<3; i++) {
                        try { 
                                record[i] = recordHome.findByPrimaryKey("bill " + i);
                        } catch (FinderException e) {
                                record[i] = recordHome.create("bill " + i);
                        }
                        
                        record[i].setAddress("SanFrancisco, CA 9411"+i);
                        allTypes.addObjectToList(record[i]);
                }
                System.out.println("OK");
                
                System.out.print(++test+"- "+"Getting them back..");
                
                Collection collection = allTypes.getObjectList();
                boolean ok = true;
                
                for (i=0; i<3; i++) ok = ok && collection.contains(record[i]);
                        
                if (ok) System.out.println("OK"); else {
                        System.out.println("failed");
                        throw new Exception("abort");
                }
        }
        
        
        protected void setUp() throws Exception 
        {
                if (deployed) return;
                        
                System.out.println("_____________________________________________");
                System.out.println();
                System.out.println("jBoss, the EJB Open Source Server");
                System.out.println("Copyright (C), The jBoss Organization, 2000");
                System.out.println("_____________________________________________");
                System.out.println();
                System.out.println("Welcome to the database test");
                System.out.println("_____________________________________________");
                System.out.println();
                System.out.print("Deploying the bean...");
                System.out.flush();
                new org.jboss.jmx.client.Deployer().deploy("../deploy/dbtest.jar");
                deployed = true;
                System.out.println("done!");
        }
  }
  
  
  

Reply via email to