1 package org.apache.commons.betwixt.scarab; 2 3 18 19 import java.io.FileInputStream ; 20 import java.io.StringWriter ; 21 import java.io.Writer ; 22 import java.util.List ; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 import junit.textui.TestRunner; 27 28 import org.apache.commons.betwixt.AbstractTestCase; 29 import org.apache.commons.betwixt.XMLIntrospector; 30 import org.apache.commons.betwixt.io.BeanReader; 31 import org.apache.commons.betwixt.io.BeanWriter; 32 import org.apache.commons.betwixt.strategy.HyphenatedNameMapper; 33 34 40 public class TestScarabSettings extends AbstractTestCase 41 { 42 public static void main( String [] args ) 43 { 44 TestRunner.run( suite() ); 45 } 46 47 50 public static Test suite() 51 { 52 return new TestSuite(TestScarabSettings.class); 53 } 54 55 60 public TestScarabSettings(String testName) 61 { 62 super(testName); 63 } 64 65 69 public void testRoundTrip() 70 throws Exception 71 { 72 BeanReader reader = createBeanReader(); 73 74 ScarabSettings ss = (ScarabSettings) reader.parse( 75 new FileInputStream (getTestFile("src/test/org/apache/commons/betwixt/scarab/scarab-settings.xml"))); 76 77 StringWriter buffer = new StringWriter (); 79 write(ss, buffer); 80 81 reader = createBeanReader(); 83 84 String text = buffer.toString(); 86 87 System.out.println(text); 88 89 95 testScarabSettings(ss); 96 97 } 99 100 101 104 107 protected BeanReader createBeanReader() 108 throws Exception 109 { 110 BeanReader reader = new BeanReader(); 111 reader.setXMLIntrospector(createXMLIntrospector()); 112 reader.registerBeanClass(ScarabSettings.class); 113 return reader; 114 } 115 116 121 protected XMLIntrospector createXMLIntrospector() 122 { 123 XMLIntrospector introspector = new XMLIntrospector(); 124 125 introspector.getConfiguration().setAttributesForPrimitives(false); 127 128 131 introspector.getConfiguration().setElementNameMapper(new HyphenatedNameMapper()); 133 134 return introspector; 135 } 136 137 140 protected void testScarabSettings(ScarabSettings ss) 141 throws Exception 142 { 143 List globalAttributes = ss.getGlobalAttributes(); 144 GlobalAttribute ga = (GlobalAttribute) globalAttributes.get(1); 145 assertEquals("Functional area", ga.getName()); 146 147 List globalAttributeOptions = ga.getGlobalAttributeOptions(); 148 149 System.out.println( "GlobalAttribute: " + ga); 150 System.out.println( "globalAttributeOptions: " + globalAttributeOptions); 151 152 assertEquals(ga.getCreatedDate().getTimestamp(), "2002-05-31 13:29:27.0"); 153 154 assertEquals(globalAttributeOptions.size(), 2); 155 GlobalAttributeOption gao = (GlobalAttributeOption) globalAttributeOptions.get(0); 156 assertEquals("UI", gao.getChildOption()); 157 gao = (GlobalAttributeOption) globalAttributeOptions.get(1); 158 assertEquals("Code", gao.getChildOption()); 159 160 List globalIssueTypes = ss.getGlobalIssueTypes(); 161 GlobalIssueType git = (GlobalIssueType) globalIssueTypes.get(0); 162 assertEquals("Defect", git.getName()); 163 164 List modules = ss.getModules(); 165 Module m = (Module) modules.get(0); 166 assertEquals("Source", m.getName()); 167 } 168 169 172 protected void write(Object bean, Writer out) 173 throws Exception 174 { 175 BeanWriter writer = new BeanWriter(out); 176 writer.setXMLIntrospector(createXMLIntrospector()); 177 writer.enablePrettyPrint(); 178 writer.write(bean); 179 } 180 } 181 182 | Popular Tags |