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 org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
007: import org.springframework.web.servlet.DispatcherServlet;
008:
009: import com.tc.test.server.HSqlDBServer;
010: import com.tc.test.server.appserver.deployment.AbstractDBServer;
011: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
012: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
013: import com.tc.test.server.appserver.deployment.ProxyBuilder;
014: import com.tctest.spring.bean.IHibernateBean;
015: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
016:
017: import java.util.HashMap;
018: import java.util.Map;
019:
020: import junit.framework.Test;
021:
022: /**
023: *
024: */
025: public class HibernateTest extends AbstractTwoServerDeploymentTest {
026: private static final String APP_NAME = "test-hibernate";
027: private static final String REMOTE_SERVICE_NAME = "hibernateservice";
028:
029: private IHibernateBean hibernateBean1;
030: private IHibernateBean hibernateBean2;
031:
032: public HibernateTest() {
033: super ();
034: disableAllUntil("2010-03-01");
035: // this.disableTestUntil("testLazyObj", "2010-03-01");
036: // this.disableTestUntil("testLazyChild", "2010-03-01");
037: }
038:
039: protected void setUp() throws Exception {
040: super .setUp();
041:
042: try {
043: Map initCtx = new HashMap();
044: initCtx.put(ProxyBuilder.EXPORTER_TYPE_KEY,
045: HttpInvokerServiceExporter.class);
046: String name = APP_NAME + "/http/" + REMOTE_SERVICE_NAME;
047: hibernateBean1 = (IHibernateBean) server0.getProxy(
048: IHibernateBean.class, name, initCtx);
049: hibernateBean2 = (IHibernateBean) server1.getProxy(
050: IHibernateBean.class, name, initCtx);
051:
052: } catch (Exception ex) {
053: ex.printStackTrace();
054: throw ex;
055: }
056: }
057:
058: public void testSharePersitentObj() throws Exception {
059: hibernateBean1.sharePersistentObj();
060: assertEquals("Failed to share persistent object",
061: hibernateBean1.getSharedId(), hibernateBean2
062: .getSharedId());
063: assertEquals("Failed to share persistent object",
064: hibernateBean1.getSharedFld(), hibernateBean2
065: .getSharedFld());
066: }
067:
068: public void testShareDetachedObj() throws Exception {
069: hibernateBean1.shareDetachedObj();
070: assertEquals("Failed to share detached object", hibernateBean1
071: .getSharedId(), hibernateBean2.getSharedId());
072: assertEquals("Failed to share detached object", hibernateBean1
073: .getSharedFld(), hibernateBean2.getSharedFld());
074: }
075:
076: public void testLazyObj() throws Exception {
077: hibernateBean1.shareLazyObj();
078: assertEquals("Failed to share lazy object", hibernateBean1
079: .getSharedId(), hibernateBean2.getSharedId());
080: assertEquals("Failed to share lazy object", hibernateBean1
081: .getSharedFld(), hibernateBean2.getSharedFld());
082: }
083:
084: public void testLazyChild() throws Exception {
085: hibernateBean1.shareObjWithLazyChild();
086: assertEquals("Failed to share lazy object", hibernateBean1
087: .getSharedId(), hibernateBean2.getSharedId());
088: assertEquals("Failed to share lazy object", hibernateBean1
089: .getSharedFld(), hibernateBean2.getSharedFld());
090: }
091:
092: public void testAssociateDetachedObject() throws Exception {
093: hibernateBean1.sharePersistentObj();
094: hibernateBean2.associateSharedObj();
095:
096: assertEquals("Failed to share lazy object", hibernateBean1
097: .getSharedId(), hibernateBean2.getSharedId());
098: assertEquals("Failed to share lazy object", hibernateBean1
099: .getSharedFld(), hibernateBean2.getSharedFld());
100:
101: hibernateBean1.shareDetachedObj();
102: hibernateBean2.associateSharedObj();
103:
104: assertEquals("Failed to share lazy object", hibernateBean1
105: .getSharedId(), hibernateBean2.getSharedId());
106: assertEquals("Failed to share lazy object", hibernateBean1
107: .getSharedFld(), hibernateBean2.getSharedFld());
108: }
109:
110: private static class HibernateTestSetup extends
111: SpringTwoServerTestSetup {
112: private static final int DB_PORT = 0; // will use the default port - 9001
113: private static final String DB_NAME = "testdb";
114:
115: private HibernateTestSetup() {
116: super (HibernateTest.class,
117: "/tc-config-files/hibernate-tc-config.xml",
118: APP_NAME);
119: }
120:
121: protected void setUp() throws Exception {
122: super .setUp();
123:
124: if (shouldDisable())
125: return;
126:
127: try {
128: // sm = ServerManagerUtil.startAndBind(HibernateTest.class, isWithPersistentStore());
129:
130: // AbstractDBServer dbSvr = sm.makeDBServer("HSQL", DB_NAME, DB_PORT);
131: AbstractDBServer dbSvr = new HSqlDBServer(DB_NAME,
132: DB_PORT);
133: getServerManager().addServerToStop(dbSvr);
134: dbSvr.start();
135:
136: } catch (Exception ex) {
137: ex.printStackTrace();
138: throw ex;
139: }
140: }
141:
142: protected void configureWar(DeploymentBuilder builder) {
143: builder
144: .addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory-hibernate.xml");
145: builder.addRemoteService(HttpInvokerServiceExporter.class,
146: REMOTE_SERVICE_NAME, "hibernate-bean",
147: IHibernateBean.class);
148: builder.setDispatcherServlet("httpinvoker", "/http/*",
149: DispatcherServlet.class, null, true);
150: builder
151: .addDirectoryOrJARContainingClass(org.hibernate.Session.class);
152: builder
153: .addDirectoryOrJARContainingClass(org.dom4j.DocumentException.class);
154: //builder.addDirectoryOrJARContainingClass(org.apache.xerces.jaxp.SAXParserFactoryImpl.class);
155: builder
156: .addDirectoryOrJARContainingClass(org.hsqldb.jdbcDriver.class);
157: builder
158: .addDirectoryOrJARContainingClass(net.sf.ehcache.CacheException.class);
159: builder
160: .addDirectoryOrJARContainingClass(net.sf.cglib.beans.BulkBeanException.class);
161: builder
162: .addDirectoryOrJARContainingClass(org.apache.commons.dbcp.BasicDataSource.class);
163: builder
164: .addDirectoryOrJARContainingClass(org.apache.commons.pool.impl.GenericObjectPool.class);
165: builder
166: .addDirectoryOrJARContainingClass(org.apache.commons.collections.SequencedHashMap.class);
167: // builder.addDirectoryOrJARContainingClass(com.tc.aspectwerkz.exception.WrappedRuntimeException.class);
168: // builder.addDirectoryOrJARContainingClass(org.xml.sax.ext.Attributes2.class);
169: }
170: }
171:
172: public static Test suite() {
173: return new HibernateTestSetup();
174: }
175:
176: }
|