From 89435bd821a91899be38e28cb5adf0f7101c106a Mon Sep 17 00:00:00 2001 From: mkralik3 Date: Tue, 6 Jun 2023 12:43:20 +0200 Subject: [PATCH] fix/test: null check for a type param in Deploment + test expansion * Add more tests for Deployments resources + native tests --- api/pom.xml | 5 + .../api/resource/v1/DeploymentsResource.java | 18 +- .../api/resource/support/NativeHelper.java | 42 ++ .../resource/v1/DeploymentsResourceIT.java | 15 + .../resource/v1/DeploymentsResourceTest.java | 99 +--- .../v1/DeploymentsResourcesTestAbstract.java | 451 ++++++++++++++++++ .../backend/api/resource/integration.yaml | 15 + 7 files changed, 548 insertions(+), 97 deletions(-) create mode 100644 api/src/test/java/io/kaoto/backend/api/resource/support/NativeHelper.java create mode 100644 api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceIT.java create mode 100644 api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourcesTestAbstract.java create mode 100644 api/src/test/resources/io/kaoto/backend/api/resource/integration.yaml diff --git a/api/pom.xml b/api/pom.xml index 8e21e9ffc..98217ecf5 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -71,6 +71,11 @@ assertj-core test + + org.awaitility + awaitility + test + diff --git a/api/src/main/java/io/kaoto/backend/api/resource/v1/DeploymentsResource.java b/api/src/main/java/io/kaoto/backend/api/resource/v1/DeploymentsResource.java index 6268965a5..4127b262c 100644 --- a/api/src/main/java/io/kaoto/backend/api/resource/v1/DeploymentsResource.java +++ b/api/src/main/java/io/kaoto/backend/api/resource/v1/DeploymentsResource.java @@ -150,10 +150,15 @@ private String securityCheck(final String crd) { @Operation(summary = "Get CRD", description = "Returns the custom resource identified by name.") public String resource( - final @Parameter(description = "Name of the resource to get.") @PathParam("name") String name, - final @Parameter(description = "Type of the resource to get") @QueryParam("type") String type, + final @Parameter(description = "Name of the resource to get.") @PathParam("name") + String name, + final @Parameter(description = "Type of the resource to get", required = true) @QueryParam("type") + String type, final @Parameter(description = "Namespace of the cluster where the resource is running.") @QueryParam("namespace") String namespace) { + if (type == null) { + throw new IllegalStateException("query parameter 'type' is required."); + } CustomResource cr = clusterService.get(namespace, name, type); if (cr == null) { throw new NotFoundException("Resource with name " + name + " not " @@ -192,10 +197,15 @@ public String resource( @Operation(summary = "Stop/Remove", description = "Remove the resource identified by name.") public boolean stop( - final @Parameter(description = "Name of the resource to get.") @PathParam("name") String name, - final @Parameter(description = "Type of the resource to get") @QueryParam("type") String type, + final @Parameter(description = "Name of the resource to get.") @PathParam("name") + String name, + final @Parameter(description = "Type of the resource to get", required = true) @QueryParam("type") + String type, final @Parameter(description = "Namespace of the cluster where the resource is running.") @QueryParam("namespace") String namespace) { + if (type == null) { + throw new IllegalStateException("query parameter 'type' is required."); + } return clusterService.stop(name, namespace, type); } diff --git a/api/src/test/java/io/kaoto/backend/api/resource/support/NativeHelper.java b/api/src/test/java/io/kaoto/backend/api/resource/support/NativeHelper.java new file mode 100644 index 000000000..b98929e13 --- /dev/null +++ b/api/src/test/java/io/kaoto/backend/api/resource/support/NativeHelper.java @@ -0,0 +1,42 @@ +package io.kaoto.backend.api.resource.support; + +import org.awaitility.Awaitility; +import org.awaitility.Durations; +import org.jboss.logging.Logger; + +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; + +import static io.quarkus.bootstrap.util.IoUtils.readFile; + +/** + * Functions that help native testing to use the same functionality as JVM testing does with injection + */ +public class NativeHelper { + + private static final Logger log = Logger.getLogger(NativeHelper.class); + + + public static void waitForWarmUpCatalog(String catalogClassName) { + // when quarkus run native image before native tests, they set path to log to api/target/quarkus.log + // and it cannot be overridden + Path quarkusNativeLog = Paths.get("target", "quarkus.log"); + log.info("Using Quarkus log file from " + quarkusNativeLog); + Awaitility.await() + .timeout(Duration.ofSeconds(20)) + .pollDelay(Durations.ONE_SECOND) + .dontCatchUncaughtExceptions() + .until(() -> { + try { + return readFile(quarkusNativeLog).contains( + String.format("Catalog class %s_Subclass warmed up in", catalogClassName)); + } catch (NoSuchFileException e) { + throw new IllegalStateException("The quarkus.log file doesn't exist in the api/target! " + + "This can happen when integration tests are executing against a running application. " + + "Usage NativeHelper in remote native testing is not implemented yet!"); + } + }); + } +} diff --git a/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceIT.java b/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceIT.java new file mode 100644 index 000000000..c03e100c0 --- /dev/null +++ b/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceIT.java @@ -0,0 +1,15 @@ +package io.kaoto.backend.api.resource.v1; + +import io.kaoto.backend.api.metadata.catalog.StepCatalog; +import io.kaoto.backend.api.resource.support.NativeHelper; +import io.quarkus.test.junit.QuarkusIntegrationTest; + + +@QuarkusIntegrationTest +public class DeploymentsResourceIT extends DeploymentsResourcesTestAbstract { + + @Override + protected void waitForWarmUpCatalog() { + NativeHelper.waitForWarmUpCatalog(StepCatalog.class.getCanonicalName()); + } +} diff --git a/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceTest.java b/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceTest.java index 10be7945f..cfd8d77a1 100644 --- a/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceTest.java +++ b/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourceTest.java @@ -1,110 +1,23 @@ package io.kaoto.backend.api.resource.v1; import io.kaoto.backend.api.metadata.catalog.StepCatalog; -import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.kubernetes.client.WithKubernetesTestServer; -import org.junit.jupiter.api.Test; import javax.inject.Inject; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Path; - -import static io.restassured.RestAssured.given; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusTest -@WithKubernetesTestServer -@TestHTTPEndpoint(DeploymentsResource.class) -class DeploymentsResourceTest { +class DeploymentsResourceTest extends DeploymentsResourcesTestAbstract { private StepCatalog catalog; - @Test - void test() throws URISyntaxException, IOException { - - catalog.waitForWarmUp().join(); - - var res = given() - .when() - .contentType("application/json") - .get() - .then() - .statusCode(Response.Status.OK.getStatusCode()); - assertEquals("[]", res.extract().response().asString()); - - - String yamlBinding = Files.readString(Path.of( - DeploymentsResourceTest.class.getResource( - "../twitter-search-source-binding.yaml") - .toURI())); - final var name = "integration-4"; - - given() - .when() - .get("/{name}", name) - .then() - .statusCode(Response.Status.NOT_FOUND.getStatusCode()); - - given() - .when() - .contentType("application/json") - .delete("/{name}", name) - .then() - .statusCode(Response.Status.NOT_FOUND.getStatusCode()); - - given() - .when().body(yamlBinding) - .contentType("text/yaml") - .post("/{name}", "Updated integration") - .then() - .statusCode(Response.Status.OK.getStatusCode()); - - res = given() - .when() - .contentType("application/json") - .get() - .then() - .statusCode(Response.Status.OK.getStatusCode()); - assertNotEquals("[]", res.extract().response().asString()); - - res = given() - .when() - .get("/{name}", name) - .then() - .statusCode(Response.Status.OK.getStatusCode()); - var yaml = res.extract().response().asString(); - assertNotNull(yaml); - assertTrue(yaml.contains("kind: KameletBinding")); - assertTrue(yaml.contains("name: twitter-search-source")); - assertTrue(yaml.contains("name: aws-translate-action")); - - res = given() - .when() - .contentType("application/json") - .delete("/{name}", name) - .then() - .statusCode(Response.Status.OK.getStatusCode()); - assertTrue(Boolean.valueOf(res.extract().response().asString())); - - res = given() - .when() - .contentType("application/json") - .get() - .then() - .statusCode(Response.Status.OK.getStatusCode()); - assertEquals("[]", res.extract().response().asString()); - } - @Inject public void setCatalog(final StepCatalog catalog) { this.catalog = catalog; } + + @Override + protected void waitForWarmUpCatalog() { + catalog.waitForWarmUp().join(); + } } diff --git a/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourcesTestAbstract.java b/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourcesTestAbstract.java new file mode 100644 index 000000000..dfb96b5bd --- /dev/null +++ b/api/src/test/java/io/kaoto/backend/api/resource/v1/DeploymentsResourcesTestAbstract.java @@ -0,0 +1,451 @@ +package io.kaoto.backend.api.resource.v1; + +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.client.server.mock.KubernetesServer; +import io.kaoto.backend.model.deployment.camelroute.Integration; +import io.kaoto.backend.model.deployment.kamelet.Kamelet; +import io.kaoto.backend.model.deployment.kamelet.KameletBinding; +import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.kubernetes.client.KubernetesTestServer; +import io.quarkus.test.kubernetes.client.WithKubernetesTestServer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Objects; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; + +@WithKubernetesTestServer +@TestHTTPEndpoint(DeploymentsResource.class) +public abstract class DeploymentsResourcesTestAbstract { + + private static final String DEFAULT_NAMESPACE = "default"; + private static final String OTHER_NAMESPACE = "other"; + private static final String BINDING_NAME = "integration-4"; + + protected abstract void waitForWarmUpCatalog(); + + @KubernetesTestServer + KubernetesServer mockServer; + + @BeforeEach + void setupTest() { + waitForWarmUpCatalog(); + } + + @AfterEach + void cleanUp() { + mockServer.getClient().resources(KameletBinding.class).inAnyNamespace().list().getItems() + .forEach(kameletBinding -> mockServer.getClient().resource(kameletBinding).delete()); + mockServer.getClient().resources(Kamelet.class).inAnyNamespace().list().getItems() + .forEach(kamelet -> mockServer.getClient().resource(kamelet).delete()); + mockServer.getClient().resources(Integration.class).inAnyNamespace().list().getItems() + .forEach(integration -> mockServer.getClient().resource(integration).delete()); + } + + @Test + void getAllTest() { + List res = given() + .when() + .get() + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().jsonPath().getList("type", String.class); + assertThat(res).isEmpty(); + + createTestKameletBinding(DEFAULT_NAMESPACE); + createTestKamelet(DEFAULT_NAMESPACE); + createTestIntegration(DEFAULT_NAMESPACE); + res = given() + .when() + .get() + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().jsonPath().getList("type", String.class); + assertThat(res) + .isNotEmpty() + .hasSize(3) + .containsExactlyInAnyOrder("KameletBinding", "Kamelet", "Integration"); + } + + @Test + void getAllNamespaceQueryTest() { + List res = given() + .queryParam("namespace", OTHER_NAMESPACE) + .when() + .get() + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().jsonPath().getList("type", String.class); + assertThat(res).isEmpty(); + + createTestKameletBinding(DEFAULT_NAMESPACE); + res = given() + .queryParam("namespace", OTHER_NAMESPACE) + .when() + .get() + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().jsonPath().getList("type", String.class); + assertThat(res).isEmpty(); + + createTestKameletBinding(OTHER_NAMESPACE); + createTestKamelet(OTHER_NAMESPACE); + createTestIntegration(OTHER_NAMESPACE); + res = given() + .queryParam("namespace", OTHER_NAMESPACE) + .when() + .get() + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().jsonPath().getList("type", String.class); + assertThat(res) + .isNotEmpty() + .hasSize(3) + .containsExactlyInAnyOrder("KameletBinding", "Kamelet", "Integration"); + } + + @Test + void getExceptionsTest() { + String response = given() + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()) + .extract().body().asString(); + assertThat(response).isEqualTo( + String.format("Error processing deployment: Resource with name %s not found.", BINDING_NAME)); + response = given() + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.BAD_REQUEST.getStatusCode()) + .extract().body().asString(); + assertThat(response).isEqualTo("Error processing deployment: query parameter 'type' is required."); + createTestKameletBinding(DEFAULT_NAMESPACE); + response = given() + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.BAD_REQUEST.getStatusCode()) + .extract().body().asString(); + assertThat(response).isEqualTo("Error processing deployment: query parameter 'type' is required."); + } + + @Test + void getTest() { + given() + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()); + createTestKameletBinding(DEFAULT_NAMESPACE); + String resource = given() + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().asString(); + assertThat(resource) + .contains("kind: KameletBinding") + .contains("name: twitter-search-source"); + } + + @Test + void getNamespaceQueryTest() { + createTestKameletBinding(OTHER_NAMESPACE); + String differentTestKb = createDifferentTestKameletBinding(OTHER_NAMESPACE); + given() + .queryParam("namespace", OTHER_NAMESPACE) + .queryParam("type", "Kamelet") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()); + given() + .queryParam("namespace", DEFAULT_NAMESPACE) + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()); + given() + .queryParam("namespace", DEFAULT_NAMESPACE) + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", differentTestKb) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()); + String resource = given() + .queryParam("namespace", OTHER_NAMESPACE) + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().response().asString(); + assertThat(resource) + .contains("kind: KameletBinding") + .contains("name: twitter-search-source"); + + String kameletName = createTestKamelet(DEFAULT_NAMESPACE); + resource = given() + .queryParam("type", "Kamelet") + .when() + .get("/{name}", kameletName) + .then() + .contentType("text/yaml") + .statusCode(Response.Status.OK.getStatusCode()) + .extract().response().asString(); + assertThat(resource).contains("kind: Kamelet"); + } + + @Test + void startKameletTest() { + assertThat(mockServer.getClient().resources(Kamelet.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()).isEmpty(); + given() + .when().body(getTestKameletBinding("../eip.kamelet.yaml")) + .contentType("text/yaml") + .post("/{name}", "Not needed anymore") + .then() + .statusCode(Response.Status.OK.getStatusCode()); + + assertThat(mockServer.getClient().resources(Kamelet.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()) + .extracting(Kamelet::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that Kamelet was created") + .containsExactly("eip-action"); + } + + @Test + void startKameletBindingsTest() { + assertThat(mockServer.getClient().resources(KameletBinding.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()).isEmpty(); + given() + .when().body(getTestKameletBinding("../twitter-search-source-binding.yaml")) + .contentType("text/yaml") + .post("/{name}", "Not needed anymore") + .then() + .statusCode(Response.Status.OK.getStatusCode()); + + assertThat(mockServer.getClient().resources(KameletBinding.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()) + .extracting(KameletBinding::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that Kamelet Bindings was created") + .containsExactly(BINDING_NAME); + } + + @Test + void startIntegrationTest() { + assertThat(mockServer.getClient().resources(Integration.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()).isEmpty(); + given() + .when().body(getTestKameletBinding("../integration.yaml")) + .contentType("text/yaml") + .post("/{name}", "Not needed anymore") + .then() + .statusCode(Response.Status.OK.getStatusCode()); + + assertThat(mockServer.getClient().resources(Integration.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()) + .extracting(Integration::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that Integration was created") + .containsExactly("integration"); + } + + @Test + void startInvalidTest() { + String response = given() + .when().body(getTestKameletBinding("../route-with-beans.yaml")) + .contentType("text/yaml") + .post("/{name}", "Not needed anymore") + .then() + .statusCode(Response.Status.BAD_REQUEST.getStatusCode()) + .extract().response().asString(); + assertThat(response).isEqualTo( + "Error processing deployment: Couldn't understand the yaml sent. Check the syntax and try again."); + } + + @Test + void startNamespaceQueryTest() { + assertThat(mockServer.getClient().resources(KameletBinding.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()).isEmpty(); + assertThat(mockServer.getClient().resources(KameletBinding.class).inNamespace(OTHER_NAMESPACE).list() + .getItems()).isEmpty(); + given() + .queryParam("namespace", OTHER_NAMESPACE) + .when().body(getTestKameletBinding("../twitter-search-source-binding.yaml")) + .contentType("text/yaml") + .post("/{name}", "Not needed anymore") + .then() + .statusCode(Response.Status.OK.getStatusCode()); + assertThat(mockServer.getClient().resources(KameletBinding.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()).isEmpty(); + assertThat(mockServer.getClient().resources(KameletBinding.class).inNamespace(OTHER_NAMESPACE).list() + .getItems()) + .extracting(KameletBinding::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet binding was created") + .containsExactly(BINDING_NAME); + } + @Test + void deleteExceptionsTest() { + String response = given() + .queryParam("type", "KameletBinding") + .when() + .get("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()) + .extract().body().asString(); + assertThat(response).isEqualTo( + String.format("Error processing deployment: Resource with name %s not found.", BINDING_NAME)); + response = given() + .when() + .delete("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.BAD_REQUEST.getStatusCode()) + .extract().body().asString(); + assertThat(response).isEqualTo("Error processing deployment: query parameter 'type' is required."); + } + + + @Test + void deleteTest() { + createTestKameletBinding(DEFAULT_NAMESPACE); + createTestKameletBinding(OTHER_NAMESPACE); + String differentKbName = createDifferentTestKameletBinding(DEFAULT_NAMESPACE); + String kameletName = createTestKamelet(DEFAULT_NAMESPACE); + + Boolean result = given() + .queryParam("type", "KameletBinding") + .when() + .delete("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().as(Boolean.class); + assertThat(result).isTrue(); + assertThat( + mockServer.getClient().resources(KameletBinding.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()) + .extracting(KameletBinding::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet binding was deleted") + .doesNotContain(BINDING_NAME) + .as("Check that other kamelet binding was not deleted") + .containsExactly(differentKbName); + assertThat( + mockServer.getClient().resources(Kamelet.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()) + .extracting(Kamelet::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet was not deleted") + .containsExactly(kameletName); + assertThat( + mockServer.getClient().resources(KameletBinding.class).inNamespace(OTHER_NAMESPACE).list() + .getItems()) + .extracting(KameletBinding::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet binding with the same name in different namespace was not deleted") + .containsExactly(BINDING_NAME); + } + + @Test + void deleteNamespaceAndTypeQueryTest() { + createTestKameletBinding(DEFAULT_NAMESPACE); + createTestKameletBinding(OTHER_NAMESPACE); + String differentKbName = createDifferentTestKameletBinding(OTHER_NAMESPACE); + String kameletName = createTestKamelet(OTHER_NAMESPACE); + + Boolean result = given() + .queryParam("namespace", OTHER_NAMESPACE) + .queryParam("type", "KameletBinding") + .when() + .delete("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.OK.getStatusCode()) + .extract().body().as(Boolean.class); + assertThat(result).isTrue(); + + assertThat( + mockServer.getClient().resources(KameletBinding.class).inNamespace(OTHER_NAMESPACE).list() + .getItems()) + .extracting(KameletBinding::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet binding was deleted from specified namespace") + .doesNotContain(BINDING_NAME) + .as("Check that other kamelet binding was not deleted from specified namespace") + .containsExactly(differentKbName); + assertThat( + mockServer.getClient().resources(Kamelet.class).inNamespace(OTHER_NAMESPACE).list() + .getItems()) + .extracting(Kamelet::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet was not deleted from specified namespace") + .containsExactly(kameletName); + assertThat( + mockServer.getClient().resources(KameletBinding.class).inNamespace(DEFAULT_NAMESPACE).list() + .getItems()) + .extracting(KameletBinding::getMetadata) + .extracting(ObjectMeta::getName) + .as("Check that kamelet binding with the same name in default namespace was not deleted") + .containsExactly(BINDING_NAME); + given() + .queryParam("namespace", OTHER_NAMESPACE) + .queryParam("type", "KameletBinding") + .when() + .delete("/{name}", BINDING_NAME) + .then() + .statusCode(Response.Status.NOT_FOUND.getStatusCode()); + } + + private void createTestKameletBinding(String namespace) { + mockServer.getClient().resources(KameletBinding.class).inNamespace(namespace) + .load(DeploymentsResourcesTestAbstract.class.getResourceAsStream( + "../twitter-search-source-binding.yaml")).create(); + } + + private String getTestKameletBinding(String pathToFileInResources) { + try { + return Files.readString(Path.of(Objects.requireNonNull( + DeploymentsResourcesTestAbstract.class.getResource(pathToFileInResources)).toURI())); + } catch (IOException | URISyntaxException e) { + throw new RuntimeException("Problem with processing kamelet binding file: " + e.getMessage()); + } + } + + private String createDifferentTestKameletBinding(String namespace) { + mockServer.getClient().resources(KameletBinding.class).inNamespace(namespace) + .load(DeploymentsResourcesTestAbstract.class.getResourceAsStream( + "../camel-conector-example.yaml")).create(); + return "camel-conector-example"; + } + + private String createTestKamelet(String namespace) { + mockServer.getClient().resources(Kamelet.class).inNamespace(namespace) + .load(DeploymentsResourcesTestAbstract.class.getResourceAsStream( + "../eip.kamelet.yaml")).create(); + return "eip-action"; + } + + private String createTestIntegration(String namespace) { + mockServer.getClient().resources(Integration.class).inNamespace(namespace) + .load(DeploymentsResourcesTestAbstract.class.getResourceAsStream( + "../integration.yaml")).create(); + return "integration"; + } +} diff --git a/api/src/test/resources/io/kaoto/backend/api/resource/integration.yaml b/api/src/test/resources/io/kaoto/backend/api/resource/integration.yaml new file mode 100644 index 000000000..662608d8d --- /dev/null +++ b/api/src/test/resources/io/kaoto/backend/api/resource/integration.yaml @@ -0,0 +1,15 @@ +apiVersion: camel.apache.org/v1 +kind: Integration +metadata: + name: integration +spec: + flows: + - from: + uri: timer:tick + parameters: + period: '5000' + steps: + - to: + uri: activemq:queue:myQueue + - to: + uri: log:save