Skip to content

Commit

Permalink
Add negative tests for versionless feature support
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Sep 21, 2024
1 parent 85242ee commit 045e535
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 2 deletions.
2 changes: 1 addition & 1 deletion liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-ant-tasks</artifactId>
<version>1.9.15</version>
<version>1.9.16-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.buildResult = failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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>

<parent>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>kernel-install-versionless-feature-fail-bad-platform-it</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<assemblyArtifact>
<groupId>${runtimeGroupId}</groupId>
<artifactId>${runtimeKernelId}</artifactId>
<version>${runtimeVersion}</version>
<type>zip</type>
</assemblyArtifact>
<serverName>test</serverName>
<serverXmlFile>src/test/resources/server.xml</serverXmlFile>
</configuration>
<executions>
<execution>
<id>install-liberty-server</id>
<phase>compile</phase>
<goals>
<goal>install-server</goal>
</goals>
</execution>
<execution>
<id>create-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
<execution>
<id>install-feature</id>
<phase>pre-integration-test</phase>
<goals>
<goal>install-feature</goal>
</goals>
<configuration>
<features>
<acceptLicense>true</acceptLicense>
</features>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<argLine>-enableassertions</argLine>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<server description="default server">
<featureManager>
<feature>appSecurityClient-1.0</feature>
<feature>jaxws</feature>
<platform>badname</platform>
</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.buildResult = failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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>

<parent>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>kernel-install-versionless-feature-fail-no-platform-it</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<assemblyArtifact>
<groupId>${runtimeGroupId}</groupId>
<artifactId>${runtimeKernelId}</artifactId>
<version>${runtimeVersion}</version>
<type>zip</type>
</assemblyArtifact>
<serverName>test</serverName>
<serverXmlFile>src/test/resources/server.xml</serverXmlFile>
</configuration>
<executions>
<execution>
<id>install-liberty-server</id>
<phase>compile</phase>
<goals>
<goal>install-server</goal>
</goals>
</execution>
<execution>
<id>create-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
<execution>
<id>install-feature</id>
<phase>pre-integration-test</phase>
<goals>
<goal>install-feature</goal>
</goals>
<configuration>
<features>
<acceptLicense>true</acceptLicense>
</features>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<argLine>-enableassertions</argLine>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<server description="default server">
<featureManager>
<feature>appSecurityClient-1.0</feature>
<feature>servlet</feature>
</featureManager>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//Check build.log content for certain tests
boolean flag = false;
String testname = basedir.getName();
String expectedMessage = null;
switch (testname) {
case "kernel-install-versionless-feature-fail-bad-platform-it":
expectedMessage = "CWWKF1515E: The badname platform could not be found.";
break;
case "kernel-install-versionless-feature-fail-no-platform-it":
expectedMessage = "CWWKF1516E: The platform could not be determined. The following versionless features cannot be installed: [servlet]";
break;
default:
return false;
}
File buildlog = new File(basedir,"build.log");
if (buildlog.exists()) {
try {
InputStream buildOutput = new FileInputStream(buildlog);
InputStreamReader in = new InputStreamReader(buildOutput);
java.util.Scanner s = new java.util.Scanner(in);
while (s.hasNextLine() && !flag) {
String line = s.nextLine();
if (line.contains(expectedMessage)) {
flag = true;
System.out.println("Correct error message found for test "+testname);
}
}
s.close();
in.close();
buildOutput.close();
} catch (Exception e) {
System.out.println("Error checking build.log " + e.getMessage());
}
}
if (!flag) {
System.out.println("FAILED: Expected error message ("+expectedMessage+") not found in "+buildlog.getAbsolutePath());
}
return flag;
9 changes: 8 additions & 1 deletion liberty-maven-plugin/src/test/resources/cleanTest.bsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
//If need to check build.log for error message, call script
boolean flag = true;
if (basedir.getName().contains("versionless-feature-fail-")) {
String errorScript = new File(basedir, "checkErrorVersionlessFeature.bsh").getAbsolutePath();
System.out.println("Running post-build script: "+ errorScript);
flag = source(errorScript);
}
//Runs clean in the test project directory
Runtime.getRuntime().exec("../../../../mvnw clean", null, basedir);
System.out.println("Cleaned target dir(s) for " + basedir);
return true;
return flag;

0 comments on commit 045e535

Please sign in to comment.