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.RepositoryBean; 12 import com.inversoft.verge.repository.config.Config; 13 import com.inversoft.verge.repository.config.RepositoryConfigRegistry; 14 15 16 23 public class RepositoryBeanTest extends WebTestCase { 24 25 28 public RepositoryBeanTest(String name) { 29 super(name); 30 setLocal(true); 31 } 32 33 34 37 public void testLookup() { 38 if (isLocal()) { 40 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 41 "src/com/inversoft/verge/repository/test/test-config.xml"); 42 } 43 44 try { 45 ResourceBundle bundle = ResourceBundle.getBundle( 46 "com.inversoft.verge.config.ConfigFactories"); 47 ConfigFactoryRegistry.load(bundle); 48 new VergeConfigMediator().mediate(context); 49 } catch (Exception e) { 51 fail(e.toString()); 52 } 53 54 try { 55 RepositoryBean bean = new RepositoryBean("item1", request); 56 Object item1 = bean.getInstance(request); 57 assertNotNull(item1); 58 assertEquals(SimpleItem.class, item1.getClass()); 59 } catch (BeanException be) { 60 fail(be.toString()); 61 } 62 63 try { 64 RepositoryBean bean = new RepositoryBean("user", request); 65 Object user = bean.getInstance(request); 66 assertNotNull(user); 67 assertEquals(SimpleItem.class, user.getClass()); 68 } catch (BeanException be) { 69 fail(be.toString()); 70 } 71 72 try { 73 Config config = 74 RepositoryConfigRegistry.getInstance(request).lookup("common"); 75 RepositoryBean bean = new RepositoryBean(config); 76 Object user = bean.getInstance(request); 77 assertNotNull(user); 78 assertEquals(SimpleItem2.class, user.getClass()); 79 } catch (BeanException be) { 80 fail(be.toString()); 81 } 82 } 83 } | Popular Tags |