Search in sources :

Example 1 with AbstractObjectAssert

use of org.assertj.core.api.AbstractObjectAssert in project quarkus by quarkusio.

the class OpenshiftWithLegacySidecarAndS2iTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml"));
    List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
    assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("openshift-sidecar-test");
            assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
        });
        AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec");
        specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, podSpec -> {
            assertThat(podSpec.getContainers()).hasSize(2);
            assertSidecar(podSpec);
            assertApplicationContainer(podSpec);
        });
    });
}
Also used : Path(java.nio.file.Path) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) Collections(java.util.Collections) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 2 with AbstractObjectAssert

use of org.assertj.core.api.AbstractObjectAssert in project quarkus by quarkusio.

the class OpenshiftWithSidecarAndS2iTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml"));
    List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
    assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("openshift-sidecar-test");
            assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
        });
        AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec");
        specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, podSpec -> {
            assertThat(podSpec.getContainers()).hasSize(2);
            assertSidecar(podSpec);
            assertApplicationContainer(podSpec);
        });
    });
}
Also used : Path(java.nio.file.Path) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) Collections(java.util.Collections) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 3 with AbstractObjectAssert

use of org.assertj.core.api.AbstractObjectAssert in project quarkus by quarkusio.

the class OpenshiftWithAppConfigMapTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml"));
    List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
    assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("openshift-with-app-config-map");
            assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
        });
        AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec");
        specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, podSpec -> {
            assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
                List<EnvVar> envVars = container.getEnv();
                assertThat(envVars).anySatisfy(envVar -> {
                    assertThat(envVar.getName()).isEqualTo("SMALLRYE_CONFIG_LOCATIONS");
                    assertThat(envVar.getValue()).isEqualTo("/mnt/app-config-map");
                });
                List<VolumeMount> mounts = container.getVolumeMounts();
                assertThat(mounts).anySatisfy(mount -> {
                    assertThat(mount.getName()).isEqualTo("app-config-map");
                    assertThat(mount.getMountPath()).isEqualTo("/mnt/app-config-map");
                });
            });
            List<Volume> volumes = podSpec.getVolumes();
            assertThat(volumes).anySatisfy(volume -> {
                assertThat(volume.getName()).isEqualTo("app-config-map");
                assertThat(volume.getConfigMap().getName()).isEqualTo("my-config-map");
            });
        });
    });
}
Also used : Path(java.nio.file.Path) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) AppArtifact(io.quarkus.bootstrap.model.AppArtifact) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Version(io.quarkus.builder.Version) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) IOException(java.io.IOException) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) Collections(java.util.Collections) Volume(io.fabric8.kubernetes.api.model.Volume) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Volume(io.fabric8.kubernetes.api.model.Volume) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractObjectAssert

use of org.assertj.core.api.AbstractObjectAssert in project quarkus by quarkusio.

the class OpenshiftWithApplicationPropertiesTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml"));
    List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
    assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("test-it");
            assertThat(m.getLabels()).contains(entry("foo", "bar"));
            assertThat(m.getNamespace()).isEqualTo("applications");
        });
        AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec");
        specAssert.extracting("replicas").isEqualTo(3);
        specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, podSpec -> {
            assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
                assertThat(container.getEnv()).extracting("name", "value").contains(tuple("MY_ENV_VAR", "SOMEVALUE"));
                assertThat(container.getImagePullPolicy()).isEqualTo("IfNotPresent");
            });
        });
        specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> {
            assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "test-it"));
        });
    });
    assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h).isInstanceOfSatisfying(Service.class, s -> {
            assertThat(s.getMetadata()).satisfies(m -> {
                assertThat(m.getNamespace()).isEqualTo("applications");
            });
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getSelector()).containsOnly(entry("app.kubernetes.io/name", "test-it"));
                assertThat(spec.getPorts()).hasSize(1).singleElement().satisfies(p -> {
                    assertThat(p.getPort()).isEqualTo(80);
                    assertThat(p.getTargetPort().getIntVal()).isEqualTo(9090);
                });
            });
        });
    });
    assertThat(openshiftList).filteredOn(i -> "Route".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Route.class, r -> {
            // Check that labels and annotations are also applied to Routes (#10260)
            assertThat(r.getMetadata()).satisfies(m -> {
                assertThat(m.getName()).isEqualTo("test-it");
                assertThat(m.getLabels()).contains(entry("foo", "bar"));
                assertThat(m.getAnnotations()).contains(entry("bar", "baz"));
                assertThat(m.getNamespace()).isEqualTo("applications");
            });
            assertThat(r.getSpec().getPort().getTargetPort().getIntVal()).isEqualTo(9090);
        });
    });
}
Also used : Path(java.nio.file.Path) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) IOException(java.io.IOException) Assertions.entry(org.assertj.core.api.Assertions.entry) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) Route(io.fabric8.openshift.api.model.Route) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Map(java.util.Map) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Service(io.fabric8.kubernetes.api.model.Service) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 5 with AbstractObjectAssert

use of org.assertj.core.api.AbstractObjectAssert in project quarkus by quarkusio.

the class OpenshiftV4Test method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.json")).isDirectoryContaining(p -> p.getFileName().endsWith("openshift.yml")).satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));
    List<HasMetadata> openshiftList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("openshift.yml"));
    assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h.getMetadata()).satisfies(m -> {
            assertThat(m.getName()).isEqualTo("openshift-v4");
            assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
            assertThat(m.getLabels().get("app.kubernetes.io/name")).isEqualTo("openshift-v4");
            assertThat(m.getLabels().get("app")).isNull();
            assertThat(m.getNamespace()).isNull();
        });
        AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec");
        specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> {
            assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "openshift-v4"), entry("app.kubernetes.io/version", "0.1-SNAPSHOT"));
        });
    });
    assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).singleElement().satisfies(h -> {
        assertThat(h).isInstanceOfSatisfying(Service.class, s -> {
            assertThat(s.getMetadata()).satisfies(m -> {
                assertThat(m.getNamespace()).isNull();
                assertThat(m.getLabels().get("app.kubernetes.io/name")).isEqualTo("openshift-v4");
                assertThat(m.getLabels().get("app")).isNull();
            });
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(spec.getSelector()).containsOnly(entry("app.kubernetes.io/name", "openshift-v4"), entry("app.kubernetes.io/version", "0.1-SNAPSHOT"));
            });
        });
    });
}
Also used : Path(java.nio.file.Path) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) IOException(java.io.IOException) Assertions.entry(org.assertj.core.api.Assertions.entry) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Map(java.util.Map) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Service(io.fabric8.kubernetes.api.model.Service) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)11 AbstractObjectAssert (org.assertj.core.api.AbstractObjectAssert)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 Test (org.junit.jupiter.api.Test)11 ProdBuildResults (io.quarkus.test.ProdBuildResults)10 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)10 QuarkusProdModeTest (io.quarkus.test.QuarkusProdModeTest)10 IOException (java.io.IOException)10 Path (java.nio.file.Path)10 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)10 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)9 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)6 AppArtifact (io.quarkus.bootstrap.model.AppArtifact)6 Version (io.quarkus.builder.Version)6 Collections (java.util.Collections)5 Assertions.entry (org.assertj.core.api.Assertions.entry)5 Service (io.fabric8.kubernetes.api.model.Service)4 Map (java.util.Map)4 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)3 Volume (io.fabric8.kubernetes.api.model.Volume)2