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.tctest.spring.bean.DisposableService;
15:
16: /**
17: * Spring singleton test
18: */
19: public class DisposableBean_Test extends SimpleTransparentTestBase {
20:
21: public DisposableBean_Test() {
22: //
23: }
24:
25: protected int getNodeCount() {
26: return 1;
27: }
28:
29: protected Class getApplicationClass() {
30: return SingletonApp.class;
31: }
32:
33: public static class SingletonApp extends
34: AbstractSimpleTransparentApp {
35: public SingletonApp(String appId, ApplicationConfig cfg,
36: ListenerProvider listenerProvider) {
37: super (appId, cfg, listenerProvider);
38: }
39:
40: protected void doIt() {
41: ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext(
42:
43: "com/tctest/spring/beanfactory-disposable.xml");
44:
45: DisposableService singleton1 = (DisposableService) ctx1
46: .getBean("disposable");
47:
48: assertDistributed(ctx1, "disposable", singleton1);
49:
50: assertSame(singleton1,
51: DisposableService.afterPropertiesSetThis);
52:
53: assertEquals("disposable", singleton1.getName());
54:
55: assertNotNull(singleton1.getFoo());
56:
57: ctx1.close();
58:
59: // assertNull(singleton1.getName());
60: assertSame(singleton1, DisposableService.destroyThis);
61: }
62:
63: public static void visitL1DSOConfig(ConfigVisitor visitor,
64: DSOClientConfigHelper config) {
65: DSOSpringConfigHelper springConfig = new StandardDSOSpringConfigHelper();
66: springConfig
67: .addApplicationNamePattern(SpringTestConstants.APPLICATION_NAME); // app name used by testing framework
68: springConfig
69: .addConfigPattern("*/beanfactory-disposable.xml");
70: springConfig.addBean("disposable");
71:
72: config.addDSOSpringConfig(springConfig);
73:
74: config.addIncludePattern(
75: "com.tctest.spring.bean.SimpleListener", true,
76: true, false);
77: config.addIncludePattern(
78: "com.tctest.spring.bean.DisposableService", true,
79: true, false);
80:
81: }
82:
83: }
84: }
|