1 7 package com.inversoft.verge.repository.test; 8 9 10 import java.util.ResourceBundle ; 11 12 import com.inversoft.config.ConfigFactoryRegistry; 13 import com.inversoft.junit.WebTestCase; 14 import com.inversoft.verge.config.VergeConfigConstants; 15 import com.inversoft.verge.config.VergeConfigMediator; 16 import com.inversoft.verge.repository.Repository; 17 import com.inversoft.verge.repository.RepositoryException; 18 19 20 27 public class RepositoryTest extends WebTestCase { 28 29 32 public RepositoryTest(String name) { 33 super(name); 34 setLocal(true); 35 } 36 37 38 41 public void testInitialization() { 42 43 if (isLocal()) { 45 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 46 "src/com/inversoft/verge/repository/test/test-config.xml"); 47 } 48 49 try { 50 ResourceBundle bundle = ResourceBundle.getBundle( 51 "com.inversoft.verge.config.ConfigFactories"); 52 ConfigFactoryRegistry.load(bundle); 53 new VergeConfigMediator().mediate(context); 54 } catch (Exception e) { 56 fail(e.toString()); 57 } 58 } 59 60 63 public void testItemSetup() { 64 65 testInitialization(); 67 68 SimpleItem item1 = 70 (SimpleItem) Repository.getInstance().lookupItem(request, "item1"); 71 assertTrue("item1 should not be null", item1 != null); 72 73 SimpleItem item2 = 74 (SimpleItem) Repository.getInstance().lookupItem(request, "item2"); 75 assertTrue("item2 should be Brian Pontarelli", 76 item2.getName().equals("Brian Pontarelli")); 77 assertTrue("item2 should be 26 years old", 78 item2.getAge().intValue() == 26); 79 assertTrue("item2 should have 3.14 dollars", 80 item2.getMoney().floatValue() == 3.14f); 81 82 assertTrue("item1 and item2 should be in the request", 83 request.getAttribute("item1") != null && 84 request.getAttribute("item2") != null); 85 assertTrue("item1 and item2 should be in the request and of correct type", 86 request.getAttribute("item1") instanceof SimpleItem && 87 request.getAttribute("item2") instanceof SimpleItem); 88 89 assertTrue(Repository.getInstance().isItemLoaded(request, "item1")); 90 assertTrue(Repository.getInstance().isItemLoaded(request, "item2")); 91 assertFalse(Repository.getInstance().isItemLoaded(request, "user")); 92 93 assertTrue(Repository.getInstance().isValidItem(request, "item1")); 94 } 95 96 100 public void testItemReferences() { 101 102 testInitialization(); 104 105 SimpleItem user = 107 (SimpleItem) Repository.getInstance().lookupItem(request, "user"); 108 assertTrue("user should not be null", user != null); 109 110 SimpleItem2 address1 = user.getReference(); 111 SimpleItem2 address2 = 112 (SimpleItem2) Repository.getInstance().lookupItem(request, "address"); 113 assertTrue("address1 and address2 should be the same object", address1 == address2); 114 assertTrue("address1 should be Chicago", address1.getCity().equals("Chicago")); 115 assertTrue("address1 should be IL", address1.getState().equals("IL")); 116 117 assertTrue("user and address should be in the request", 118 request.getSession().getAttribute("user") != null && 119 request.getSession().getAttribute("address") != null); 120 assertTrue("user and address should be in the request and of correct type", 121 request.getSession().getAttribute("user") instanceof SimpleItem && 122 request.getSession().getAttribute("address") instanceof SimpleItem2); 123 } 124 125 128 public void testLookupFailure() { 129 130 testInitialization(); 132 133 try { 134 Repository.getInstance().lookupItem(request, "notValid"); 135 fail("Should not have found the notValid item"); 136 } catch (RepositoryException re) { 137 } 139 } 140 141 144 public void testCreateFailure() { 145 146 testInitialization(); 148 149 try { 150 Repository.getInstance().lookupItem(request, "badCreate"); 151 fail("Should not have been able to create the bad item"); 152 } catch (RepositoryException re) { 153 } 155 } 156 157 160 public void testBadReference() { 161 162 testInitialization(); 164 165 try { 166 Repository.getInstance().lookupItem(request, "badRef"); 167 fail("Should not have been able to create the reference"); 168 } catch (RepositoryException re) { 169 } 171 } 172 173 176 public void testBadProperty() { 177 178 testInitialization(); 180 181 try { 182 Repository.getInstance().lookupItem(request, "failProperty"); 183 fail("Should not have been able to find the property"); 184 } catch (RepositoryException re) { 185 } 187 } 188 } | Popular Tags |