01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring;
05:
06: import org.springframework.context.support.ClassPathXmlApplicationContext;
07:
08: import com.tc.object.config.ConfigVisitor;
09: import com.tc.object.config.DSOClientConfigHelper;
10: import com.tc.object.config.DSOSpringConfigHelper;
11: import com.tc.object.config.StandardDSOSpringConfigHelper;
12: import com.tc.simulator.app.ApplicationConfig;
13: import com.tc.simulator.listener.ListenerProvider;
14: import com.tc.util.runtime.Vm;
15: import com.tctest.TransparentTestBase;
16: import com.tctest.runner.AbstractTransparentApp;
17: import com.tctest.spring.bean.FooService;
18:
19: import java.util.Date;
20:
21: /**
22: * Spring singleton test
23: */
24: public class SingletonWithInterceptor_Test extends TransparentTestBase {
25: private static final int LOOP_ITERATIONS = 1;
26: private static final int EXECUTION_COUNT = 1;
27: private static final int NODE_COUNT = 2;
28:
29: public SingletonWithInterceptor_Test() {
30: if (Vm.isIBM()) {
31: disableAllUntil(new Date(Long.MAX_VALUE));
32: }
33: }
34:
35: protected void setUp() throws Exception {
36: super .setUp();
37: getTransparentAppConfig().setClientCount(NODE_COUNT)
38: .setApplicationInstancePerClientCount(EXECUTION_COUNT)
39: .setIntensity(LOOP_ITERATIONS);
40: initializeTestRunner();
41: }
42:
43: protected Class getApplicationClass() {
44: return SingletonApp.class;
45: }
46:
47: public static class SingletonApp extends AbstractTransparentApp {
48: public SingletonApp(String appId, ApplicationConfig cfg,
49: ListenerProvider listenerProvider) {
50: super (appId, cfg, listenerProvider);
51: }
52:
53: public void run() {
54: Thread t = Thread.currentThread();
55: ClassLoader cl = t.getContextClassLoader();
56:
57: try {
58: t.setContextClassLoader(getClass().getClassLoader());
59:
60: ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext(
61: "com/tctest/spring/beanfactory-interceptor.xml");
62:
63: FooService singleton1 = (FooService) ctx1
64: .getBean("service");
65:
66: assertEquals("interceptorInvoked", singleton1
67: .serviceMethod());
68:
69: } catch (Throwable e) {
70: notifyError(e);
71:
72: } finally {
73: t.setContextClassLoader(cl);
74:
75: }
76: }
77:
78: public static void visitL1DSOConfig(ConfigVisitor visitor,
79: DSOClientConfigHelper config) {
80: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
81: springConfig
82: .addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); // app name used by testing
83: // framework
84: springConfig
85: .addConfigPattern("*/beanfactory-interceptor.xml");
86: springConfig.addBean("service");
87: config.addDSOSpringConfig(springConfig);
88:
89: // config.addIncludePattern("com.tctest.spring.bean.SimpleListener", true, true);
90: // config.addIncludePattern("com.tctest.spring.bean.FooServiceImpl", true, true);
91:
92: // config.addIsolatedClass("org.springframework.");
93: // config.addIsolatedClass("com.tctest.spring.");
94: // config.addIsolatedClass("com.tcspring.");
95: }
96:
97: }
98: }
|