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.IMasterBean;
009: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
010:
011: import java.util.List;
012:
013: import junit.framework.Test;
014:
015: /**
016: * This is really testing a single WebApplicationContext with multiple bean definition files
017: * Testing the following features
018: * 1. proxy is correctly invoked
019: * 2. The shared bean is cached in the mixin cache
020: *
021: * @author Liyu Yi
022: */
023: public class MultipleBeanDefsTest extends
024: AbstractTwoServerDeploymentTest {
025:
026: private static final String REMOTE_SERVICE_NAME = "MasterService";
027: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml \n classpath:/com/tctest/spring/beanfactory-master.xml";
028: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/multibeandef-tc-config.xml";
029:
030: private IMasterBean masterBean1;
031: private IMasterBean masterBean2;
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: masterBean1 = (IMasterBean) server0.getProxy(IMasterBean.class,
036: REMOTE_SERVICE_NAME);
037: masterBean2 = (IMasterBean) server1.getProxy(IMasterBean.class,
038: REMOTE_SERVICE_NAME);
039: }
040:
041: /**
042: * Test regular shared bean behavior
043: */
044: public void testBeanFromMultipleContexts() throws Exception {
045: List values1 = masterBean1.getValues();
046: List values2 = masterBean2.getValues();
047:
048: assertEquals("Pre-condition checking failed" + values1, 0,
049: values1.size());
050: assertEquals("Pre-condition checking failed" + values2, 0,
051: values2.size());
052:
053: masterBean1.addValue("masterBean1");
054: masterBean2.addValue("masterBean2");
055:
056: values1 = masterBean1.getValues();
057: values2 = masterBean2.getValues();
058:
059: assertEquals("Not shared correctly" + values1, 2, values1
060: .size());
061: assertEquals("Not shared correctly" + values2, 2, values2
062: .size());
063:
064: assertTrue(values1.contains("masterBean1"));
065: assertTrue(values1.contains("masterBean2"));
066: assertTrue(values2.contains("masterBean1"));
067: assertTrue(values2.contains("masterBean2"));
068: }
069:
070: /**
071: *
072: */
073: public void testUsingSharedBeanReferenceAcrossCluster()
074: throws Exception {
075: assertTrue("After a round trip, failed the check for ==",
076: masterBean1.isTheSameSingletonReferenceUsed());
077: assertTrue("After a round trip, failed the check for ==",
078: masterBean2.isTheSameSingletonReferenceUsed());
079: }
080:
081: private static class MultipleBeanDefsTestSetup extends
082: SpringTwoServerTestSetup {
083:
084: private MultipleBeanDefsTestSetup() {
085: super (MultipleBeanDefsTest.class, CONFIG_FILE_FOR_TEST,
086: "test-multibeandef");
087: }
088:
089: protected void configureWar(DeploymentBuilder builder) {
090: builder
091: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
092: builder.addRemoteService(REMOTE_SERVICE_NAME,
093: "distributedMasterBean", IMasterBean.class);
094: }
095: }
096:
097: public static Test suite() {
098: return new MultipleBeanDefsTestSetup();
099: }
100:
101: }
|