1 51 52 package org.bsf.listOfValues; 53 54 import junit.framework.TestCase; 55 import org.bsf.listOfValues.client.LovManager; 56 import org.bsf.listOfValues.exceptions.NoSuchLovException; 57 import org.bsf.listOfValues.exceptions.NoSuchLovValueException; 58 import org.bsf.remoting.EJBDefinition; 59 import org.bsf.remoting.http.HttpServiceFactory; 60 61 import java.util.List ; 62 63 69 public class TestLovService extends TestCase { 70 private HttpServiceFactory factory = new HttpServiceFactory(); 71 72 private static final Long FIRST_LOV_TO_TEST = new Long ( 1 ); 74 private static final Long SECOND_LOV_TO_TEST = new Long ( 3 ); 75 76 private static final Long NOT_A_LOV_OID = new Long ( 9999 ); 78 private static final Long NOT_A_LOV_VALUE_OID_IN_FIRST_LOV_TO_TEST = new Long ( 0 ); 79 80 EJBDefinition lovServiceDefinition = new EJBDefinition( "ejb/LOVService", 81 "org.bsf.listOfValues.LOVServiceHome", 82 "org.bsf.listOfValues.LOVService" ); 83 84 public TestLovService( String s ) { 85 super( s ); 86 87 factory.setPort( 8080 ); 89 90 factory.setHost( "localhost" ); 92 93 factory.setServerContext( "testLov" ); 95 96 try { 97 LovManager.setLovService( (LOVService) factory.getService( lovServiceDefinition ) ); 101 } catch( Exception e ) { 102 System.out.println( "Unable to retrieve the LovService... Will exit..." ); 103 104 e.printStackTrace(); 106 107 System.exit( 0 ); 109 } 110 } 111 112 117 public void testLovRetrieval() throws Exception { 118 try { 119 System.out.println( "\nRunning: testLovRetrieval()" ); 120 121 printLov( FIRST_LOV_TO_TEST, LovManager.getListOfValues( FIRST_LOV_TO_TEST ) ); 123 124 printLov( SECOND_LOV_TO_TEST, LovManager.getListOfValues( SECOND_LOV_TO_TEST ) ); 126 } catch( NoSuchLovException e ) { 127 fail(); 128 } 129 } 130 131 135 public void testMissingLov() throws Exception { 136 try { 137 System.out.println( "\nRunning: testMissingLov()" ); 138 139 LovManager.getListOfValues( NOT_A_LOV_OID ); 140 } catch( NoSuchLovException e ) { 141 System.out.println( "\n[Success] testMissingLov: We managed to get the NoSuchLovException..." ); 143 144 return; 146 } 147 148 fail(); 150 } 151 152 156 public void testMissingLovValue() throws Exception { 157 try { 158 System.out.println( "\nRunning: testMissingLovValue()" ); 159 160 LovManager.getLovValue( FIRST_LOV_TO_TEST, NOT_A_LOV_VALUE_OID_IN_FIRST_LOV_TO_TEST ); 161 } catch( NoSuchLovException e ) { 162 fail(); 164 } catch( NoSuchLovValueException e ) { 165 System.out.println( "\n[Success] testMissingLovValue: We managed to get the NoSuchLovValueException..." ); 167 168 return; 170 } 171 172 fail(); 174 } 175 176 private void printLov( Long p_lovOID, List p_lov ) { 177 System.out.println( "\nDisplaying LOV: " + p_lovOID ); 178 179 if ( p_lov == null ) { 180 System.out.println( "Null LOV..." ); 181 } else { 182 for ( int index = 0 ; index < p_lov.size() ; index++ ) { 183 System.out.println( ( p_lov.get( index ) ) ); 184 } 185 } 186 } 187 } | Popular Tags |