1 7 package com.inversoft.verge.mvc.model.web.test; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 12 import com.inversoft.junit.WebTestCase; 13 import com.inversoft.verge.mvc.model.web.WebMetaData; 14 import com.inversoft.verge.mvc.model.web.WebModelHandler; 15 import com.inversoft.verge.util.ScopeConstants; 16 17 18 28 public class WebMetaDataTest extends WebTestCase { 29 30 33 public WebMetaDataTest(String name) { 34 super(name); 35 setLocal(true); 36 } 37 38 39 42 public void testAll() { 43 Map params = new HashMap (); 44 params.put(WebMetaData.CLASS_PARAMETER, 45 "com.inversoft.verge.mvc.model.web.test.Bean1"); 46 params.put(WebMetaData.SCOPE_PARAMETER, 47 "" + ScopeConstants.SESSION_INT); 48 49 try { 50 WebMetaData md = new WebMetaData("test.string1", params); 51 assertEquals("Should have an id of test", md.getID(), "test"); 52 assertEquals("Should have an property of string1", md.getProperty(), 53 "string1"); 54 assertEquals("Should have an definition of test.string1", "test.string1", 55 md.getDefinition()); 56 assertEquals("Should be Bean1 class", md.getModelClass(), Bean1.class); 57 assertEquals("Should be session scoped", md.getScope(), 58 ScopeConstants.SESSION_INT); 59 assertNotNull("Should have model handler", md.getModelHandler()); 60 assertTrue("Should have web model handler", 61 md.getModelHandler() instanceof WebModelHandler); 62 } catch (Exception e) { 63 fail(e.toString()); 64 } 65 66 try { 67 WebMetaData md = new WebMetaData("test", "string1", 68 Bean1.class.getName(), ScopeConstants.SESSION_INT); 69 assertEquals("Should have an id of test", md.getID(), "test"); 70 assertEquals("Should have an property of string1", md.getProperty(), 71 "string1"); 72 assertEquals("Should be Bean1 class", md.getModelClass(), Bean1.class); 73 assertEquals("Should be session scoped", md.getScope(), 74 ScopeConstants.SESSION_INT); 75 assertEquals("Should be the same parameters map", params, md.getExtraParams()); 76 assertEquals("Should be the same definition", "test.string1", md.getDefinition()); 77 assertNotNull("Should have model handler", md.getModelHandler()); 78 assertTrue("Should have web model handler", 79 md.getModelHandler() instanceof WebModelHandler); 80 } catch (Exception e) { 81 fail(e.toString()); 82 } 83 84 try { 85 WebMetaData md = new WebMetaData("test", Bean1.class.getName(), 86 ScopeConstants.SESSION_INT); 87 assertEquals("Should have an id of test", md.getID(), "test"); 88 assertNull("Should NOT have a property", md.getProperty()); 89 assertEquals("Should be Bean1 class", md.getModelClass(), Bean1.class); 90 assertEquals("Should be session scoped", md.getScope(), 91 ScopeConstants.SESSION_INT); 92 assertEquals("Should be the same parameters map", params, md.getExtraParams()); 93 assertNotNull("Should have model handler", md.getModelHandler()); 94 assertTrue("Should have web model handler", 95 md.getModelHandler() instanceof WebModelHandler); 96 md.setProperty("string1"); 97 assertEquals("Should have an property of string1", md.getProperty(), 98 "string1"); 99 assertEquals("Should be the same definition", "test.string1", 100 md.getDefinition()); 101 } catch (Exception e) { 102 fail(e.toString()); 103 } 104 105 try { 107 WebMetaData md = new WebMetaData("item", Bean1.class.getName(), 108 ScopeConstants.SESSION_INT); 109 assertEquals("Should be item", "item", md.getID()); 110 assertNull("Should be null", md.getProperty()); 111 md.setProperty("string1"); 112 assertEquals("Should have an property of string1", md.getProperty(), 113 "string1"); 114 assertEquals("item.string1", md.getDefinition()); 115 md.setProperty("string2"); 116 assertEquals("item.string2", md.getDefinition()); 117 md.setProperty("foo"); 118 assertEquals("item.foo", md.getDefinition()); 119 } catch (Exception e) { 120 fail(e.toString()); 121 } 122 } 123 } 124 | Popular Tags |