1 17 18 package org.sape.carbon.services.config.jar.test; 19 20 import org.sape.carbon.core.config.Config; 21 import org.sape.carbon.core.config.ConfigurationException; 22 import org.sape.carbon.core.config.node.ConfigurationDocument; 23 import org.sape.carbon.core.config.node.Folder; 24 import org.sape.carbon.core.config.test.InternalNodeTest; 25 26 import junit.extensions.ActiveTestSuite; 27 import junit.framework.Test; 28 import junit.framework.TestSuite; 29 30 37 public class InternalJarNodeTest extends InternalNodeTest { 38 private static final String JAR_NODE_NAME = 39 "/jar_config/test/JarNodeTest"; 40 private static final String THREAD_TEST_NODE_NAME1 = 41 "TestNode1"; 42 private static final String THREAD_TEST_NODE_NAME2 = 43 "TestNode2"; 44 private static final String THREAD_LINK_TEST_NODE_NAME = 45 "TestNode3"; 46 private static final String LINK_TARGET_NAME = 47 "TestNode3Target"; 48 49 53 public InternalJarNodeTest(String name) { 54 super(name); 55 } 56 57 60 protected void setUp() throws Exception { 61 super.root = (Folder) Config.getInstance(). 62 fetchNode(InternalJarNodeTest.JAR_NODE_NAME); 63 } 64 65 public void testThreadedRelativeLink() { 66 try { 67 testSetAndGetAttribute((ConfigurationDocument) 68 super.root.fetchChild(THREAD_LINK_TEST_NODE_NAME)); 69 } catch (ConfigurationException ce) { 70 fail("caught ConfigurationException: " + ce); 71 } 72 } 73 74 public void testThreadedAccess1() { 75 try { 76 testSetAndGetAttribute((ConfigurationDocument) 77 super.root.fetchChild(THREAD_TEST_NODE_NAME1)); 78 } catch (ConfigurationException ce) { 79 fail("caught ConfigurationException: " + ce); 80 } 81 } 82 83 public void testThreadedAccess2() { 84 try { 85 testSetAndGetAttribute((ConfigurationDocument) 86 super.root.fetchChild(THREAD_TEST_NODE_NAME2)); 87 } catch (ConfigurationException ce) { 88 fail("caught ConfigurationException: " + ce); 89 } 90 } 91 92 private void testSetAndGetAttribute(ConfigurationDocument doc) 93 throws ConfigurationException { 94 95 for (int i=0; i<5; i++) { 96 TestJarConfiguration config = (TestJarConfiguration) 97 doc.readConfiguration(); 98 99 int newValue = config.getValue(); 100 config.setValue(newValue); 101 doc.writeConfiguration(config); 102 config = (TestJarConfiguration) doc.readConfiguration(); 103 104 if (config.getValue() != newValue) { 105 fail("value within config was not the expected value, expected [" 106 + newValue 107 + "], actual [" + config.getValue() + "]"); 108 } 109 } 110 } 111 112 116 public static Test suite() { 117 TestSuite masterSuite = new TestSuite(); 118 Test singleThreadedTests = getSingleThreadedTests(); 120 if (singleThreadedTests != null) { 121 masterSuite.addTest(singleThreadedTests); 122 } 123 Test multiThreadedTests = getMultiThreadedTests(); 125 if (multiThreadedTests != null) { 126 masterSuite.addTest(multiThreadedTests); 127 } 128 return masterSuite; 129 } 130 131 137 private static Test getSingleThreadedTests() { 138 TestSuite suite = new TestSuite(); 139 140 suite.addTest(new InternalJarNodeTest("testAddSubFolder")); 141 suite.addTest(new InternalJarNodeTest("testAddConfigurationDocument")); 142 suite.addTest(new InternalJarNodeTest("testWriteConfiguration")); 143 suite.addTest(new InternalJarNodeTest("testReadConfiguration")); 144 suite.addTest(new InternalJarNodeTest("testNodeAttributes")); 145 suite.addTest(new InternalJarNodeTest("testFetchChildren")); 146 suite.addTest( 147 new InternalJarNodeTest("testAddDuplicateConfigurationDocument")); 148 suite.addTest(new InternalJarNodeTest("testAddDuplicateSubFolder")); 149 suite.addTest(new InternalJarNodeTest("testAddNestedConfiguration")); 150 suite.addTest(new InternalJarNodeTest("testReadNestedConfiguration")); 151 suite.addTest(new InternalJarNodeTest("testRemoveNestedConfiguration")); 152 suite.addTest(new InternalJarNodeTest("testNodeRemoval")); 153 suite.addTest(new InternalJarNodeTest("testFetchRemovedNode")); 154 suite.addTest(new InternalJarNodeTest("testNullParameters")); 155 suite.addTest(new InternalJarNodeTest("testLinkFolder")); 156 suite.addTest(new InternalJarNodeTest("testLinkDoc")); 157 158 return suite; 159 } 160 161 166 private static Test getMultiThreadedTests() { 167 TestSuite suite = new ActiveTestSuite(); 168 169 175 addTest(suite, "testThreadedRelativeLink", 1); 176 addTest(suite, "testThreadedAccess1", 1); 177 addTest(suite, "testThreadedAccess2", 1); 178 179 return suite; 180 } 181 182 190 private static void addTest(TestSuite suite, String testName, int number) { 191 for (int count = 0; count < number; count++) { 192 suite.addTest(new InternalJarNodeTest(testName)); 193 } 194 } 195 198 protected String getTestNodeAttributesAbsoluteName() { 199 return JAR_NODE_NAME + super.getTestNodeAttributesAbsoluteName(); 200 } 201 202 } 203 | Popular Tags |