1 4 package com.tctest.spring.integrationtests.framework; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 import java.util.Enumeration ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 import java.util.Map ; 13 14 import junit.framework.TestSuite; 15 16 17 public abstract class AbstractTwoServerDeploymentTest extends AbstractDeploymentTest { 18 19 public static WebApplicationServer server1; 20 public static WebApplicationServer server2; 21 22 23 protected static abstract class TwoSvrSetup extends ServerTestSetup { 24 25 Log logger = LogFactory.getLog(getClass()); 26 27 protected boolean shouldContinue = true; 28 29 private String tcConfigFile; 30 private String context; 31 private final Class testClass; 32 33 protected TwoSvrSetup(Class testClass, String tcConfigFile, String context) { 34 super(testClass); 35 this.testClass = testClass; 36 this.tcConfigFile = tcConfigFile; 37 this.context = context; 38 } 39 40 protected boolean shouldDisable() { 41 boolean rtv = false; 42 if (this.fTest instanceof TestSuite) { 43 for (Enumeration e=((TestSuite)fTest).tests(); e.hasMoreElements();) { 44 Object o = e.nextElement(); 45 if (o instanceof AbstractTwoServerDeploymentTest) { 46 AbstractTwoServerDeploymentTest t = (AbstractTwoServerDeploymentTest)o; 47 if (shouldDisableForJavaVersion(t) || shouldDisableForVariants(t)) { 48 rtv = true; 49 t.disableAllTests(); 50 } 51 } 52 } 53 } 54 return rtv; 55 } 56 57 boolean shouldDisableForVariants(AbstractTwoServerDeploymentTest t) { 58 for (Iterator iter=t.disabledVariants.entrySet().iterator(); iter.hasNext();) { 59 Map.Entry entry = (Map.Entry )iter.next(); 60 String variantName = (String )entry.getKey(); 61 List variants = (List )entry.getValue(); 62 String selected = this.sm.getTestConfig().selectedVariantFor(variantName); 63 if (variants.contains(selected)) { 64 logger.warn("Test " + t.getName() + " is disabled for " + variantName + " = " + selected ); 65 return true; 66 } 67 } 68 return false; 69 } 70 71 private boolean shouldDisableForJavaVersion(AbstractTwoServerDeploymentTest t) { 72 for (Iterator iter=t.disabledJavaVersion.iterator(); iter.hasNext();) { 73 String version = (String )iter.next(); 74 if (version.equals(System.getProperties().getProperty("java.version"))) { 75 logger.warn("Test " + t.getName() + " is disabled for " + version ); 76 return true; 77 } 78 } 79 return false; 80 } 81 82 protected void setUp() throws Exception { 83 super.setUp(); 84 85 if (shouldDisable()) { 86 this.shouldContinue = false; 87 } 88 89 setUpTwoWebAppServers(); 90 } 91 92 protected void setUpTwoWebAppServers() throws Exception { 93 long l1 = System.currentTimeMillis(); 94 Deployment warPath = makeWAR(); 95 long l2 = System.currentTimeMillis(); 96 logger.info("### WAR build "+ (l2-l1)/1000f + " at " + warPath.getFileSystemPath()); 97 98 server1 = sm.makeWebApplicationServer(tcConfigFile); 99 server1.addWarDeployment(warPath, context); 100 101 server2 = sm.makeWebApplicationServer(tcConfigFile); 102 server2.addWarDeployment(warPath, context); 103 104 server1.start(); 105 server2.start(); 106 } 107 108 private Deployment makeWAR() throws Exception { 109 DeploymentBuilder builder = super.makeDeploymentBuilder(this.context + ".war"); 110 builder.addDirectoryOrJARContainingClass(testClass); 111 builder.addDirectoryContainingResource(tcConfigFile); 112 configureWar(builder); 113 return builder.makeDeployment(); 114 } 115 116 protected abstract void configureWar(DeploymentBuilder builder); 117 } 118 119 } 120 | Popular Tags |