001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest.server.appserver.unit;
006:
007: import net.sf.ehcache.Cache;
008: import net.sf.jsr107cache.CacheListener;
009:
010: import org.apache.commons.logging.LogFactory;
011: import org.apache.derby.drda.NetworkServerControl;
012: import org.apache.log4j.Logger;
013:
014: import com.meterware.httpunit.WebConversation;
015: import com.meterware.httpunit.WebResponse;
016: import com.tc.test.server.appserver.AppServerFactory;
017: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
018: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
019: import com.tc.test.server.appserver.deployment.WebApplicationServer;
020: import com.tc.test.server.util.TcConfigBuilder;
021: import com.tc.util.TIMUtil;
022: import com.tctest.webapp.servlets.ContainerHibernateTestServlet;
023:
024: import java.io.PrintWriter;
025: import java.util.Date;
026:
027: import junit.framework.Test;
028:
029: public class ContainerHibernateTest extends
030: AbstractTwoServerDeploymentTest {
031: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/hibernate-tc-config.xml";
032:
033: public static Test suite() {
034: return new ContainerHibernateTestSetup();
035: }
036:
037: public ContainerHibernateTest() {
038: if (shouldDisable()) {
039: disableAllUntil(new Date(Long.MAX_VALUE));
040: }
041: }
042:
043: public boolean shouldDisable() {
044: // MNK-287
045: int id = AppServerFactory.getCurrentAppServerId();
046: boolean wasceOrWebSphere = (id == AppServerFactory.WASCE || id == AppServerFactory.WEBSPHERE);
047: return super .shouldDisable() || wasceOrWebSphere;
048: }
049:
050: public void testHibernate() throws Exception {
051: WebConversation conversation = new WebConversation();
052:
053: WebResponse response1 = request(server0, "server=server0",
054: conversation);
055: assertEquals("OK", response1.getText().trim());
056:
057: WebResponse response2 = request(server1, "server=server1",
058: conversation);
059: assertEquals("OK", response2.getText().trim());
060: }
061:
062: private WebResponse request(WebApplicationServer server,
063: String params, WebConversation con) throws Exception {
064: return server.ping("/events/ContainerHibernateTestServlet?"
065: + params, con);
066: }
067:
068: private static class ContainerHibernateTestSetup extends
069: TwoServerTestSetup {
070: private NetworkServerControl derbyServer;
071:
072: private ContainerHibernateTestSetup() {
073: super (ContainerHibernateTest.class, CONFIG_FILE_FOR_TEST,
074: "events");
075: }
076:
077: protected void configureWar(DeploymentBuilder builder) {
078: builder
079: .addDirectoryOrJARContainingClass(org.hibernate.SessionFactory.class); // hibernate*.jar
080: builder
081: .addDirectoryOrJARContainingClass(org.dom4j.Node.class); // domj4*.jar
082: builder
083: .addDirectoryOrJARContainingClass(net.sf.cglib.core.ClassInfo.class); // cglib-nodep*.jar
084: builder
085: .addDirectoryOrJARContainingClass(javax.transaction.Transaction.class); // jta*.jar
086: builder
087: .addDirectoryOrJARContainingClass(org.apache.commons.collections.Buffer.class); //
088: builder
089: .addDirectoryOrJARContainingClass(org.apache.derby.jdbc.ClientDriver.class); // derby*.jar
090: builder.addDirectoryOrJARContainingClass(antlr.Tool.class); // antlr*.jar
091: builder.addDirectoryOrJARContainingClass(Cache.class); // ehcache-1.3.0.jar
092: builder
093: .addDirectoryOrJARContainingClass(CacheListener.class); // jsr107cache-1.0.jar
094:
095: if (AppServerFactory.getCurrentAppServerId() != AppServerFactory.JBOSS) {
096: builder.addDirectoryOrJARContainingClass(Logger.class); // log4j
097: builder
098: .addDirectoryOrJARContainingClass(LogFactory.class); // common-loggings
099: }
100:
101: builder.addResource("/com/tctest/server/appserver/unit",
102: "hibernate.cfg.xml", "WEB-INF/classes");
103: builder.addResource("/com/tctest/server/appserver/unit",
104: "ehcache13.xml", "WEB-INF/classes");
105: builder.addResource("/com/tctest/server/appserver/unit",
106: "Event.hbm.xml", "WEB-INF/classes");
107: builder.addResource("/com/tctest/server/appserver/unit",
108: "Person.hbm.xml", "WEB-INF/classes");
109: builder.addResource("/com/tctest/server/appserver/unit",
110: "PhoneNumber.hbm.xml", "WEB-INF/classes");
111: builder.addResource("/com/tctest/server/appserver/unit",
112: "Account.hbm.xml", "WEB-INF/classes");
113:
114: builder
115: .addResource(
116: "/com/tctest/server/appserver/unit/containerhibernatetest",
117: "jboss-web.xml", "WEB-INF");
118:
119: builder.addServlet("ContainerHibernateTestServlet",
120: "/ContainerHibernateTestServlet/*",
121: ContainerHibernateTestServlet.class, null, true);
122: }
123:
124: protected void configureTcConfig(TcConfigBuilder clientConfig) {
125: clientConfig.addModule(TIMUtil.EHCACHE_1_3, TIMUtil
126: .getVersion(TIMUtil.EHCACHE_1_3));
127: clientConfig.addModule(TIMUtil.HIBERNATE_3_1_2, TIMUtil
128: .getVersion(TIMUtil.HIBERNATE_3_1_2));
129: }
130:
131: public void setUp() throws Exception {
132: derbyServer = new NetworkServerControl();
133: derbyServer.start(new PrintWriter(System.out));
134: int tries = 0;
135: while (tries < 5) {
136: try {
137: Thread.sleep(500);
138: derbyServer.ping();
139: break;
140: } catch (Exception e) {
141: tries++;
142: }
143: }
144: if (tries == 5) {
145: throw new Exception("Failed to start Derby!");
146: }
147:
148: super .setUp();
149: }
150:
151: public void tearDown() throws Exception {
152: super.tearDown();
153: derbyServer.shutdown();
154: }
155:
156: }
157: }
|