001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.config;
005:
006: import org.apache.xmlbeans.XmlException;
007: import org.apache.xmlbeans.XmlOptions;
008: import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
009:
010: import com.tc.config.Loader;
011: import com.tc.config.schema.setup.ConfigurationSetupException;
012: import com.tc.logging.NullTCLogger;
013: import com.tc.logging.TCLogger;
014: import com.terracottatech.config.Application;
015: import com.terracottatech.config.TcConfigDocument;
016: import com.terracottatech.config.TcConfigDocument.TcConfig;
017:
018: import java.io.IOException;
019: import java.lang.reflect.InvocationHandler;
020: import java.lang.reflect.Method;
021: import java.lang.reflect.Proxy;
022: import java.util.ArrayList;
023:
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: public class ConfigLoaderTest extends TestCase {
028:
029: private final String configName;
030:
031: public ConfigLoaderTest(String configName) {
032: super ("test");
033: this .configName = configName;
034: }
035:
036: public void test() throws XmlException, IOException,
037: ConfigurationSetupException {
038: ArrayList errors = new ArrayList();
039:
040: TcConfigDocument tcConfigDocument = new Loader().parse(
041: getClass().getResourceAsStream(configName), //
042: new XmlOptions().setLoadLineNumbers()
043: .setValidateOnSet());
044: TcConfig tcConfig = tcConfigDocument.getTcConfig();
045: Application application = tcConfig.getApplication();
046:
047: if (application != null) {
048: TCLogger logger = new NullTCLogger();
049:
050: DSOClientConfigHelper config = (DSOClientConfigHelper) Proxy
051: .newProxyInstance(
052: getClass().getClassLoader(),
053: new Class[] { DSOClientConfigHelper.class },
054: new InvocationHandler() {
055: public Object invoke(Object proxy,
056: Method method, Object[] args)
057: throws Throwable {
058: return null;
059: }
060: });
061:
062: ConfigLoader loader = new ConfigLoader(config, logger);
063: try {
064: loader.loadDsoConfig(application.getDso());
065: loader.loadSpringConfig(application.getSpring());
066: } catch (XmlValueOutOfRangeException e) {
067: fail(e.getMessage());
068: }
069:
070: assertTrue("Parsing errors: " + errors.toString(), errors
071: .isEmpty());
072: }
073: }
074:
075: public String getName() {
076: return super .getName() + " : " + configName;
077: }
078:
079: public static TestSuite suite() {
080: TestSuite suite = new TestSuite(ConfigLoaderTest.class
081: .getName());
082:
083: // this to make sure backward compatibility with terracotta-4.xsd
084: // update tc-config-reference.xml if this test fail or there's change to
085: // terracotta-4.xsd (upgrade version, etc)
086: suite.addTest(new ConfigLoaderTest("tc-config-reference.xml"));
087:
088: suite.addTest(new ConfigLoaderTest("empty-tc-config.xml"));
089: suite.addTest(new ConfigLoaderTest("tc-config-dso.xml"));
090: suite.addTest(new ConfigLoaderTest("tc-config-chatter.xml"));
091: suite
092: .addTest(new ConfigLoaderTest(
093: "tc-config-coordination.xml"));
094: suite.addTest(new ConfigLoaderTest("tc-config-inventory.xml"));
095:
096: suite.addTest(new ConfigLoaderTest("tc-config-jtable.xml"));
097: suite.addTest(new ConfigLoaderTest("tc-config-l2.xml"));
098: suite.addTest(new ConfigLoaderTest(
099: "tc-config-scoordination.xml"));
100: suite.addTest(new ConfigLoaderTest("tc-config-sevents.xml"));
101: suite
102: .addTest(new ConfigLoaderTest(
103: "tc-config-sharededitor.xml"));
104: suite
105: .addTest(new ConfigLoaderTest(
106: "tc-config-sharedqueue.xml"));
107: suite.addTest(new ConfigLoaderTest("tc-config-sjmx.xml"));
108: suite.addTest(new ConfigLoaderTest("tc-config-swebflow.xml"));
109:
110: suite.addTest(new ConfigLoaderTest(
111: "anothersingleton-tc-config.xml"));
112: suite.addTest(new ConfigLoaderTest("aop-tc-config.xml"));
113: suite.addTest(new ConfigLoaderTest(
114: "app-ctx-matching-tc-config.xml"));
115: suite.addTest(new ConfigLoaderTest("appctxdef-tc-config.xml"));
116: suite
117: .addTest(new ConfigLoaderTest(
118: "customscoped-tc-config.xml"));
119: suite.addTest(new ConfigLoaderTest("empty-tc-config.xml"));
120: suite.addTest(new ConfigLoaderTest("event-tc-config.xml"));
121: suite.addTest(new ConfigLoaderTest("hibernate-tc-config.xml"));
122: suite.addTest(new ConfigLoaderTest("init2-tc-config.xml"));
123: suite.addTest(new ConfigLoaderTest(
124: "interceptor-via-postprocessor-tc-config.xml"));
125: suite.addTest(new ConfigLoaderTest("lifecycle-tc-config.xml"));
126: suite
127: .addTest(new ConfigLoaderTest(
128: "multibeandef-tc-config.xml"));
129: suite
130: .addTest(new ConfigLoaderTest(
131: "multicontext-tc-config.xml"));
132: suite.addTest(new ConfigLoaderTest(
133: "multifile-context-tc-config.xml"));
134: suite
135: .addTest(new ConfigLoaderTest(
136: "parent-child-tc-config.xml"));
137: suite
138: .addTest(new ConfigLoaderTest(
139: "proxiedbean-tc-config.xml"));
140: suite
141: .addTest(new ConfigLoaderTest(
142: "redeployment-tc-config.xml"));
143: suite.addTest(new ConfigLoaderTest(
144: "referenceandreplication-tc-config.xml"));
145: suite
146: .addTest(new ConfigLoaderTest(
147: "scopedbeans-tc-config.xml"));
148: suite.addTest(new ConfigLoaderTest("sellitem-tc-config.xml"));
149: suite.addTest(new ConfigLoaderTest(
150: "sessionscoped-tc-config.xml"));
151: suite.addTest(new ConfigLoaderTest("sharedlock-tc-config.xml"));
152: suite.addTest(new ConfigLoaderTest(
153: "singleton-parent-child-tc-config.xml"));
154: suite.addTest(new ConfigLoaderTest(
155: "thread-coordination-tc-config.xml"));
156: suite.addTest(new ConfigLoaderTest("webflow-tc-config.xml"));
157:
158: return suite;
159: }
160:
161: }
|