1 package org.bsf.smartValueObject.mediator; 2 3 import junit.framework.TestCase; 4 import org.bsf.smartValueObject.mediator.EjbSvoMediator; 5 import org.bsf.smartValueObject.mediator.Mediator; 6 import org.bsf.smartValueObject.mediator.MediatorException; 7 import org.bsf.smartValueObject.TestVO; 8 9 import java.util.Properties ; 10 11 16 public class TestEjbSvoMediator extends TestCase { 17 private EjbSvoMediator mediator; 18 19 public void setUp() { 20 Properties props = new Properties (); 21 props.setProperty(Mediator.INDEXFIELD, "id"); 22 23 mediator = new EjbSvoMediator(TestVO.class, props); 24 try { 25 storeSampleObjects(); 26 } catch (MediatorException e) { 27 fail("could not initialize TestCase"); 28 } 29 } 30 31 private void storeSampleObjects() throws MediatorException { 32 TestVO test1 = new TestVO(); 33 test1.setId(42); 34 test1.setName("Number 42"); 35 mediator.updateGraph(test1); 36 37 TestVO test2 = new TestVO(); 38 test2.setId(23); 39 test2.setName("Number 23"); 40 mediator.updateGraph(test2); 41 } 42 43 public void testGetGraph() throws MediatorException { 44 int id = 42; 45 TestVO test1 = new TestVO(); 46 test1.setId(id); 47 TestVO test2 = (TestVO) mediator.getGraph(test1); 48 49 assertTrue("Got no new reference", test1 != test2); 50 assertEquals("Got no correct instance", id, test2.getId()); 51 assertEquals("Got no correcy instance", "Number 42", test2.getName()); 52 } 53 54 public void testNotFound() { 55 TestVO test1 = new TestVO(); 56 test1.setId(10); 57 58 try { 59 TestVO test2 = (TestVO) mediator.getGraph(test1); 60 } catch (MediatorException e) { 61 return; 63 } 64 65 fail("Got not exception while searching non-existent object"); 66 } 67 68 public void testStoreGraph() throws MediatorException { 69 TestVO test1 = new TestVO(); 70 test1.setId(99); 71 test1.setName("air balloons"); 72 mediator.updateGraph(test1); 73 74 TestVO testProto = new TestVO(); 75 testProto.setId(99); 76 77 TestVO result = (TestVO) mediator.getGraph(testProto); 78 79 assertTrue(test1 != result); 80 assertEquals(test1.getId(), result.getId()); 81 assertEquals(test1.getName(), result.getName()); 82 } 83 } 84 | Popular Tags |