From 27b405f6c6f787b281484ae071e6884b40aa2d75 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 23 Dec 2024 15:52:59 +0100 Subject: [PATCH] Use a global test resource for the Kubernetes server That means that the tests are not isolated from this POV but Marek was saying this would be OK. --- .../sbom/RequestEventRepositoryTest.java | 2 - .../feature/sbom/SBOMResourceRSQTest.java | 2 - .../integ/feature/sbom/SBOMServiceTest.java | 1 - .../SbomGenerationRequestRepositoryTest.java | 2 - .../feature/sbom/SbomRepositoryTest.java | 2 - .../generation/SyftImageResourceTest.java | 2 - ...nPhaseGenerationRequestReconcilerTest.java | 3 - .../GenerationFinishedMessageBodyTest.java | 2 - .../feature/sbom/messaging/PncBuildTest.java | 2 - .../test/integ/rest/ErrorResourcesTest.java | 2 - .../test/integ/rest/RestResourceTest.java | 2 - .../test/integ/rest/StatsResourceTest.java | 2 - .../utils/GlobalKubernetesServerResource.java | 5 +- .../SharedKubernetesServerTestResource.java | 75 ------------------- .../utils/WithSharedKubernetesTestServer.java | 51 ------------- 15 files changed, 3 insertions(+), 152 deletions(-) delete mode 100644 service/src/test/java/org/jboss/sbomer/service/test/utils/SharedKubernetesServerTestResource.java delete mode 100644 service/src/test/java/org/jboss/sbomer/service/test/utils/WithSharedKubernetesTestServer.java diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/RequestEventRepositoryTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/RequestEventRepositoryTest.java index f89aae00d..8de0b89b2 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/RequestEventRepositoryTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/RequestEventRepositoryTest.java @@ -29,7 +29,6 @@ import org.jboss.sbomer.service.feature.sbom.model.RequestEvent; import org.jboss.sbomer.service.feature.sbom.service.RequestEventRepository; import org.jboss.sbomer.service.test.utils.QuarkusTransactionalTest; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -43,7 +42,6 @@ import lombok.extern.slf4j.Slf4j; @QuarkusTransactionalTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @Slf4j diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMResourceRSQTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMResourceRSQTest.java index b92133294..97291c9df 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMResourceRSQTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMResourceRSQTest.java @@ -33,7 +33,6 @@ import org.jboss.sbomer.service.feature.sbom.model.Sbom; import org.jboss.sbomer.service.feature.sbom.model.SbomGenerationRequest; import org.jboss.sbomer.service.feature.sbom.service.SbomService; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -48,7 +47,6 @@ import io.restassured.path.json.JsonPath; @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class SBOMResourceRSQTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMServiceTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMServiceTest.java index 02f513168..b6bfc80a7 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMServiceTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SBOMServiceTest.java @@ -33,7 +33,6 @@ import org.jboss.sbomer.service.feature.sbom.service.SbomRepository; import org.jboss.sbomer.service.feature.sbom.service.SbomService; import org.jboss.sbomer.service.rest.QueryParameters; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomGenerationRequestRepositoryTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomGenerationRequestRepositoryTest.java index d966f1284..8f803d797 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomGenerationRequestRepositoryTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomGenerationRequestRepositoryTest.java @@ -50,7 +50,6 @@ import org.jboss.sbomer.service.feature.sbom.service.SbomService; import org.jboss.sbomer.service.rest.QueryParameters; import org.jboss.sbomer.service.test.utils.QuarkusTransactionalTest; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Test; @@ -63,7 +62,6 @@ @ApplicationScoped @QuarkusTransactionalTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class SbomGenerationRequestRepositoryTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomRepositoryTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomRepositoryTest.java index 379ea7b9c..08c8c3edf 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomRepositoryTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/SbomRepositoryTest.java @@ -42,7 +42,6 @@ import org.jboss.sbomer.service.feature.sbom.service.SbomRepository; import org.jboss.sbomer.service.rest.QueryParameters; import org.jboss.sbomer.service.test.utils.QuarkusTransactionalTest; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Test; @@ -56,7 +55,6 @@ import jakarta.validation.Validator; @QuarkusTransactionalTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class SbomRepositoryTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/generation/SyftImageResourceTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/generation/SyftImageResourceTest.java index a20807a03..32f6a7bab 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/generation/SyftImageResourceTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/generation/SyftImageResourceTest.java @@ -4,7 +4,6 @@ import org.hamcrest.CoreMatchers; import org.jboss.sbomer.service.feature.sbom.service.SbomService; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -15,7 +14,6 @@ import io.restassured.http.ContentType; @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class SyftImageResourceTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/k8s/reconciler/GenerationPhaseGenerationRequestReconcilerTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/k8s/reconciler/GenerationPhaseGenerationRequestReconcilerTest.java index 5e5161b35..89aed2f7d 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/k8s/reconciler/GenerationPhaseGenerationRequestReconcilerTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/k8s/reconciler/GenerationPhaseGenerationRequestReconcilerTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; @@ -44,7 +43,6 @@ import org.jboss.sbomer.service.feature.sbom.k8s.model.SbomGenerationStatus; import org.jboss.sbomer.service.feature.sbom.k8s.reconciler.BuildController; import org.jboss.sbomer.service.feature.sbom.k8s.resources.Labels; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -72,7 +70,6 @@ * Class responsible for testing reconciliation workflow for the generation phase. */ @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class GenerationPhaseGenerationRequestReconcilerTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/GenerationFinishedMessageBodyTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/GenerationFinishedMessageBodyTest.java index 1db72dad1..211873be0 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/GenerationFinishedMessageBodyTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/GenerationFinishedMessageBodyTest.java @@ -39,7 +39,6 @@ import org.jboss.sbomer.service.feature.sbom.features.umb.producer.model.Sbom.BomFormat; import org.jboss.sbomer.service.feature.sbom.features.umb.producer.model.Sbom.OperationGenerationRequest; import org.jboss.sbomer.service.feature.sbom.features.umb.producer.model.Sbom.PncBuildGenerationRequest; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Test; @@ -48,7 +47,6 @@ import jakarta.inject.Inject; @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class GenerationFinishedMessageBodyTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/PncBuildTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/PncBuildTest.java index 9461ed1d1..44e81f208 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/PncBuildTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/feature/sbom/messaging/PncBuildTest.java @@ -51,7 +51,6 @@ import org.jboss.sbomer.service.feature.sbom.service.SbomGenerationRequestRepository; import org.jboss.sbomer.service.test.PncWireMock; import org.jboss.sbomer.service.test.utils.AmqpMessageHelper; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -71,7 +70,6 @@ import lombok.extern.slf4j.Slf4j; @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) @WithTestResource(PncWireMock.class) @Slf4j diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/ErrorResourcesTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/ErrorResourcesTest.java index 024746b24..39fcf489b 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/ErrorResourcesTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/ErrorResourcesTest.java @@ -22,7 +22,6 @@ import org.hamcrest.CoreMatchers; import org.hamcrest.Matchers; import org.jboss.sbomer.service.feature.sbom.service.SbomService; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.ValueSource; @@ -39,7 +38,6 @@ * Ensures that we can handle errors properly. */ @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class ErrorResourcesTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/RestResourceTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/RestResourceTest.java index ba7f11213..2c04edb84 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/RestResourceTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/RestResourceTest.java @@ -47,7 +47,6 @@ import org.jboss.sbomer.service.feature.sbom.service.AdvisoryService; import org.jboss.sbomer.service.feature.sbom.service.SbomService; import org.jboss.sbomer.service.pnc.PncClient; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -70,7 +69,6 @@ import jakarta.inject.Inject; @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(TestUmbProfile.class) class RestResourceTest { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/StatsResourceTest.java b/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/StatsResourceTest.java index 004198af0..8b1c2741b 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/StatsResourceTest.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/integ/rest/StatsResourceTest.java @@ -22,7 +22,6 @@ import org.hamcrest.CoreMatchers; import org.jboss.sbomer.service.feature.sbom.service.SbomService; import org.jboss.sbomer.service.test.integ.rest.StatsResourceTest.CustomConfig; -import org.jboss.sbomer.service.test.utils.WithSharedKubernetesTestServer; import org.jboss.sbomer.service.test.utils.umb.TestUmbProfile; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -34,7 +33,6 @@ import io.restassured.RestAssured; @QuarkusTest -@WithSharedKubernetesTestServer @TestProfile(CustomConfig.class) class StatsResourceTest { public static class CustomConfig extends TestUmbProfile { diff --git a/service/src/test/java/org/jboss/sbomer/service/test/utils/GlobalKubernetesServerResource.java b/service/src/test/java/org/jboss/sbomer/service/test/utils/GlobalKubernetesServerResource.java index 8bf7ad34f..c0cce94be 100644 --- a/service/src/test/java/org/jboss/sbomer/service/test/utils/GlobalKubernetesServerResource.java +++ b/service/src/test/java/org/jboss/sbomer/service/test/utils/GlobalKubernetesServerResource.java @@ -1,9 +1,10 @@ package org.jboss.sbomer.service.test.utils; -import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.common.TestResourceScope; +import io.quarkus.test.common.WithTestResource; import io.quarkus.test.kubernetes.client.KubernetesServerTestResource; -//@QuarkusTestResource(KubernetesServerTestResource.class) +@WithTestResource(value = KubernetesServerTestResource.class, scope = TestResourceScope.GLOBAL) public class GlobalKubernetesServerResource { } diff --git a/service/src/test/java/org/jboss/sbomer/service/test/utils/SharedKubernetesServerTestResource.java b/service/src/test/java/org/jboss/sbomer/service/test/utils/SharedKubernetesServerTestResource.java deleted file mode 100644 index 7c8ad3916..000000000 --- a/service/src/test/java/org/jboss/sbomer/service/test/utils/SharedKubernetesServerTestResource.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.jboss.sbomer.service.test.utils; - -import java.lang.annotation.Annotation; -import java.lang.reflect.InvocationTargetException; -import java.net.InetAddress; -import java.util.Collections; -import java.util.function.Consumer; - -import io.fabric8.kubernetes.client.NamespacedKubernetesClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesServer; -import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager; -import io.quarkus.test.kubernetes.client.AbstractKubernetesTestResource; -import io.quarkus.test.kubernetes.client.KubernetesTestServer; - -public class SharedKubernetesServerTestResource - extends AbstractKubernetesTestResource - implements QuarkusTestResourceConfigurableLifecycleManager { - - private boolean https = false; - private boolean crud = true; - private int port = 0; - private Consumer setup; - - @Override - public void init(WithSharedKubernetesTestServer annotation) { - this.https = annotation.https(); - this.crud = annotation.crud(); - this.port = annotation.port(); - try { - this.setup = annotation.setup().getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException - | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - @Override - protected NamespacedKubernetesClient getClient() { - return server.getClient(); - } - - @Override - protected void initServer() { - server.before(); - } - - @Override - protected void configureServer() { - if (setup != null) - setup.accept(server); - } - - @Override - protected KubernetesServer createServer() { - return new KubernetesServer(https, crud, InetAddress.getLoopbackAddress(), port, Collections.emptyList()); - } - - @Override - public void stop() { - if (server != null) { - server.after(); - server = null; - } - } - - @Override - protected Class getInjectedClass() { - return KubernetesServer.class; - } - - @Override - protected Class getInjectionAnnotation() { - return KubernetesTestServer.class; - } -} diff --git a/service/src/test/java/org/jboss/sbomer/service/test/utils/WithSharedKubernetesTestServer.java b/service/src/test/java/org/jboss/sbomer/service/test/utils/WithSharedKubernetesTestServer.java deleted file mode 100644 index c0cc8de21..000000000 --- a/service/src/test/java/org/jboss/sbomer/service/test/utils/WithSharedKubernetesTestServer.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.jboss.sbomer.service.test.utils; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.function.Consumer; - -import io.fabric8.kubernetes.client.server.mock.KubernetesServer; -import io.quarkus.test.common.WithTestResource; -import io.quarkus.test.kubernetes.client.KubernetesTestServer; - -/** - * Use on your test resource to get a mock {@link KubernetesServer} spawn up, and injectable with - * {@link KubernetesTestServer}. - *

- * This annotation is only active when used on a test class, but the resource is shared across all test classes. - *

- * Make sure your tests don't interact with each other. - */ -@WithTestResource(value = SharedKubernetesServerTestResource.class) -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface WithSharedKubernetesTestServer { - - /** - * Start it with HTTPS - */ - boolean https() default false; - - /** - * Start it in CRUD mode - */ - boolean crud() default true; - - /** - * Port to use, defaults to any available port - */ - int port() default 0; - - /** - * Setup class to call after the mock server is created, for custom setup. - */ - Class> setup() default NO_SETUP.class; - - class NO_SETUP implements Consumer { - @Override - public void accept(KubernetesServer t) { - } - } -}