diff --git a/pom.xml b/pom.xml index 3a9938d..c06dceb 100644 --- a/pom.xml +++ b/pom.xml @@ -152,6 +152,12 @@ maven-surefire-plugin ${surefire-plugin.version} + + **/*Test.java + + + **/*E2E.java + org.jboss.logmanager.LogManager ${maven.home} @@ -204,7 +210,34 @@ + + + + e2e-tests + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + **/*E2E.java + + + **/*Test.java + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + diff --git a/src/test/java/io/csviri/operator/resourceglue/TestUtils.java b/src/test/java/io/csviri/operator/resourceglue/TestUtils.java index cea4213..652fcc5 100644 --- a/src/test/java/io/csviri/operator/resourceglue/TestUtils.java +++ b/src/test/java/io/csviri/operator/resourceglue/TestUtils.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,14 +40,18 @@ public static GlueOperator loadResourceFlowOperator(String path) { } } - public static GenericKubernetesResource load(String path) { + public static T load(String path, Class clazz) { try (InputStream is = TestUtils.class.getResourceAsStream(path)) { - return Serialization.unmarshal(is, GenericKubernetesResource.class); + return Serialization.unmarshal(is, clazz); } catch (IOException e) { throw new RuntimeException(e); } } + public static GenericKubernetesResource load(String path) { + return load(path, GenericKubernetesResource.class); + } + public static GenericKubernetesResource createOrUpdate(KubernetesClient client, String path) { return client.resource(load(path)).createOr(NonDeletingOperation::update); } @@ -55,6 +60,11 @@ public static void applyCrd(Class resourceClass, Kubernet applyCrd(ReconcilerUtils.getResourceTypeName(resourceClass), client); } + public static void applyCrd(KubernetesClient client, + Class... resourceClasses) { + Arrays.stream(resourceClasses).forEach(c -> applyCrd(c, client)); + } + public static void applyCrd(String resourceTypeName, KubernetesClient client) { String path = "/META-INF/fabric8/" + resourceTypeName + "-v1.yml"; try (InputStream is = TestUtils.class.getResourceAsStream(path)) { diff --git a/src/test/java/io/csviri/operator/resourceglue/WebPageE2E.java b/src/test/java/io/csviri/operator/resourceglue/WebPageE2E.java new file mode 100644 index 0000000..5a1c791 --- /dev/null +++ b/src/test/java/io/csviri/operator/resourceglue/WebPageE2E.java @@ -0,0 +1,21 @@ +package io.csviri.operator.resourceglue; + +import org.junit.jupiter.api.BeforeEach; + +import io.csviri.operator.resourceglue.customresource.glue.Glue; +import io.csviri.operator.resourceglue.customresource.operator.GlueOperator; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; + +public class WebPageE2E { + + private KubernetesClient client = new KubernetesClientBuilder().build(); + + @BeforeEach + void applyCRDs() { + TestUtils.applyCrd(client, Glue.class, GlueOperator.class); + + } + + +} diff --git a/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPage.java b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPage.java new file mode 100644 index 0000000..e6f767b --- /dev/null +++ b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPage.java @@ -0,0 +1,15 @@ +package io.csviri.operator.resourceglue.sample.webpage; + +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Plural; +import io.fabric8.kubernetes.model.annotation.Singular; +import io.fabric8.kubernetes.model.annotation.Version; + +@Version(value = "v1", storage = true, served = true) +@Group("resourceglueoperator.sample") +@Singular("webpage") +@Plural("webpages") +@javax.annotation.processing.Generated("io.fabric8.java.generator.CRGeneratorRunner") +public class WebPage extends io.fabric8.kubernetes.client.CustomResource + implements io.fabric8.kubernetes.api.model.Namespaced { +} diff --git a/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSampleTest.java b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSampleTest.java index b861e56..caeb989 100644 --- a/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSampleTest.java +++ b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSampleTest.java @@ -1,13 +1,11 @@ package io.csviri.operator.resourceglue.sample.webpage; -import java.util.HashMap; import org.junit.jupiter.api.Test; import io.csviri.operator.resourceglue.TestBase; import io.csviri.operator.resourceglue.TestUtils; import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.GenericKubernetesResource; import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.api.model.networking.v1.Ingress; @@ -21,10 +19,10 @@ public class WebPageSampleTest extends TestBase { @Test void webPageCRUD() { - createOrUpdate(TestUtils.load("/sample/webpage/webpage.crd.yml")); createOrUpdate(TestUtils.load("/sample/webpage/webpage.operator.yaml")); - var webPage = createOrUpdate(TestUtils.load("/sample/webpage/webpage.sample.yaml")); + WebPage webPage = + createOrUpdate(TestUtils.load("/sample/webpage/webpage.sample.yaml", WebPage.class)); await().untilAsserted(() -> { var deployment = get(Deployment.class, webPage.getMetadata().getName()); @@ -39,8 +37,17 @@ void webPageCRUD() { assertThat(configMap.getData().get("index.html")).contains("Hello World!"); }); - setExposed(webPage); - setNewHtml(webPage); + webPage.getSpec().setExposed(true); + webPage.getSpec().setHtml(""" + + + Hello Operator World + + + Hello World 2! + + + """); update(webPage); await().untilAsserted(() -> { @@ -58,21 +65,4 @@ void webPageCRUD() { assertThat(deployment).isNull(); }); } - - private void setNewHtml(GenericKubernetesResource webPage) { - ((HashMap) webPage.getAdditionalProperties().get("spec")).put("html", """ - - - Hello Operator World - - - Hello World 2! - - - """); - } - - private void setExposed(GenericKubernetesResource webPage) { - ((HashMap) webPage.getAdditionalProperties().get("spec")).put("exposed", true); - } } diff --git a/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSpec.java b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSpec.java new file mode 100644 index 0000000..12117ca --- /dev/null +++ b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageSpec.java @@ -0,0 +1,29 @@ +package io.csviri.operator.resourceglue.sample.webpage; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"exposed", "html"}) +public class WebPageSpec { + + private Boolean exposed; + + private String html; + + public Boolean getExposed() { + return exposed; + } + + public void setExposed(Boolean exposed) { + this.exposed = exposed; + } + + public String getHtml() { + return html; + } + + public void setHtml(String html) { + this.html = html; + } +} diff --git a/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageStatus.java b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageStatus.java new file mode 100644 index 0000000..fcb5b71 --- /dev/null +++ b/src/test/java/io/csviri/operator/resourceglue/sample/webpage/WebPageStatus.java @@ -0,0 +1,11 @@ +package io.csviri.operator.resourceglue.sample.webpage; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({}) +@JsonDeserialize(using = com.fasterxml.jackson.databind.JsonDeserializer.None.class) +public class WebPageStatus { +}