1 64 65 package com.jcorporate.expresso.kernel.management.test; 66 67 import com.jcorporate.expresso.kernel.RootContainerInterface; 68 import com.jcorporate.expresso.kernel.SystemFactory; 69 import com.jcorporate.expresso.kernel.exception.ConfigurationException; 70 import com.jcorporate.expresso.kernel.management.DefaultServiceWriter; 71 import junit.framework.TestCase; 72 73 import java.io.File ; 74 75 78 public class TestServiceWriter extends TestCase { 79 80 public TestServiceWriter(String _name) { 81 super(_name); 82 } 83 84 RootContainerInterface globalContainer = null; 85 86 89 protected void setUp() { 90 try { 91 globalContainer = SystemFactory.buildExpressoComponentSystem( 92 this.getClass().getResource("Test1ExpressoServices.xml"), 93 this.getClass().getResource("TestLog4jConfig.xml"), 94 "D:/Expresso/log"); 95 } catch (ConfigurationException ex) { 96 ex.printStackTrace(); 97 throw new IllegalStateException ("Error setting up test case: " + ex.getMessage()); 98 } 99 100 } 101 102 105 protected void tearDown() { 106 globalContainer.destroy(); 107 globalContainer = null; 108 System.gc(); 109 System.runFinalization(); 110 } 111 112 public void testXercesSaveConfiguration() { 113 runTestSaveConfig(com.jcorporate.expresso.kernel.management.XercesDOMWriter.class.getName()); 114 } 115 116 public void testTRAXSaveConfiguration() { 117 runTestSaveConfig(com.jcorporate.expresso.kernel.management.TraxDOMWriter.class.getName()); 118 } 119 120 protected void runTestSaveConfig(String domWriterClass) { 121 try { 122 DefaultServiceWriter sw = new DefaultServiceWriter(); 123 sw.setDomWriterClass(domWriterClass); 124 125 sw.writeServicesFile(globalContainer, "d:/expresso/log/testOut.xml"); 126 127 File f = new File ("d:/expresso/log/testOut.xml"); 128 if (f == null) { 129 fail("testOut.xml wasn't created"); 130 } 131 132 RootContainerInterface testContainer = 133 SystemFactory.buildExpressoComponentSystem(f.toURL(), 134 this.getClass().getResource("TestLog4jConfig.xml"), 135 "D:/Expresso/log"); 136 137 assertTrue("Test containers should be equal", 138 testContainer.getExpressoServicesConfig().equals(globalContainer.getExpressoServicesConfig())); 139 } catch (Exception ex) { 140 ex.printStackTrace(); 141 fail("Exception thrown during test: " + ex.getMessage()); 142 } 143 144 } 145 146 147 150 public static void main(String [] argv) { 151 String [] testCaseList = {TestServiceWriter.class.getName()}; 152 junit.textui.TestRunner.main(testCaseList); 153 } 154 } 155 | Popular Tags |