1 package org.bsf.smartValueObject.demo; 2 3 import junit.framework.TestCase; 4 import org.bsf.remoting.EJBDefinition; 5 import org.bsf.remoting.http.HttpServiceFactory; 6 import org.bsf.smartValueObject.mediator.ConcurrencyException; 7 import org.bsf.smartValueObject.Versionable; 8 import org.bsf.smartValueObject.SmartAccess; 9 10 import java.rmi.RemoteException ; 11 import java.util.Iterator ; 12 13 16 public class SVODemoClient extends TestCase { 17 18 private static final EJBDefinition SVO_SERVICE = 19 new EJBDefinition( "ejb/SVODemoService", 20 "org.bsf.smartValueObject.demo.SVODemoServiceHome", 21 "org.bsf.smartValueObject.demo.SVODemoService" ); 22 23 private SVODemoService svoService = null; 24 private SVODemoUser svoUser = null; 25 26 public SVODemoClient() { 27 HttpServiceFactory factory = new HttpServiceFactory(); 28 factory.setHost( "localhost" ); 29 factory.setPort( 8080 ); 30 factory.setServerContext( "SvoDemo" ); 31 svoService = (SVODemoService) factory.getService( SVO_SERVICE ); 32 try { 33 svoUser = svoService.createUserService(); 34 } catch( java.rmi.RemoteException e ) { 35 e.printStackTrace(); 36 } 37 } 38 39 43 public CompanyVO getCompanyGraph() throws RemoteException { 44 CompanyVO vo = new CompanyVO(); 45 46 vo.setId( new Long ( 0 ) ); 48 49 return (CompanyVO) svoUser.getCompanyVo( vo ); 50 } 51 52 public String storeCompanyGraph( Object graph ) throws RemoteException , 53 ConcurrencyException { 54 return svoUser.updateCompanyVo( graph ); 55 } 56 57 60 public void modifyConcurrently() throws RemoteException { 61 svoUser.modifyConcurrently(); 62 } 63 64 68 72 public void testSvoUser() throws Exception { 73 CompanyVO vo = this.getCompanyGraph(); 74 assertNotNull( vo ); 75 assertEquals( new Long ( 0 ), vo.getId() ); 76 77 SubsidiaryVO[] subAr = (SubsidiaryVO[]) 78 vo.getSubsidiaries().toArray( 79 new SubsidiaryVO[ vo.getSubsidiaries().size() ] ); 80 SubsidiaryVO parisSub = subAr[ 0 ]; 81 parisSub.setName( "Joli Paris" ); 82 83 System.out.println( this.storeCompanyGraph( vo ) ); 84 vo = this.getCompanyGraph(); 85 86 this.modifyConcurrently(); 87 88 vo.setName( vo.getName().toUpperCase() ); 89 90 try { 91 this.storeCompanyGraph( vo ); 92 } catch( ConcurrencyException e ) { 93 return; 94 } 95 fail( "Expected concurrency exception" ); 97 } 98 99 public void testBug() throws Exception { 100 CompanyVO vo = this.getCompanyGraph(); 101 assertNotNull( vo ); 102 assertEquals( new Long ( 0 ), vo.getId() ); 103 104 for (Iterator it = vo.subsidiaries(); it.hasNext(); ) { 105 vo.removeSubsidiary((SubsidiaryVO) it.next()); 106 } 107 assertTrue(!((Versionable) vo).isDirty()); 108 System.out.println(this.storeCompanyGraph(vo)); 109 } 110 111 public void testEverythingCleanOnBegin() throws Exception { 112 CompanyVO vo = this.getCompanyGraph(); 113 assertNotNull( vo ); 114 assertEquals( new Long ( 0 ), vo.getId() ); 115 assertTrue(!SmartAccess.isGraphDirty(vo)); 116 } 117 } 118 | Popular Tags |