1 7 package com.inversoft.verge.mvc.test; 8 9 10 import junit.framework.TestCase; 11 12 import com.inversoft.verge.mvc.MVCConstants; 13 import com.inversoft.verge.mvc.MVCRegistry; 14 import com.inversoft.verge.mvc.controller.DefaultControllerParser; 15 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowControllerHandler; 16 import com.inversoft.verge.mvc.controller.form.FormControllerHandler; 17 import com.inversoft.verge.mvc.model.DefaultModelHandler; 18 import com.inversoft.verge.mvc.model.DefaultModelParser; 19 import com.inversoft.verge.mvc.model.actionflow.ActionFlowModelResolver; 20 import com.inversoft.verge.mvc.model.form.FormModelResolver; 21 import com.inversoft.verge.mvc.model.repository.RepositoryModelHandler; 22 import com.inversoft.verge.mvc.model.repository.RepositoryModelResolver; 23 import com.inversoft.verge.mvc.model.web.WebModelHandler; 24 import com.inversoft.verge.mvc.model.web.WebModelResolver; 25 import com.inversoft.verge.mvc.validator.DefaultValidatorParser; 26 import com.inversoft.verge.mvc.validator.actionflow.ActionFlowValidatorHandler; 27 import com.inversoft.verge.mvc.validator.form.FormValidatorHandler; 28 29 30 39 public class MVCRegistryTest extends TestCase { 40 41 44 public MVCRegistryTest(String name) { 45 super(name); 46 } 47 48 49 52 public void testAll() { 53 TestControllerParser cp = new TestControllerParser(); 54 TestControllerHandler ch = new TestControllerHandler(); 55 TestModelParser mp = new TestModelParser(); 56 TestModelHandler mh = new TestModelHandler(); 57 TestModelResolver mr = new TestModelResolver(); 58 59 MVCRegistry.register("test", cp); 60 MVCRegistry.register("test", ch); 61 MVCRegistry.register("test", mp); 62 MVCRegistry.register("test", mh); 63 MVCRegistry.register("test", mr); 64 65 assertTrue("Should be == cp", MVCRegistry.lookupControllerParser("test") == cp); 66 assertTrue("Should be == ch", MVCRegistry.lookupControllerHandler("test") == ch); 67 assertTrue("Should be == mp", MVCRegistry.lookupModelParser("test") == mp); 68 assertTrue("Should be == mh", MVCRegistry.lookupModelHandler("test") == mh); 69 assertTrue("Should be == mr", MVCRegistry.lookupModelResolver("test") == mr); 70 71 MVCRegistry.register("test", new TestControllerParser()); 72 MVCRegistry.register("test", new TestControllerHandler()); 73 MVCRegistry.register("test", new TestModelParser()); 74 MVCRegistry.register("test", new TestModelHandler()); 75 MVCRegistry.register("test", new TestModelResolver()); 76 77 assertTrue("Should be != cp", MVCRegistry.lookupControllerParser("test") != cp); 78 assertTrue("Should be != ch", MVCRegistry.lookupControllerHandler("test") != ch); 79 assertTrue("Should be != mp", MVCRegistry.lookupModelParser("test") != mp); 80 assertTrue("Should be != mh", MVCRegistry.lookupModelHandler("test") != mh); 81 assertTrue("Should be != mr", MVCRegistry.lookupModelResolver("test") != mr); 82 83 assertTrue("Should be == null", MVCRegistry.lookupControllerParser("foo") == null); 84 assertTrue("Should be == null", MVCRegistry.lookupControllerHandler("foo") == null); 85 assertTrue("Should be == null", MVCRegistry.lookupModelParser("foo") == null); 86 assertTrue("Should be == null", MVCRegistry.lookupModelHandler("foo") == null); 87 assertTrue("Should be == null", MVCRegistry.lookupModelResolver("foo") == null); 88 } 89 90 93 public void testDefaults() { 94 assertTrue("Should be a default controller parser", 95 MVCRegistry.lookupControllerParser(MVCConstants.DEFAULT_NAME) != null && 96 MVCRegistry.lookupControllerParser(MVCConstants.DEFAULT_NAME) instanceof 97 DefaultControllerParser); 98 assertTrue("Should be a ActionFlow controller handler", 99 MVCRegistry.lookupControllerHandler(MVCConstants.ACTIONFLOW_NAME) != null && 100 MVCRegistry.lookupControllerHandler(MVCConstants.ACTIONFLOW_NAME) instanceof 101 ActionFlowControllerHandler); 102 assertTrue("Should be a form controller handler", 103 MVCRegistry.lookupControllerHandler(MVCConstants.FORM_NAME) != null && 104 MVCRegistry.lookupControllerHandler(MVCConstants.FORM_NAME) instanceof 105 FormControllerHandler); 106 107 assertTrue("Should be a default model parser", 108 MVCRegistry.lookupModelParser(MVCConstants.DEFAULT_NAME) != null && 109 MVCRegistry.lookupModelParser(MVCConstants.DEFAULT_NAME) instanceof 110 DefaultModelParser); 111 assertTrue("Should be action flow model handler", 112 MVCRegistry.lookupModelHandler(MVCConstants.ACTIONFLOW_NAME) != null && 113 MVCRegistry.lookupModelHandler(MVCConstants.ACTIONFLOW_NAME) instanceof 114 DefaultModelHandler); 115 assertTrue("Should be action flow model resolver", 116 MVCRegistry.lookupModelResolver(MVCConstants.ACTIONFLOW_NAME) != null && 117 MVCRegistry.lookupModelResolver(MVCConstants.ACTIONFLOW_NAME) instanceof 118 ActionFlowModelResolver); 119 assertTrue("Should be a form model handler", 120 MVCRegistry.lookupModelHandler(MVCConstants.FORM_NAME) != null && 121 MVCRegistry.lookupModelHandler(MVCConstants.FORM_NAME) instanceof 122 DefaultModelHandler); 123 assertTrue("Should be a form model resolver", 124 MVCRegistry.lookupModelResolver(MVCConstants.FORM_NAME) != null && 125 MVCRegistry.lookupModelResolver(MVCConstants.FORM_NAME) instanceof 126 FormModelResolver); 127 assertTrue("Should be a repository model handler", 128 MVCRegistry.lookupModelHandler(MVCConstants.REPOSITORY_NAME) != null && 129 MVCRegistry.lookupModelHandler(MVCConstants.REPOSITORY_NAME) instanceof 130 RepositoryModelHandler); 131 assertTrue("Should be a repository model resolver", 132 MVCRegistry.lookupModelResolver(MVCConstants.REPOSITORY_NAME) != null && 133 MVCRegistry.lookupModelResolver(MVCConstants.REPOSITORY_NAME) instanceof 134 RepositoryModelResolver); 135 assertTrue("Should be a web model handler", 136 MVCRegistry.lookupModelHandler(MVCConstants.WEB_NAME) != null && 137 MVCRegistry.lookupModelHandler(MVCConstants.WEB_NAME) instanceof 138 WebModelHandler); 139 assertTrue("Should be a web model resolver", 140 MVCRegistry.lookupModelResolver(MVCConstants.WEB_NAME) != null && 141 MVCRegistry.lookupModelResolver(MVCConstants.WEB_NAME) instanceof 142 WebModelResolver); 143 144 assertTrue("Should be a validator parser", 145 MVCRegistry.lookupValidatorParser(MVCConstants.DEFAULT_NAME) != null && 146 MVCRegistry.lookupValidatorParser(MVCConstants.DEFAULT_NAME) instanceof 147 DefaultValidatorParser); 148 assertTrue("Should be a action flow validator handler", 149 MVCRegistry.lookupValidatorHandler(MVCConstants.ACTIONFLOW_NAME) != null && 150 MVCRegistry.lookupValidatorHandler(MVCConstants.ACTIONFLOW_NAME) instanceof 151 ActionFlowValidatorHandler); 152 assertTrue("Should be a form validator handler", 153 MVCRegistry.lookupValidatorHandler(MVCConstants.FORM_NAME) != null && 154 MVCRegistry.lookupValidatorHandler(MVCConstants.FORM_NAME) instanceof 155 FormValidatorHandler); 156 } 157 } | Popular Tags |