001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest.spring.integrationtests.tests;
005:
006: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
007: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
008: import com.tctest.spring.bean.CounterSaver;
009: import com.tctest.spring.bean.ISingleton;
010: import com.tctest.spring.bean.ISingletonAdvice;
011: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
012:
013: import junit.extensions.TestSetup;
014: import junit.framework.Test;
015:
016: /**
017: * Testing the following features
018: * 1. Introduction and pointcut advices retain the original semantics
019: * 2. Introduction and pointcut advices are also shared
020: *
021: * @author Liyu Yi
022: */
023: public class AdviceClusteringTest extends
024: AbstractTwoServerDeploymentTest {
025:
026: private static final String PC_SERVICE_NAME = "SingletonAdvice";
027: private static final String IN_SERVICE_NAME = "CounterSaver";
028: private static final String SINGLETON_SERVICE_NAME = "Singlton";
029: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-aop.xml";
030: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/aop-tc-config.xml";
031:
032: private ISingleton singletonWithPC1;
033: private ISingleton singletonWithPC2;
034: private CounterSaver counterSaver1;
035: private CounterSaver counterSaver2;
036: private ISingletonAdvice pcAdvice1;
037: private ISingletonAdvice pcAdvice2;
038:
039: protected void setUp() throws Exception {
040: super .setUp();
041:
042: singletonWithPC1 = (ISingleton) server0.getProxy(
043: ISingleton.class, SINGLETON_SERVICE_NAME);
044: singletonWithPC2 = (ISingleton) server1.getProxy(
045: ISingleton.class, SINGLETON_SERVICE_NAME);
046: counterSaver1 = (CounterSaver) server0.getProxy(
047: CounterSaver.class, IN_SERVICE_NAME);
048: counterSaver2 = (CounterSaver) server1.getProxy(
049: CounterSaver.class, IN_SERVICE_NAME);
050: pcAdvice1 = (ISingletonAdvice) server0.getProxy(
051: ISingletonAdvice.class, PC_SERVICE_NAME);
052: pcAdvice2 = (ISingletonAdvice) server1.getProxy(
053: ISingletonAdvice.class, PC_SERVICE_NAME);
054: }
055:
056: public void testAdviceClustering() throws Exception {
057: logger.debug("testing shared aspects");
058:
059: int singletonCnt1 = singletonWithPC1.getCounter(); // advice counter increased
060: int singletonCnt2 = singletonWithPC2.getCounter(); // advice counter increased
061:
062: assertEquals("Pre-condition not met for singletonCnt1", 0,
063: singletonCnt1);
064: assertEquals("Pre-condition not met for singletonCnt2", 0,
065: singletonCnt2);
066: assertEquals("Pre-condition not met for counterSaver1", 0,
067: counterSaver1.getSavedCounter());
068: assertEquals("Pre-condition not met for counterSaver2", 0,
069: counterSaver2.getSavedCounter());
070:
071: // check pointcut advice sharing
072: int adviceCnt1 = pcAdvice1.getCounter();
073: int adviceCnt2 = pcAdvice2.getCounter();
074: assertEquals("PointCut advice is not working for pcAdvice1", 2,
075: adviceCnt1);
076: assertEquals("PointCut advice is not working for pcAdvice2", 2,
077: adviceCnt2);
078:
079: // check bean sharing
080: singletonWithPC1.incrementCounter(); // is shared
081: assertEquals("Shared bean is not working for singletonWithPC2",
082: 1, singletonWithPC2.getCounter());
083:
084: // check introduction sharing
085: counterSaver2.saveCounter(); // saved counter is shared; both saved counter should be set
086: assertEquals(
087: "Shared introduction is not working for singletonWithPC2",
088: 1, counterSaver2.getSavedCounter());
089:
090: logger.debug("!!!! Asserts passed !!!");
091: }
092:
093: private static class AdviceClusteringTestSetup extends
094: SpringTwoServerTestSetup {
095: private AdviceClusteringTestSetup() {
096: super (AdviceClusteringTest.class, CONFIG_FILE_FOR_TEST,
097: "test-adviceclustering");
098: }
099:
100: protected void configureWar(DeploymentBuilder builder) {
101: builder
102: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
103: builder.addRemoteService(IN_SERVICE_NAME,
104: "singletonWithCounterSaver", CounterSaver.class);
105: builder.addRemoteService(PC_SERVICE_NAME,
106: "singletonAdvice", ISingletonAdvice.class);
107: builder.addRemoteService(SINGLETON_SERVICE_NAME,
108: "singletonWithGetCounter", ISingleton.class);
109: }
110: }
111:
112: /**
113: * JUnit test loader entry point
114: */
115: public static Test suite() {
116: TestSetup setup = new AdviceClusteringTestSetup();
117: return setup;
118: }
119:
120: }
|