1 package com.inversoft.verge.repository.test; 2 3 4 import java.util.ResourceBundle ; 5 6 import com.inversoft.beans.BeanException; 7 import com.inversoft.config.ConfigFactoryRegistry; 8 import com.inversoft.junit.WebTestCase; 9 import com.inversoft.verge.config.VergeConfigConstants; 10 import com.inversoft.verge.config.VergeConfigMediator; 11 import com.inversoft.verge.repository.Repository; 12 import com.inversoft.verge.repository.RepositoryBeanProperty; 13 14 15 22 public class RepositoryBeanPropertyTest extends WebTestCase { 23 24 27 public RepositoryBeanPropertyTest(String name) { 28 super(name); 29 setLocal(true); 30 } 31 32 33 36 public void testLookup() { 37 if (isLocal()) { 39 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 40 "src/com/inversoft/verge/repository/test/test-config.xml"); 41 } 42 43 try { 44 ResourceBundle bundle = ResourceBundle.getBundle( 45 "com.inversoft.verge.config.ConfigFactories"); 46 ConfigFactoryRegistry.load(bundle); 47 new VergeConfigMediator().mediate(context); 48 } catch (Exception e) { 50 fail(e.toString()); 51 } 52 53 try { 54 RepositoryBeanProperty bp = new RepositoryBeanProperty("item1.name", request); 55 assertEquals(SimpleItem.class, bp.getBeanClass()); 56 assertEquals("item1", bp.getRepositoryId()); 57 assertEquals("item1.name", bp.getFullName()); 58 59 SimpleItem item1 = 60 (SimpleItem) Repository.getInstance().lookupItem(request, "item1"); 61 item1.setName("Bob"); 62 assertEquals("Bob", bp.getPropertyValue(request)); 63 64 bp.setPropertyValue(request, "Jane"); 65 assertEquals("Jane", item1.getName()); 66 assertEquals("Jane", bp.getPropertyValue(request)); 67 } catch (BeanException be) { 68 fail(be.toString()); 69 } 70 71 try { 72 RepositoryBeanProperty bp = new RepositoryBeanProperty("item1", 73 "name", request); 74 assertEquals(SimpleItem.class, bp.getBeanClass()); 75 assertEquals("item1", bp.getRepositoryId()); 76 assertEquals("item1.name", bp.getFullName()); 77 78 SimpleItem item1 = 79 (SimpleItem) Repository.getInstance().lookupItem(request, "item1"); 80 item1.setName("Bob"); 81 assertEquals("Bob", bp.getPropertyValue(request)); 82 83 bp.setPropertyValue(request, "Jane"); 84 assertEquals("Jane", item1.getName()); 85 assertEquals("Jane", bp.getPropertyValue(request)); 86 } catch (BeanException be) { 87 fail(be.toString()); 88 } 89 } 90 } | Popular Tags |