mirror of
https://github.com/Alfresco/alfresco-sdk.git
synced 2025-05-19 17:15:24 +00:00
Add integration-test module as a dependency for the platform war and include it to allow remote execution
This commit is contained in:
parent
85c7e11bb6
commit
24500024ed
@ -31,6 +31,21 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
|
<!-- Make sure we attach the tests so we can include them when running -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>test-jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<!-- Filter the test resource files in the IT project, and do property substitutions.
|
<!-- Filter the test resource files in the IT project, and do property substitutions.
|
||||||
We need this config so this is done before the Alfresco Maven Plugin 'it' is executed. -->
|
We need this config so this is done before the Alfresco Maven Plugin 'it' is executed. -->
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -103,15 +118,6 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<phase>pre-integration-test</phase>
|
<phase>pre-integration-test</phase>
|
||||||
</execution>
|
</execution>
|
||||||
<!-- No need to call a shutdown mojo, it shuts down after the tests finishes
|
|
||||||
<execution>
|
|
||||||
<id>stop-alfresco</id>
|
|
||||||
<goals>
|
|
||||||
<goal>shutdown</goal>
|
|
||||||
</goals>
|
|
||||||
<phase>post-integration-test</phase>
|
|
||||||
</execution>
|
|
||||||
-->
|
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -307,6 +307,15 @@
|
|||||||
<artifactId>${artifactId}-platform-jar</artifactId>
|
<artifactId>${artifactId}-platform-jar</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</moduleDependency>
|
</moduleDependency>
|
||||||
|
|
||||||
|
<!-- Bring in the integration tests -->
|
||||||
|
<moduleDependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>integration-tests</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
</moduleDependency>
|
||||||
|
|
||||||
</platformModules>
|
</platformModules>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
@ -21,6 +21,11 @@ import org.alfresco.maven.plugin.config.ModuleDependency;
|
|||||||
import org.alfresco.maven.plugin.config.TomcatDependency;
|
import org.alfresco.maven.plugin.config.TomcatDependency;
|
||||||
import org.alfresco.maven.plugin.config.TomcatWebapp;
|
import org.alfresco.maven.plugin.config.TomcatWebapp;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.net.telnet.TelnetClient;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
@ -33,6 +38,10 @@ import org.codehaus.plexus.util.FileUtils;
|
|||||||
import org.zeroturnaround.zip.ZipUtil;
|
import org.zeroturnaround.zip.ZipUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -272,7 +281,7 @@ public abstract class AbstractRunMojo extends AbstractMojo {
|
|||||||
/**
|
/**
|
||||||
* Legacy to be compatible with maven.tomcat.port
|
* Legacy to be compatible with maven.tomcat.port
|
||||||
*/
|
*/
|
||||||
@Parameter(property = "maven.tomcat.port", defaultValue = "8080")
|
@Parameter(property = "maven.tomcat.port", defaultValue = "")
|
||||||
protected String mavenTomcatPort;
|
protected String mavenTomcatPort;
|
||||||
|
|
||||||
|
|
||||||
@ -345,7 +354,7 @@ public abstract class AbstractRunMojo extends AbstractMojo {
|
|||||||
*/
|
*/
|
||||||
protected String getPort() {
|
protected String getPort() {
|
||||||
String port = tomcatPort;
|
String port = tomcatPort;
|
||||||
if (mavenTomcatPort.toString() != tomcatPort.toString()) {
|
if (mavenTomcatPort != null) {
|
||||||
port = mavenTomcatPort;
|
port = mavenTomcatPort;
|
||||||
getLog().info( "Tomcat Port overridden by property maven.tomcat.port");
|
getLog().info( "Tomcat Port overridden by property maven.tomcat.port");
|
||||||
}
|
}
|
||||||
@ -353,6 +362,28 @@ public abstract class AbstractRunMojo extends AbstractMojo {
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected boolean tomcatIsRunning() {
|
||||||
|
|
||||||
|
CloseableHttpClient client= HttpClients.createDefault();
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpGet httpget = new HttpGet("http://localhost:" + getPort() + "/alfresco");
|
||||||
|
response = client.execute(httpget);
|
||||||
|
getLog().info("Tomcat is running on port "+ getPort());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
getLog().info("Tomcat is not running on port " + getPort() );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Download and unpack the Solr 4 configuration as we don't have it in the project.
|
* Download and unpack the Solr 4 configuration as we don't have it in the project.
|
||||||
* It will reside under /alf_data_dev/solr
|
* It will reside under /alf_data_dev/solr
|
||||||
@ -877,6 +908,7 @@ public abstract class AbstractRunMojo extends AbstractMojo {
|
|||||||
element(name("groupId"), moduleDep.getGroupId()),
|
element(name("groupId"), moduleDep.getGroupId()),
|
||||||
element(name("artifactId"), moduleDep.getArtifactId()),
|
element(name("artifactId"), moduleDep.getArtifactId()),
|
||||||
element(name("version"), moduleDep.getVersion()),
|
element(name("version"), moduleDep.getVersion()),
|
||||||
|
element(name("classifier"), moduleDep.getClassifier()),
|
||||||
element(name("type"), moduleDep.getType()),
|
element(name("type"), moduleDep.getType()),
|
||||||
element(name("overWrite"), "true"));
|
element(name("overWrite"), "true"));
|
||||||
|
|
||||||
@ -1143,7 +1175,7 @@ public abstract class AbstractRunMojo extends AbstractMojo {
|
|||||||
|
|
||||||
// Set up the system properties that should be set for Tomcat
|
// Set up the system properties that should be set for Tomcat
|
||||||
ArrayList systemProps = new ArrayList<Element>();
|
ArrayList systemProps = new ArrayList<Element>();
|
||||||
systemProps.add(element(name("java.io.tmpdir"), "${project.build.directory}"));
|
systemProps.add(element(name("java.io.tmpdir"), "${project.build.directory}/tmp"));
|
||||||
if (enableSolr) {
|
if (enableSolr) {
|
||||||
systemProps.add(element(name("solr.solr.home"), solrHome));
|
systemProps.add(element(name("solr.solr.home"), solrHome));
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,8 @@ public class IntegrationTestMojo extends AbstractRunMojo {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// execEnv.getMavenSession().getGoals().add("alfresco:it");
|
|
||||||
|
|
||||||
getLog().info("Checking if Tomcat is already running on port " + "");
|
getLog().info("Checking if Tomcat is already running on port " + "");
|
||||||
|
if ( ! tomcatIsRunning() ) {
|
||||||
|
|
||||||
if (enableSolr) {
|
if (enableSolr) {
|
||||||
unpackSolrConfig();
|
unpackSolrConfig();
|
||||||
@ -105,18 +104,6 @@ public class IntegrationTestMojo extends AbstractRunMojo {
|
|||||||
"alfresco-rad",
|
"alfresco-rad",
|
||||||
"${alfresco.sdk.version}",
|
"${alfresco.sdk.version}",
|
||||||
ModuleDependency.TYPE_JAR));
|
ModuleDependency.TYPE_JAR));
|
||||||
|
|
||||||
// Create a JAR with all tests and add to module dependencies for platform WAR
|
|
||||||
// So we can run tests on the server
|
|
||||||
// TODO: remove different approach at the moment with separate integration-tests module copyTestClassesFromSubModules2Parent();
|
|
||||||
// TODO: remove testJarArtifactId = packageAndInstallTestsJar();
|
|
||||||
// TODO: remove platformModules.add(
|
|
||||||
// TODO: new ModuleDependency(
|
|
||||||
// TODO: project.getGroupId(),
|
|
||||||
// TODO: testJarArtifactId,
|
|
||||||
// TODO: project.getVersion(),
|
|
||||||
// TODO: ModuleDependency.TYPE_JAR));
|
|
||||||
// Now build the platform WAR
|
|
||||||
buildPlatformWar();
|
buildPlatformWar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,167 +118,9 @@ public class IntegrationTestMojo extends AbstractRunMojo {
|
|||||||
if (startTomcat) {
|
if (startTomcat) {
|
||||||
boolean fork = true;
|
boolean fork = true;
|
||||||
startTomcat(fork);
|
startTomcat(fork);
|
||||||
// TODO: remove different approach at the moment with separate integration-tests module runIntegrationTests(testJarArtifactId);
|
|
||||||
// TODO: remove stopTomcat();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* In an AIO project copy all integration test (IT) test-classes from sub projects/modules
|
|
||||||
* to the parent target/test-classes
|
|
||||||
*
|
|
||||||
* @throws MojoExecutionException
|
|
||||||
*/
|
|
||||||
protected void copyTestClassesFromSubModules2Parent() throws MojoExecutionException {
|
|
||||||
// Get sub-module names, so we can see where to copy test classes from
|
|
||||||
List<String> childModules = project.getModules();
|
|
||||||
if (childModules == null || childModules.size() <= 0) {
|
|
||||||
// Running in a single JAR module, nothing to copy,
|
|
||||||
// all test classes are already in top level target/test-classes
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String module : childModules) {
|
|
||||||
getLog().info("Copying integration test-classes (*IT.class) from module '" + module +
|
|
||||||
"' to parent target/test-classes");
|
|
||||||
|
|
||||||
executeMojo(
|
|
||||||
plugin(
|
|
||||||
groupId("org.apache.maven.plugins"),
|
|
||||||
artifactId("maven-resources-plugin"),
|
|
||||||
version(MAVEN_RESOURCE_PLUGIN_VERSION)
|
|
||||||
),
|
|
||||||
goal("copy-resources"),
|
|
||||||
configuration(
|
|
||||||
element(name("outputDirectory"), "${project.build.testOutputDirectory}"),
|
|
||||||
element(name("resources"),
|
|
||||||
element(name("resource"),
|
|
||||||
element(name("directory"), module + "/target/test-classes"),
|
|
||||||
element(name("includes"),
|
|
||||||
element(name("include"), "**/*.class")
|
|
||||||
),
|
|
||||||
element(name("filtering"), "false")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
execEnv
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Package all IT Tests in JAR file and install it in local maven repo.
|
|
||||||
*
|
|
||||||
* @return the customized JAR file artifactId, to be used by the failsafe plugin
|
|
||||||
* @throws MojoExecutionException
|
|
||||||
*/
|
|
||||||
protected String packageAndInstallTestsJar() throws MojoExecutionException {
|
|
||||||
final String jarArtifactId = project.getArtifactId() + "-IT-classes";
|
|
||||||
|
|
||||||
// Package the JAR file with all the Integration Tests (IT)
|
|
||||||
// Note. don't use the maven-war-plugin here as it will package the module files twice, once from the
|
|
||||||
// target/classes dir and once via the JAR
|
|
||||||
final String jarPath = project.getBuild().getDirectory() + "/" + jarArtifactId + ".jar";
|
|
||||||
final String jarSourceDir = project.getBuild().getDirectory() + "/test-classes";
|
|
||||||
|
|
||||||
ZipUtil.pack(new File(jarSourceDir), new File(jarPath));
|
|
||||||
|
|
||||||
getLog().info("Installing integration test JAR into local Maven repo.");
|
|
||||||
|
|
||||||
// Install the Test JAR file in the local maven repo
|
|
||||||
executeMojo(
|
|
||||||
plugin(
|
|
||||||
groupId("org.apache.maven.plugins"),
|
|
||||||
artifactId("maven-install-plugin"),
|
|
||||||
version(MAVEN_INSTALL_PLUGIN_VERSION)
|
|
||||||
),
|
|
||||||
goal("install-file"),
|
|
||||||
configuration(
|
|
||||||
element(name("file"), jarPath),
|
|
||||||
element(name("groupId"), "${project.groupId}"),
|
|
||||||
element(name("artifactId"), jarArtifactId),
|
|
||||||
element(name("version"), "${project.version}"),
|
|
||||||
element(name("packaging"), "jar") // Don't forget, otherwise installed as .POM
|
|
||||||
)
|
|
||||||
, execEnv
|
|
||||||
);
|
|
||||||
|
|
||||||
return jarArtifactId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run all IT tests contained in JAR with passed in artifact ID. Group ID and Version will be the same
|
|
||||||
* as the project.
|
|
||||||
*
|
|
||||||
* @param testJarArtifactId
|
|
||||||
* @throws MojoExecutionException
|
|
||||||
*/
|
|
||||||
protected void runIntegrationTests(String testJarArtifactId) throws MojoExecutionException {
|
|
||||||
getLog().info("Executing integration tests (*IT.class)...");
|
|
||||||
|
|
||||||
// JUnit runner
|
|
||||||
List<Dependency> failsafePluginDependencies = new ArrayList<Dependency>();
|
|
||||||
failsafePluginDependencies.add(dependency("org.apache.maven.surefire", "surefire-junit47", "2.19.1"));
|
|
||||||
|
|
||||||
// Add dependencies to classes under test
|
|
||||||
List<Element> classpathElements = new ArrayList<>();
|
|
||||||
List<String> childModules = project.getModules();
|
|
||||||
if (childModules != null && childModules.size() > 0) {
|
|
||||||
// Get sub-module names, so we can see what libs to include
|
|
||||||
for (String module : childModules) {
|
|
||||||
String classpathElement = project.getBasedir() + "/" + module + "/target/" + module + "-1.0-SNAPSHOT.jar";
|
|
||||||
getLog().info("Adding module '" + classpathElement + "' to test classpath");
|
|
||||||
classpathElements.add(element(name("additionalClasspathElement"), classpathElement));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute Failsafe Mojo
|
|
||||||
Plugin failsafePlugin = plugin(
|
|
||||||
groupId("org.apache.maven.plugins"),
|
|
||||||
artifactId("maven-failsafe-plugin"),
|
|
||||||
version("2.19.1"),
|
|
||||||
failsafePluginDependencies
|
|
||||||
);
|
|
||||||
getLog().info("Start executing failsafe Mojo...");
|
|
||||||
|
|
||||||
// This might be ugly, the MojoExecuter will only accept Element[] and we need this list to be dynamic
|
|
||||||
// to avoid NPEs. If there's a better way to do this, then feel free to change it!
|
|
||||||
Element[] classpathElementArray = new Element[classpathElements.size()];
|
|
||||||
classpathElements.toArray(classpathElementArray);
|
|
||||||
|
|
||||||
executeMojo(failsafePlugin,
|
|
||||||
goal("integration-test"),
|
|
||||||
configuration(
|
|
||||||
element(name("includes"),
|
|
||||||
element(name("include"), "**/*IT.class")
|
|
||||||
),
|
|
||||||
element(name("additionalClasspathElements"),
|
|
||||||
classpathElementArray
|
|
||||||
),
|
|
||||||
// IT Test dependency to scan
|
|
||||||
element(name("dependenciesToScan"),
|
|
||||||
element(name("dependency"), project.getGroupId() + ":" + testJarArtifactId)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
execEnv
|
|
||||||
);
|
|
||||||
|
|
||||||
getLog().info("Stopped executing failsafe Mojo");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void stopTomcat() throws MojoExecutionException {
|
|
||||||
getLog().info("Stopping Tomcat...");
|
|
||||||
|
|
||||||
Plugin tomcatPlugin = plugin(
|
|
||||||
groupId("org.apache.tomcat.maven"),
|
|
||||||
artifactId("tomcat7-maven-plugin"),
|
|
||||||
version(MAVEN_TOMCAT7_PLUGIN_VERSION)
|
|
||||||
);
|
|
||||||
|
|
||||||
executeMojo(tomcatPlugin,
|
|
||||||
goal("shutdown") ,
|
|
||||||
configuration(),
|
|
||||||
execEnv
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -29,6 +29,7 @@ public abstract class MavenDependency {
|
|||||||
private String groupId;
|
private String groupId;
|
||||||
private String artifactId;
|
private String artifactId;
|
||||||
private String version;
|
private String version;
|
||||||
|
private String classifier;
|
||||||
|
|
||||||
public MavenDependency() {}
|
public MavenDependency() {}
|
||||||
|
|
||||||
@ -38,6 +39,14 @@ public abstract class MavenDependency {
|
|||||||
this.version = v;
|
this.version = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MavenDependency(String g, String a, String v, String c) {
|
||||||
|
this.groupId = g;
|
||||||
|
this.artifactId = a;
|
||||||
|
this.version = v;
|
||||||
|
this.classifier = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
@ -54,14 +63,20 @@ public abstract class MavenDependency {
|
|||||||
this.artifactId = artifactId;
|
this.artifactId = artifactId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() { return version; }
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(String version) {
|
public void setVersion(String version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getClassifier() {
|
||||||
|
return classifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassifier(String c) { this.classifier = c; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
@ -71,6 +86,7 @@ public abstract class MavenDependency {
|
|||||||
|
|
||||||
if (!groupId.equals(that.groupId)) return false;
|
if (!groupId.equals(that.groupId)) return false;
|
||||||
if (!artifactId.equals(that.artifactId)) return false;
|
if (!artifactId.equals(that.artifactId)) return false;
|
||||||
|
if (!classifier.equals(that.classifier)) return false;
|
||||||
return version.equals(that.version);
|
return version.equals(that.version);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user