KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > aj > AspectJTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.spring.aj;
5
6 import com.tc.test.TestConfigObject;
7 import com.tctest.spring.integrationtests.framework.AbstractDeploymentTest;
8 import com.tctest.spring.integrationtests.framework.Deployment;
9 import com.tctest.spring.integrationtests.framework.DeploymentBuilder;
10 import com.tctest.spring.integrationtests.framework.Server;
11 import com.tctest.spring.integrationtests.framework.WebApplicationServer;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17
18 public class AspectJTest extends AbstractDeploymentTest {
19
20   private static final String JavaDoc REMOTE_SERVICE_NAME = "InstrumentedBean";
21
22   private Deployment deployment;
23   private String JavaDoc context = "test-aspectj";
24
25   public AspectJTest() {
26     this.disableVariant(TestConfigObject.SPRING_VARIANT, "128");
27   }
28   
29   protected void setUp() throws Exception JavaDoc {
30     super.setUp();
31
32     DeploymentBuilder builder = makeDeploymentBuilder(context+".war");
33     
34     builder.addRemoteService(REMOTE_SERVICE_NAME, "instrumentedBean", IInstrumentedBean.class);
35     
36     builder.addDirectoryOrJARContainingClass(IInstrumentedBean.class);
37     builder.addDirectoryOrJARContainingClass(org.aspectj.lang.Aspects.class);
38     // builder.addDirectoryOrJARContainingClassOfSelectedVersion(org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect.class, new String[] {TestConfigObject.SPRING_VARIANT}); // spring advices
39

40     builder.addBeanDefinitionFile("classpath:/com/tctest/spring/aj/beanfactory-aspectj.xml");
41     builder.addDirectoryContainingResource("/tc-config-files/aspectj-tc-config.xml");
42     
43     deployment = builder.makeDeployment();
44   }
45
46   public void testSingleton2() throws Exception JavaDoc {
47     List JavaDoc<WebApplicationServer> servers = new ArrayList JavaDoc<WebApplicationServer>();
48
49     int nodeCount = 2;
50     for (int i = 0; i < nodeCount; i++) {
51       WebApplicationServer server = makeWebApplicationServer("/tc-config-files/aspectj-tc-config.xml");
52       server.addWarDeployment(deployment, context);
53       server.start();
54       servers.add(server);
55     }
56
57     // ((WebApplicationServer) servers.get(0)).ping("/"+context);
58

59     for (Iterator JavaDoc it1 = servers.iterator(); it1.hasNext();) {
60       WebApplicationServer server1 = (WebApplicationServer) it1.next();
61       for(Iterator JavaDoc it2 = servers.iterator(); it2.hasNext();) {
62         WebApplicationServer server2 = (WebApplicationServer) it2.next();
63         if(server1==server2) continue;
64
65         assertShared(server1, server2, REMOTE_SERVICE_NAME);
66         assertTransient(server1, server2, REMOTE_SERVICE_NAME);
67       }
68     }
69   }
70
71   
72   private static void assertShared(Server server1, Server server2, String JavaDoc remoteServiceName) throws Exception JavaDoc {
73     IInstrumentedBean bean1 = (IInstrumentedBean) server1.getProxy(IInstrumentedBean.class, remoteServiceName);
74     IInstrumentedBean bean2 = (IInstrumentedBean) server2.getProxy(IInstrumentedBean.class, remoteServiceName);
75
76     assertEquals("1", bean1.getProperty1());
77     assertEquals("2", bean1.getProperty2());
78     
79     assertEquals(bean1.getValue(), bean2.getValue());
80     
81     bean1.setValue("AA1"+System.currentTimeMillis());
82     assertEquals("Should be shared", bean1.getValue(), bean2.getValue());
83     
84     bean2.setValue("AA2"+System.currentTimeMillis());
85     assertEquals("Should be shared", bean2.getValue(), bean1.getValue());
86   }
87   
88   private static void assertTransient(Server server1, Server server2, String JavaDoc remoteServiceName) throws Exception JavaDoc {
89     IInstrumentedBean bean1 = (IInstrumentedBean) server1.getProxy(IInstrumentedBean.class, remoteServiceName);
90     IInstrumentedBean bean2 = (IInstrumentedBean) server2.getProxy(IInstrumentedBean.class, remoteServiceName);
91     
92     String JavaDoc originalValue = "aaa";
93     assertEquals(originalValue, bean1.getTransientValue());
94     assertEquals(originalValue, bean2.getTransientValue());
95     
96     bean1.setTransientValue("s1");
97     assertEquals(originalValue, bean2.getTransientValue());
98     
99     bean2.setTransientValue("s2");
100     assertEquals("s1", bean1.getTransientValue());
101     assertEquals("s2", bean2.getTransientValue());
102
103     bean1.setTransientValue(originalValue);
104     bean2.setTransientValue(originalValue);
105   }
106
107 // public StandardTerracottaAppServerConfig buildTCConfig() {
108
// StandardTerracottaAppServerConfig tcConfigBuilder = getConfigBuilder();
109
// SpringConfigBuilder springConfigBuilder = tcConfigBuilder.getConfigBuilder().getApplication().getSpring();
110
// SpringApplicationConfigBuilder application = springConfigBuilder.getApplications()[ 0];
111
// application.setName("test-singleton");
112
// SpringApplicationContextConfigBuilder applicationContext = application.getApplicationContexts()[ 0];
113
// applicationContext.setPaths(new String[] { "*.xml"});
114
// applicationContext.addBean("singleton");
115
// tcConfigBuilder.build();
116
// logger.debug(tcConfigBuilder.toString());
117
// return tcConfigBuilder;
118
// }
119

120 }
121
Popular Tags