Archetypes - Integration tests verifier approach

New approach for the execution of the ITs for the archetypes. It uses the
maven verifier component to generate the project from the archetype and
afterwards execute the required goal/s and check the results.

This approach works properly in windows in contrast to the default archetypes
ITs mechanism, which failed executing the runner script.
This commit is contained in:
Jose Luis Osorno 2018-12-26 11:19:11 +01:00
parent 7bf16b467b
commit 97f0ea6119
7 changed files with 288 additions and 22 deletions

View File

@ -40,7 +40,7 @@
<acs.debug.port>8888</acs.debug.port>
<postgres.port>5555</postgres.port>
<!-- This parameter is only required for those cases in which ACS is not exposed in http://localhost:8080/alfresco (i.e. Windows Docker) -->
<test.acs.endpoint.path></test.acs.endpoint.path>
<test.acs.endpoint.path>@@test.acs.endpoint.path@@</test.acs.endpoint.path>
</properties>

View File

@ -1,19 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.alfresco.maven.archetype</groupId>
<artifactId>archetypes-it</artifactId>
<packaging>maven-archetype</packaging>
<name>Alfresco SDK - All-in-One Archetype</name>
<description>Sample multi-module project for All-in-One development on the Alfresco platform. Includes modules for Platform/Repository JAR and Share JAR</description>
<groupId>org.alfresco.maven.archetype</groupId>
<artifactId>archetypes-it</artifactId>
<packaging>jar</packaging>
<name>Archetypes IT</name>
<description>Archetypes Integration Tests</description>
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-aggregator</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-aggregator</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
@ -26,9 +27,35 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Runs the integration tests, any class that follows naming convention
"**/IT*.java", "**/*IT.java", and "**/*ITCase.java" will be considered an integration test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify-test</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,13 +1,17 @@
package org.alfresco.maven.archetype.allinone;
package org.alfresco.maven.archetype;
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
/**
* Exposes the core functionality required to generate a new project from an archetype and execute some of the goals of the runner scripts.
*
* @author Jose Luis Osorno <joseluis.osorno@ixxus.com>
*/
public abstract class AbstractArchetypeIT {
protected static final File ROOT = new File("target/test-classes/");
@ -26,14 +30,23 @@ public abstract class AbstractArchetypeIT {
Verifier verifier = new Verifier(ROOT.getAbsolutePath());
// Deleting a former created artifact from the archetype to be tested
verifier.deleteArtifact(archetypeProperties.getProjectGroupId(), archetypeProperties.getProjectArtifactId(), archetypeProperties.getProjectVersion(), null);
verifier.deleteArtifact(archetypeProperties.getProjectGroupId(), archetypeProperties.getProjectArtifactId(), archetypeProperties.getProjectVersion(),
null);
// Delete the created maven project
verifier.deleteDirectory(archetypeProperties.getProjectArtifactId());
}
/**
* Create the {@link ArchetypeProperties} object with the details of the archetype to use and the project to generate in the test.
*
* @return the {@link ArchetypeProperties} object with the details of the archetype to use and the project to generate in the test
*/
protected abstract ArchetypeProperties createArchetypeProperties();
protected void generateProject() throws Exception {
/**
* Generate a new project from an archetype and verify the generation was successful.
*/
protected void generateProjectFromArchetype() throws Exception {
Verifier verifier = new Verifier(ROOT.getAbsolutePath());
verifier.setSystemProperties(archetypeProperties.getSystemProperties());
verifier.setAutoclean(false);
@ -41,8 +54,14 @@ public abstract class AbstractArchetypeIT {
verifier.verifyErrorFreeLog();
}
protected ProcessBuilder getProcessBuilder() {
ProcessBuilder pb = new ProcessBuilder(getCommand(),"build_test");
/**
* Generate a {@link ProcessBuilder} with the project runner script to execute an specific goal.
*
* @param goalToExecute the goal to be executed in the {@link ProcessBuilder}
* @return the generated {@link ProcessBuilder}
*/
protected ProcessBuilder getProcessBuilder(final String goalToExecute) {
ProcessBuilder pb = new ProcessBuilder(getCommand(), goalToExecute);
pb.directory(new File(projectPath));
pb.redirectOutput(new File(projectPath + File.separator + LOG_FILENAME));
pb.redirectError(new File(projectPath + File.separator + ERROR_FILENAME));
@ -50,6 +69,6 @@ public abstract class AbstractArchetypeIT {
}
private String getCommand() {
return projectPath + File.separator + (System.getProperty( "os.name" ).startsWith( "Windows" ) ? WINDOWS_EXEC : LINUX_EXEC);
return projectPath + File.separator + (System.getProperty("os.name").startsWith("Windows") ? WINDOWS_EXEC : LINUX_EXEC);
}
}

View File

@ -0,0 +1,39 @@
package org.alfresco.maven.archetype;
import org.apache.maven.it.Verifier;
import org.junit.Test;
/**
* Integration tests for the all-in-one archetype.
*/
public class AllInOneArchetypeIT extends AbstractArchetypeIT {
@Override
protected ArchetypeProperties createArchetypeProperties() {
return ArchetypeProperties.builder()
.withArchetypeGroupId("org.alfresco.maven.archetype")
.withArchetypeArtifactId("alfresco-allinone-archetype")
.withArchetypeVersion("4.0.0-SNAPSHOT")
.withProjectGroupId("archetype.it")
.withProjectArtifactId("allinone-test-run")
.withProjectVersion("0.1-SNAPSHOT")
.build();
}
@Test
public void whenGenerateProjectFromArchetypeThenAProperProjectIsCreated() throws Exception {
generateProjectFromArchetype();
// Since creating the archetype was successful, we now want to actually build the generated project executing the integration tests
ProcessBuilder pb = getProcessBuilder("build_test");
pb.start().waitFor();
// Verify the execution of the integration tests of the project were successful
Verifier verifier = new Verifier(projectPath);
verifier.setAutoclean(false);
verifier.setLogFileName(LOG_FILENAME);
verifier.verifyErrorFreeLog();
verifier.verifyTextInLog("Tests run: 5, Failures: 0, Errors: 0, Skipped: 0");
}
}

View File

@ -0,0 +1,115 @@
package org.alfresco.maven.archetype;
import java.util.Properties;
/**
* Represent the properties of a project generation execution from a maven archetype.
*
* @author Jose Luis Osorno <joseluis.osorno@ixxus.com>
*/
public class ArchetypeProperties {
private final String archetypeGroupId;
private final String archetypeArtifactId;
private final String archetypeVersion;
private final String projectGroupId;
private final String projectArtifactId;
private final String projectVersion;
private ArchetypeProperties(String archetypeGroupId, String archetypeArtifactId, String archetypeVersion, String projectGroupId,
String projectArtifactId, String projectVersion) {
this.archetypeGroupId = archetypeGroupId;
this.archetypeArtifactId = archetypeArtifactId;
this.archetypeVersion = archetypeVersion;
this.projectGroupId = projectGroupId;
this.projectArtifactId = projectArtifactId;
this.projectVersion = projectVersion;
}
public static ArchetypePropertiesBuilder builder() {
return new ArchetypePropertiesBuilder();
}
public Properties getSystemProperties() {
Properties props = new Properties(System.getProperties());
props.put("archetypeGroupId", archetypeGroupId);
props.put("archetypeArtifactId", archetypeArtifactId);
props.put("archetypeVersion", archetypeVersion);
props.put("groupId", projectGroupId);
props.put("artifactId", projectArtifactId);
props.put("version", projectVersion);
props.put("interactiveMode", "false");
return props;
}
public String getArchetypeGroupId() {
return archetypeGroupId;
}
public String getArchetypeArtifactId() {
return archetypeArtifactId;
}
public String getArchetypeVersion() {
return archetypeVersion;
}
public String getProjectGroupId() {
return projectGroupId;
}
public String getProjectArtifactId() {
return projectArtifactId;
}
public String getProjectVersion() {
return projectVersion;
}
public static class ArchetypePropertiesBuilder {
private String archetypeGroupId;
private String archetypeArtifactId;
private String archetypeVersion;
private String projectGroupId;
private String projectArtifactId;
private String projectVersion;
private ArchetypePropertiesBuilder() {
}
public ArchetypePropertiesBuilder withArchetypeGroupId(final String archetypeGroupId) {
this.archetypeGroupId = archetypeGroupId;
return this;
}
public ArchetypePropertiesBuilder withArchetypeArtifactId(final String archetypeArtifactId) {
this.archetypeArtifactId = archetypeArtifactId;
return this;
}
public ArchetypePropertiesBuilder withArchetypeVersion(final String archetypeVersion) {
this.archetypeVersion = archetypeVersion;
return this;
}
public ArchetypePropertiesBuilder withProjectGroupId(final String projectGroupId) {
this.projectGroupId = projectGroupId;
return this;
}
public ArchetypePropertiesBuilder withProjectArtifactId(final String projectArtifactId) {
this.projectArtifactId = projectArtifactId;
return this;
}
public ArchetypePropertiesBuilder withProjectVersion(final String projectVersion) {
this.projectVersion = projectVersion;
return this;
}
public ArchetypeProperties build() {
return new ArchetypeProperties(archetypeGroupId, archetypeArtifactId, archetypeVersion, projectGroupId,
projectArtifactId, projectVersion);
}
}
}

View File

@ -0,0 +1,33 @@
package org.alfresco.maven.archetype;
import org.apache.maven.it.Verifier;
import org.junit.Test;
/**
* Integration tests for the platform jar archetype.
*/
public class PlatformJarArchetypeIT extends AbstractArchetypeIT {
@Override
protected ArchetypeProperties createArchetypeProperties() {
return ArchetypeProperties.builder()
.withArchetypeGroupId("org.alfresco.maven.archetype")
.withArchetypeArtifactId("alfresco-platform-jar-archetype")
.withArchetypeVersion("4.0.0-SNAPSHOT")
.withProjectGroupId("archetype.it")
.withProjectArtifactId("repojar-test-run")
.withProjectVersion("0.1-SNAPSHOT")
.build();
}
@Test
public void whenGenerateProjectFromArchetypeThenAProperProjectIsCreated() throws Exception {
generateProjectFromArchetype();
// Since creating the archetype was successful, we now want to actually build the generated project
Verifier verifier = new Verifier(projectPath);
verifier.setAutoclean(false);
verifier.executeGoal("install");
verifier.verifyErrorFreeLog();
}
}

View File

@ -0,0 +1,33 @@
package org.alfresco.maven.archetype;
import org.apache.maven.it.Verifier;
import org.junit.Test;
/**
* Integration tests for the share jar archetype.
*/
public class ShareJarArchetypeIT extends AbstractArchetypeIT {
@Override
protected ArchetypeProperties createArchetypeProperties() {
return ArchetypeProperties.builder()
.withArchetypeGroupId("org.alfresco.maven.archetype")
.withArchetypeArtifactId("alfresco-share-jar-archetype")
.withArchetypeVersion("4.0.0-SNAPSHOT")
.withProjectGroupId("archetype.it")
.withProjectArtifactId("sharejar-test-run")
.withProjectVersion("0.1-SNAPSHOT")
.build();
}
@Test
public void whenGenerateProjectFromArchetypeThenAProperProjectIsCreated() throws Exception {
generateProjectFromArchetype();
// Since creating the archetype was successful, we now want to actually build the generated project
Verifier verifier = new Verifier(projectPath);
verifier.setAutoclean(false);
verifier.executeGoal("install");
verifier.verifyErrorFreeLog();
}
}