Skip to content

Commit

Permalink
Add integration tests using maven-invoker plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo42 committed May 15, 2024
1 parent 2139478 commit cc4ec43
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crd-generator/maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

<packaging>maven-plugin</packaging>

<properties>
<!-- required for integration tests -->
<fabric8-client.version>${project.version}</fabric8-client.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -91,6 +96,36 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<cloneClean>true</cloneClean>
<!--<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>-->
<settingsFile>src/it/settings.xml</settingsFile>
<postBuildHookScript>verify</postBuildHookScript>
<addTestClassPath>true</addTestClassPath>
<skipInvocation>${skipTests}</skipInvocation>
<streamLogs>true</streamLogs>
<invokerPropertiesFile>invoker.properties</invokerPropertiesFile>
<scriptVariables>
<version>${project.version}</version>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
</scriptVariables>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals.1=clean package
invoker.mavenOpts=
invoker.debug=false
56 changes: 56 additions & 0 deletions crd-generator/maven-plugin/src/it/project-explicit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>io.fabric8.crd.generator.samples</groupId>
<artifactId>project-explicit</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<version>@lombok.version@</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client-api</artifactId>
<version>@fabric8-client.version@</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<customResourceClasses>
<customResourceClass>io.fabric8.crd.maven.example.explicit.v1.Multiple</customResourceClass>
<customResourceClass>io.fabric8.crd.maven.example.explicit.v2.Multiple</customResourceClass>
</customResourceClasses>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.fabric8.crd.maven.example.explicit.v1;

import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.fabric8.io")
@Version(value = "v1", storage = false)
public class Multiple extends CustomResource<MultipleSpec, Void> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.fabric8.crd.maven.example.explicit.v1;

public class MultipleSpec {
private String v1;

public String getV1() {
return v1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.fabric8.crd.maven.example.explicit.v2;

import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.fabric8.io")
@Version("v2")
public class Multiple extends CustomResource<MultipleSpec, Void> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.crd.maven.example.explicit.v2;

public class MultipleSpec {
private String v2;

public String getV2() {
return v2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import io.fabric8.crd.generator.maven.plugin.Verify;


[ "multiples.sample.fabric8.io-v1" ].each {
Verify.verifyExist(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)))
}

true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals.1=clean package
invoker.mavenOpts=
invoker.debug=false
52 changes: 52 additions & 0 deletions crd-generator/maven-plugin/src/it/project-scan/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>io.fabric8.crd.generator.samples</groupId>
<artifactId>scan-project</artifactId>
<version>0.1-SNAPSHOT</version>

<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<version>@lombok.version@</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client-api</artifactId>
<version>@fabric8-client.version@</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-maven-plugin</artifactId>
<version>@fabric8-client.version@</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.fabric8.crd.maven.example.simple.v1;

import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.fabric8.io")
@Version(value = "v1", storage = false)
public class Multiple extends CustomResource<MultipleSpec, Void> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.fabric8.crd.maven.example.simple.v1;

import lombok.Data;

@Data
public class MultipleSpec {
private String v1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.fabric8.crd.maven.example.simple.v2;

import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.fabric8.io")
@Version("v2")
public class Multiple extends CustomResource<MultipleSpec, Void> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.crd.maven.example.simple.v2;

import lombok.Data;

@Data
public class MultipleSpec {
private String v2;
}
8 changes: 8 additions & 0 deletions crd-generator/maven-plugin/src/it/project-scan/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import io.fabric8.crd.generator.maven.plugin.Verify;


[ "multiples.sample.fabric8.io-v1" ].each {
Verify.verifyExist(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)))
}

true
35 changes: 35 additions & 0 deletions crd-generator/maven-plugin/src/it/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.fabric8.crd.generator.maven.plugin;

import java.io.File;

class Verify {
static void verifyExist(File file) {
if (!file.exists())
throw new AssertionError("File " + file.getAbsoluteFile() + " does not exist");
}
}

0 comments on commit cc4ec43

Please sign in to comment.