1 7 package com.inversoft.verge.mvc.controller.actionflow.config.test; 8 9 10 import org.jdom.Element; 11 12 import com.inversoft.config.ConfigurationException; 13 import com.inversoft.junit.WebTestCase; 14 import com.inversoft.verge.mvc.controller.actionflow.config.BaseNamespace; 15 import com.inversoft.verge.mvc.controller.actionflow.config.Constants; 16 import com.inversoft.verge.mvc.controller.actionflow.config.DefaultTypes; 17 import com.inversoft.verge.mvc.controller.actionflow.config.PresentationNode; 18 import com.inversoft.verge.mvc.controller.actionflow.config.PresentationNodeBuilder; 19 20 21 28 public class PresentationNodeBuilderTest extends WebTestCase { 29 30 33 public PresentationNodeBuilderTest(String name) { 34 super(name); 35 setLocal(true); 36 } 37 38 41 public void testSimple() { 42 43 BaseNamespace namespace = new BaseNamespace("test", DefaultTypes.NAMESPACE); 44 Element element = new Element("node"); 45 element.setAttribute(Constants.NAME_ATTRIBUTE, "/test/myFile.jsp"); 46 element.setAttribute(Constants.TYPE_ATTRIBUTE, "presentation"); 47 48 PresentationNodeBuilder builder = new PresentationNodeBuilder(); 49 try { 50 PresentationNode config = 51 (PresentationNode) builder.build(namespace, element); 52 assertTrue("Name should be /test/myFile.jsp", 53 config.getName().equals("/test/myFile.jsp")); 54 assertTrue("type should be presentation", 55 config.getType().equals("presentation")); 56 assertTrue("path should be /test/", config.getPath().equals("/test/")); 57 assertTrue("filename should be myFile.jsp", config.getFileName().equals("myFile.jsp")); 58 assertEquals("URL should be /test/myFile.jsp", "/test/myFile.jsp", config.getURL()); 59 assertTrue("Should not be exit", !config.isExitPoint()); 60 assertTrue("Should not be default", !config.isDefaultEntry()); 61 } catch (ConfigurationException ce) { 62 fail(ce.toString()); 63 } 64 } 65 66 69 public void testFailure() { 70 71 BaseNamespace namespace = new BaseNamespace("test", DefaultTypes.NAMESPACE); 72 Element element = new Element("node"); 73 element.setAttribute(Constants.TYPE_ATTRIBUTE, "presentation"); 75 76 PresentationNodeBuilder builder = new PresentationNodeBuilder(); 77 try { 78 builder.build(namespace, element); 79 fail("Should have failed because no name"); 80 } catch (ConfigurationException ce) { 81 assertTrue("Should have errors", ce.getErrors() != null && 82 ce.getErrors().isEmpty() == false); 83 } 84 85 element = new Element("node"); 86 element.setAttribute(Constants.NAME_ATTRIBUTE, "/test/myFile.jsp"); 87 element.setAttribute(Constants.TYPE_ATTRIBUTE, "presentation"); 88 element.setAttribute(Constants.EXIT_ATTRIBUTE, "bob"); 89 90 try { 91 builder.build(namespace, element); 92 fail("Should have failed exit is bob"); 93 } catch (ConfigurationException ce) { 94 assertTrue("Should have errors", ce.getErrors() != null && 95 ce.getErrors().isEmpty() == false); 96 } 97 98 element = new Element("node"); 99 element.setAttribute(Constants.NAME_ATTRIBUTE, "/test/myFile.jsp"); 100 element.setAttribute(Constants.TYPE_ATTRIBUTE, "presentation"); 101 element.setAttribute(Constants.DEFAULT_ATTRIBUTE, "bob"); 102 103 try { 104 builder.build(namespace, element); 105 fail("Should have failed default is bob"); 106 } catch (ConfigurationException ce) { 107 assertTrue("Should have errors", ce.getErrors() != null && 108 ce.getErrors().isEmpty() == false); 109 } 110 111 element = new Element("node"); 112 element.setAttribute(Constants.NAME_ATTRIBUTE, "/test/"); 113 element.setAttribute(Constants.TYPE_ATTRIBUTE, "presentation"); 114 115 try { 116 builder.build(namespace, element); 117 fail("Should have failed because mane is invalid"); 118 } catch (ConfigurationException ce) { 119 assertTrue("Should have errors", ce.getErrors() != null && 120 ce.getErrors().isEmpty() == false); 121 } 122 } 123 124 127 public void testComplete() { 128 129 BaseNamespace namespace = new BaseNamespace("test", DefaultTypes.NAMESPACE); 130 Element element = new Element("node"); 131 element.setAttribute(Constants.NAME_ATTRIBUTE, "/test/myFile.jsp"); 132 element.setAttribute(Constants.TYPE_ATTRIBUTE, "presentation"); 133 element.setAttribute(Constants.EXIT_ATTRIBUTE, "true"); 134 element.setAttribute(Constants.DEFAULT_ATTRIBUTE, "true"); 135 136 PresentationNodeBuilder builder = new PresentationNodeBuilder(); 137 try { 138 PresentationNode config = 139 (PresentationNode) builder.build(namespace, element); 140 assertTrue("Name should be /test/myFile.jsp", 141 config.getName().equals("/test/myFile.jsp")); 142 assertTrue("type should be presentation", 143 config.getType().equals("presentation")); 144 assertTrue("path should be /test/", config.getPath().equals("/test/")); 145 assertTrue("filename should be myFile.jsp", 146 config.getFileName().equals("myFile.jsp")); 147 assertTrue("Should be exit", config.isExitPoint()); 148 assertTrue("Should be default", config.isDefaultEntry()); 149 } catch (ConfigurationException ce) { 150 fail(ce.toString()); 151 } 152 153 element.removeAttribute("type"); 155 try { 156 builder.build(namespace, element); 157 fail("Should have failed because name and type are null"); 158 } catch (ConfigurationException be) { 159 assertTrue("Should have one error at least", !be.getErrors().isEmpty()); 160 System.out.println(be.toString()); 161 } 162 } 163 } | Popular Tags |