- * Creates a namespace and configures a {@link KubernetesClient} instance that will + * Creates a {@link KubernetesClient} instance that will * be automatically injected into tests. * + *
+ * Optionally, creates a Namespace for the tests and configures the client to use it. The Namespace + * is deleted after the test suite execution. + * *
{@code * @KubernetesTest * class MyTest { @@ -46,4 +50,8 @@ @Retention(RUNTIME) @ExtendWith(KubernetesNamespacedTestExtension.class) public @interface KubernetesTest { + /** + * Create an ephemeral Namespace for the test. + */ + boolean createEphemeralNamespace() default true; } diff --git a/junit/kubernetes-junit-jupiter/src/main/java/io/fabric8/junit/jupiter/api/LoadKubernetesManifests.java b/junit/kubernetes-junit-jupiter/src/main/java/io/fabric8/junit/jupiter/api/LoadKubernetesManifests.java index f2df7ac5452..cf067c143e6 100644 --- a/junit/kubernetes-junit-jupiter/src/main/java/io/fabric8/junit/jupiter/api/LoadKubernetesManifests.java +++ b/junit/kubernetes-junit-jupiter/src/main/java/io/fabric8/junit/jupiter/api/LoadKubernetesManifests.java @@ -36,7 +36,8 @@ */ @Target({ TYPE, METHOD, ANNOTATION_TYPE }) @Retention(RUNTIME) -@ExtendWith({ KubernetesNamespacedTestExtension.class, LoadKubernetesManifestsExtension.class }) +@ExtendWith(KubernetesNamespacedTestExtension.class) +@ExtendWith(LoadKubernetesManifestsExtension.class) public @interface LoadKubernetesManifests { String[] value(); diff --git a/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestTest.java b/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestTest.java new file mode 100644 index 00000000000..293ebdd3dc9 --- /dev/null +++ b/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestTest.java @@ -0,0 +1,53 @@ +/** + * 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.junit.jupiter.api; + +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.NamespacedKubernetesClient; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +@KubernetesTest(createEphemeralNamespace = false) +// Due to the way the extensions interact with the test, this test class can't be parameterized +class KubernetesTestTest { + + private static KubernetesClient staticKubernetesClient; + private KubernetesClient kubernetesClient; + private static NamespacedKubernetesClient staticNamespacedKubernetesClient; + private NamespacedKubernetesClient namespacedKubernetesClient; + + @Test + void staticKubernetesClient() { + assertThat(staticKubernetesClient).isNotNull(); + } + + @Test + void kubernetesClient() { + assertThat(kubernetesClient).isNotNull(); + } + + @Test + void staticNamespacedKubernetesClient() { + assertThat(staticNamespacedKubernetesClient).isNotNull(); + } + + @Test + void namespacedKubernetesClient() { + assertThat(namespacedKubernetesClient).isNotNull(); + } + +} diff --git a/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestWithSuperClass.java b/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestWithSuperClass.java new file mode 100644 index 00000000000..c80b7efe38f --- /dev/null +++ b/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestWithSuperClass.java @@ -0,0 +1,26 @@ +/** + * 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.junit.jupiter.api; + +import io.fabric8.kubernetes.client.KubernetesClient; + +@KubernetesTest(createEphemeralNamespace = false) +public class KubernetesTestWithSuperClass { + + static KubernetesClient staticSuperClient; + KubernetesClient superClient; + +} diff --git a/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestWithSuperClassTest.java b/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestWithSuperClassTest.java new file mode 100644 index 00000000000..03127e7c632 --- /dev/null +++ b/junit/kubernetes-junit-jupiter/src/test/java/io/fabric8/junit/jupiter/api/KubernetesTestWithSuperClassTest.java @@ -0,0 +1,48 @@ +/** + * 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.junit.jupiter.api; + +import io.fabric8.kubernetes.client.KubernetesClient; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class KubernetesTestWithSuperClassTest extends KubernetesTestWithSuperClass { + + private static KubernetesClient staticClient; + private KubernetesClient client; + + @Test + void staticSuperClientIsSet() { + assertThat(staticSuperClient).isNotNull(); + } + + @Test + void superClientIsSet() { + assertThat(superClient).isNotNull(); + } + + @Test + void staticClientIsSet() { + assertThat(staticClient).isNotNull(); + } + + @Test + void clientIsSet() { + assertThat(client).isNotNull(); + } + +}