diff --git a/addons/common/kubernetes-service-catalog/pom.xml b/addons/common/kubernetes-service-catalog/pom.xml index 58b06d68e4f..e0a99662be5 100644 --- a/addons/common/kubernetes-service-catalog/pom.xml +++ b/addons/common/kubernetes-service-catalog/pom.xml @@ -12,4 +12,17 @@ kogito-addons-kubernetes-service-catalog Kogito :: Add-Ons :: Kubernetes Service Catalog Common Library for Kubernetes Service Discovery implementations + + + + org.junit.jupiter + junit-jupiter + test + + + org.assertj + assertj-core + test + + \ No newline at end of file diff --git a/addons/common/kubernetes-service-catalog/src/test/java/org/kie/kogito/addons/k8s/resource/catalog/KubernetesServiceCatalogTest.java b/addons/common/kubernetes-service-catalog/src/test/java/org/kie/kogito/addons/k8s/resource/catalog/KubernetesServiceCatalogTest.java new file mode 100644 index 00000000000..c9622c96815 --- /dev/null +++ b/addons/common/kubernetes-service-catalog/src/test/java/org/kie/kogito/addons/k8s/resource/catalog/KubernetesServiceCatalogTest.java @@ -0,0 +1,114 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates. + * + * 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 org.kie.kogito.addons.k8s.resource.catalog; + +import java.net.URI; +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.KNATIVE; +import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.KUBERNETES; +import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.OPENSHIFT; + +/** + * Test classes for implementations of {@link KubernetesServiceCatalog} must extend this class. + * It tests all use cases an implementation of {@link KubernetesServiceCatalog} must cover. + */ +public abstract class KubernetesServiceCatalogTest { + + private static final String EXPECTED_KNATIVE_URI = "http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io"; + + private static final String EXPECTED_KUBERNETES_URI = "http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io"; + + private static final String EXPECTED_OPENSHIFT_URI = "http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io"; + + private static final String NAMESPACE = "test"; + + private static final String KNATIVE_SERVICENAME = "serverless-workflow-greeting-quarkus"; + + private static final String KUBERNETES_SERVICENAME = "serverless-workflow-greeting-quarkus-kubernetes"; + + private static final String OPENSHIFT_SERVICENAME = "serverless-workflow-greeting-quarkus-openshift"; + + private static final String NAMESPACE_KNATIVE_SERVICENAME = NAMESPACE + '/' + KNATIVE_SERVICENAME; + + private static final String NAMESPACE_KUBERNETES_SERVICENAME = NAMESPACE + '/' + KUBERNETES_SERVICENAME; + + private static final String NAMESPACE_OPENSHIFT_SERVICENAME = NAMESPACE + '/' + OPENSHIFT_SERVICENAME; + + private static final String GVK = "services.v1.serving.knative.dev"; + + private static final String GVK_KNATIVE_SERVICENAME = GVK + '/' + KNATIVE_SERVICENAME; + + private static final String GVK_NAMESPACE_SERVICENAME = GVK + '/' + NAMESPACE_KNATIVE_SERVICENAME; + + private static final String GVK_KUBERNETES_SERVICENAME = GVK + '/' + KUBERNETES_SERVICENAME; + + private static final String GVK_NAMESPACE_KUBERNETES_SERVICENAME = GVK + '/' + NAMESPACE_KUBERNETES_SERVICENAME; + + private static final String GVK_OPENSHIFT_SERVICENAME = GVK + '/' + OPENSHIFT_SERVICENAME; + + private static final String GVK_NAMESPACE_OPENSHIFT_SERVICENAME = GVK + '/' + NAMESPACE_OPENSHIFT_SERVICENAME; + + private final KubernetesServiceCatalog kubernetesServiceCatalog; + + protected KubernetesServiceCatalogTest(KubernetesServiceCatalog kubernetesServiceCatalog) { + this.kubernetesServiceCatalog = kubernetesServiceCatalog; + } + + protected final String getNamespace() { + return NAMESPACE; + } + + protected final String getKnativeServiceName() { + return KNATIVE_SERVICENAME; + } + + protected final String getKubernetesServiceName() { + return KUBERNETES_SERVICENAME; + } + + protected final String getOpenshiftServicename() { + return OPENSHIFT_SERVICENAME; + } + + @ParameterizedTest + @MethodSource("possibleUriFormats") + void getServiceAddress(KubernetesProtocol kubernetesProtocol, String coordinates, String expectedUri) { + KubernetesServiceCatalogKey key = new KubernetesServiceCatalogKey(kubernetesProtocol, coordinates); + assertThat(kubernetesServiceCatalog.getServiceAddress(key)) + .map(URI::toString) + .hasValue(expectedUri); + } + + protected static Stream possibleUriFormats() { + return Stream.of( + Arguments.of(KNATIVE, KNATIVE_SERVICENAME, EXPECTED_KNATIVE_URI), + Arguments.of(KNATIVE, NAMESPACE_KNATIVE_SERVICENAME, EXPECTED_KNATIVE_URI), + Arguments.of(KNATIVE, GVK_KNATIVE_SERVICENAME, EXPECTED_KNATIVE_URI), + Arguments.of(KNATIVE, GVK_NAMESPACE_SERVICENAME, EXPECTED_KNATIVE_URI), + + Arguments.of(KUBERNETES, GVK_KUBERNETES_SERVICENAME, EXPECTED_KUBERNETES_URI), + Arguments.of(KUBERNETES, GVK_NAMESPACE_KUBERNETES_SERVICENAME, EXPECTED_KUBERNETES_URI), + + Arguments.of(OPENSHIFT, GVK_OPENSHIFT_SERVICENAME, EXPECTED_OPENSHIFT_URI), + Arguments.of(OPENSHIFT, GVK_NAMESPACE_OPENSHIFT_SERVICENAME, EXPECTED_OPENSHIFT_URI)); + } +} \ No newline at end of file diff --git a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/pom.xml b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/pom.xml index 42c99a8df5e..4cf954e2df9 100644 --- a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/pom.xml +++ b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/pom.xml @@ -34,6 +34,13 @@ kubernetes-client + + org.kie.kogito + kogito-addons-kubernetes-service-catalog + ${project.version} + test-jar + test + io.quarkus quarkus-test-kubernetes-client diff --git a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/Fabric8KubernetesServiceCatalogTest.java b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/Fabric8KubernetesServiceCatalogTest.java new file mode 100644 index 00000000000..9e3d66eb770 --- /dev/null +++ b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/Fabric8KubernetesServiceCatalogTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates. + * + * 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 org.kie.kogito.addons.quarkus.fabric8.k8s.service.catalog; + +import javax.inject.Inject; + +import org.junit.jupiter.api.BeforeEach; +import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogTest; + +import io.fabric8.kubernetes.client.server.mock.KubernetesServer; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.kubernetes.client.KubernetesTestServer; +import io.quarkus.test.kubernetes.client.WithKubernetesTestServer; + +import static org.kie.kogito.addons.quarkus.k8s.test.utils.KnativeResourceDiscoveryTestUtil.createServiceIfNotExists; + +@QuarkusTest +@WithKubernetesTestServer +class Fabric8KubernetesServiceCatalogTest extends KubernetesServiceCatalogTest { + + @KubernetesTestServer + KubernetesServer mockServer; + + @BeforeEach + void beforeEach() { + createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", getNamespace(), getKnativeServiceName()); + createServiceIfNotExists(mockServer, "knative/quarkus-greeting-kubernetes.yaml", getNamespace(), getKubernetesServiceName()); + createServiceIfNotExists(mockServer, "knative/quarkus-greeting-openshift.yaml", getNamespace(), getOpenshiftServicename()); + } + + @Inject + Fabric8KubernetesServiceCatalogTest(Fabric8KubernetesServiceCatalog fabric8KubernetesServiceCatalog) { + super(fabric8KubernetesServiceCatalog); + } +} \ No newline at end of file diff --git a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/KnativeServiceDiscoveryTest.java b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/KnativeServiceDiscoveryTest.java index 217b7d6108e..e42ec2cf505 100644 --- a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/KnativeServiceDiscoveryTest.java +++ b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/fabric8/k8s/service/catalog/KnativeServiceDiscoveryTest.java @@ -45,7 +45,7 @@ class KnativeServiceDiscoveryTest { @Test void queryService() { String remoteServiceUrl = "http://" + REMOTE_SERVICE_HOST; - KnativeResourceDiscoveryTestUtil.createServiceIfNotExists(mockServer, remoteServiceUrl, "knative/quarkus-greeting.yaml", "test", "serverless-workflow-greeting-quarkus"); + KnativeResourceDiscoveryTestUtil.createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", "test", "serverless-workflow-greeting-quarkus", remoteServiceUrl); Optional uri = knativeServiceDiscovery.query(new KnativeServiceUri("test", "serverless-workflow-greeting-quarkus")); @@ -62,7 +62,7 @@ void queryService() { @Test void https() { String remoteServiceUrl = "https://" + REMOTE_SERVICE_HOST; - KnativeResourceDiscoveryTestUtil.createServiceIfNotExists(mockServer, remoteServiceUrl, "knative/quarkus-greeting-https.yaml", "test", "serverless-workflow-greeting-quarkus-https"); + KnativeResourceDiscoveryTestUtil.createServiceIfNotExists(mockServer, "knative/quarkus-greeting-https.yaml", "test", "serverless-workflow-greeting-quarkus-https", remoteServiceUrl); Optional url = knativeServiceDiscovery.query(new KnativeServiceUri("test", "serverless-workflow-greeting-quarkus-https")); diff --git a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-kubernetes.yaml b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-kubernetes.yaml new file mode 100644 index 00000000000..6a07c7fed5f --- /dev/null +++ b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-kubernetes.yaml @@ -0,0 +1,54 @@ +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + annotations: + serving.knative.dev/creator: minikube-user + serving.knative.dev/lastModifier: minikube-user + creationTimestamp: '2022-08-17T13:58:53Z' + generation: 1 + name: serverless-workflow-greeting-quarkus-kubernetes + resourceVersion: '43817' + uid: 98530cb6-3274-4d0c-b654-a82645cda058 +spec: + template: + metadata: + annotations: + client.knative.dev/updateTimestamp: '2022-08-17T13:58:53Z' + client.knative.dev/user-image: kiegroup/serverless-workflow-greeting-quarkus:1.0 + creationTimestamp: + spec: + containerConcurrency: 0 + containers: + - image: kiegroup/serverless-workflow-greeting-quarkus:1.0 + name: user-container + readinessProbe: + successThreshold: 1 + tcpSocket: + port: 0 + resources: { } + enableServiceLinks: false + timeoutSeconds: 300 + traffic: + - latestRevision: true + percent: 100 +status: + address: + url: http://serverless-workflow-greeting-quarkus.test.svc.cluster.local + conditions: + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: ConfigurationsReady + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: Ready + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: RoutesReady + latestCreatedRevisionName: serverless-workflow-greeting-quarkus-00001 + latestReadyRevisionName: serverless-workflow-greeting-quarkus-00001 + observedGeneration: 1 + traffic: + - latestRevision: true + percent: 100 + revisionName: serverless-workflow-greeting-quarkus-00001 + url: http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io diff --git a/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-openshift.yaml b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-openshift.yaml new file mode 100644 index 00000000000..3095b53773d --- /dev/null +++ b/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/test/resources/knative/quarkus-greeting-openshift.yaml @@ -0,0 +1,54 @@ +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + annotations: + serving.knative.dev/creator: minikube-user + serving.knative.dev/lastModifier: minikube-user + creationTimestamp: '2022-08-17T13:58:53Z' + generation: 1 + name: serverless-workflow-greeting-quarkus-openshift + resourceVersion: '43817' + uid: 98530cb6-3274-4d0c-b654-a82645cda058 +spec: + template: + metadata: + annotations: + client.knative.dev/updateTimestamp: '2022-08-17T13:58:53Z' + client.knative.dev/user-image: kiegroup/serverless-workflow-greeting-quarkus:1.0 + creationTimestamp: + spec: + containerConcurrency: 0 + containers: + - image: kiegroup/serverless-workflow-greeting-quarkus:1.0 + name: user-container + readinessProbe: + successThreshold: 1 + tcpSocket: + port: 0 + resources: { } + enableServiceLinks: false + timeoutSeconds: 300 + traffic: + - latestRevision: true + percent: 100 +status: + address: + url: http://serverless-workflow-greeting-quarkus.test.svc.cluster.local + conditions: + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: ConfigurationsReady + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: Ready + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: RoutesReady + latestCreatedRevisionName: serverless-workflow-greeting-quarkus-00001 + latestReadyRevisionName: serverless-workflow-greeting-quarkus-00001 + observedGeneration: 1 + traffic: + - latestRevision: true + percent: 100 + revisionName: serverless-workflow-greeting-quarkus-00001 + url: http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io diff --git a/quarkus/addons/fabric8-kubernetes-service-catalog/test-utils/src/main/java/org/kie/kogito/addons/quarkus/k8s/test/utils/KnativeResourceDiscoveryTestUtil.java b/quarkus/addons/fabric8-kubernetes-service-catalog/test-utils/src/main/java/org/kie/kogito/addons/quarkus/k8s/test/utils/KnativeResourceDiscoveryTestUtil.java index 30f90e09274..c156609e027 100644 --- a/quarkus/addons/fabric8-kubernetes-service-catalog/test-utils/src/main/java/org/kie/kogito/addons/quarkus/k8s/test/utils/KnativeResourceDiscoveryTestUtil.java +++ b/quarkus/addons/fabric8-kubernetes-service-catalog/test-utils/src/main/java/org/kie/kogito/addons/quarkus/k8s/test/utils/KnativeResourceDiscoveryTestUtil.java @@ -26,8 +26,12 @@ public final class KnativeResourceDiscoveryTestUtil { private KnativeResourceDiscoveryTestUtil() { } + public static void createServiceIfNotExists(KubernetesServer k8sServer, String knativeYaml, String namespace, String serviceName) { + createServiceIfNotExists(k8sServer, knativeYaml, namespace, serviceName, null); + } + @SuppressWarnings("deprecation") // Quarkus LTS 2.13 compatibility - public static void createServiceIfNotExists(KubernetesServer k8sServer, String remoteServiceUrl, String knativeYaml, String namespace, String serviceName) { + public static void createServiceIfNotExists(KubernetesServer k8sServer, String knativeYaml, String namespace, String serviceName, String remoteServiceUrl) { if (k8sServer.getClient().services().inNamespace("test").withName(serviceName).get() == null) { KnativeClient knativeClient = k8sServer.getClient().adapt(KnativeClient.class); @@ -36,7 +40,9 @@ public static void createServiceIfNotExists(KubernetesServer k8sServer, String r .load(getResourceAsStream(knativeYaml)) .get(); - service.getStatus().setUrl(remoteServiceUrl); + if (remoteServiceUrl != null) { + service.getStatus().setUrl(remoteServiceUrl); + } // ItemWritableOperation#create is deprecated. However, we can't use the new method while Quarkus LTS is not greater than 2.16. knativeClient.services().inNamespace(namespace).create(service); diff --git a/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/KnativeServerlessWorkflowCustomFunctionTest.java b/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/KnativeServerlessWorkflowCustomFunctionTest.java index 2e0c9ed8887..45344199c48 100644 --- a/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/KnativeServerlessWorkflowCustomFunctionTest.java +++ b/quarkus/addons/knative/serving/runtime/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/KnativeServerlessWorkflowCustomFunctionTest.java @@ -18,7 +18,6 @@ import java.time.Instant; import java.util.List; import java.util.Map; -import java.util.stream.Stream; import javax.inject.Inject; @@ -27,9 +26,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import org.kie.kogito.event.cloudevents.utils.InvalidCloudEventException; import org.kie.kogito.process.workitem.WorkItemExecutionException; import org.kie.kogito.serverless.workflow.SWFConstants; @@ -73,14 +69,6 @@ class KnativeServerlessWorkflowCustomFunctionTest { private static final String SERVICENAME = "serverless-workflow-greeting-quarkus"; - private static final String NAMESPACE_SERVICENAME = NAMESPACE + '/' + SERVICENAME; - - private static final String GVK = "services.v1.serving.knative.dev"; - - private static final String GVK_SERVICENAME = GVK + '/' + SERVICENAME; - - private static final String GVK_NAMESPACE_SERVICENAME = GVK + '/' + NAMESPACE_SERVICENAME; - private static final String CLOUD_EVENT_PATH = "/cloud-event"; private static String remoteServiceUrl; @@ -103,7 +91,7 @@ static void beforeAll() { @BeforeEach void beforeEach() { - createServiceIfNotExists(mockServer, remoteServiceUrl, "knative/quarkus-greeting.yaml", NAMESPACE, SERVICENAME); + createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", NAMESPACE, SERVICENAME, remoteServiceUrl); } @AfterAll @@ -191,12 +179,11 @@ private void mockExecuteWithEmptyParametersEndpoint() { .put("project", "Kogito")))); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithEmptyParameters(String operation) { + @Test + void executeWithEmptyParameters() { mockExecuteWithEmptyParametersEndpoint(); - JsonNode output = knativeServerlessWorkflowCustomFunction.execute("unused", operation, Map.of()); + JsonNode output = knativeServerlessWorkflowCustomFunction.execute("unused", SERVICENAME, Map.of()); JsonNode expected = JsonNodeFactory.instance.objectNode() .put("org", "Acme") @@ -205,16 +192,15 @@ void executeWithEmptyParameters(String operation) { assertThat(output).isEqualTo(expected); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithParameters(String operation) { + @Test + void executeWithParameters() { mockExecuteWithParametersEndpoint(); Map parameters = Map.of( "org", "Acme", "project", "Kogito"); - JsonNode output = knativeServerlessWorkflowCustomFunction.execute(UNUSED, operation, parameters); + JsonNode output = knativeServerlessWorkflowCustomFunction.execute(UNUSED, SERVICENAME, parameters); JsonNode expected = JsonNodeFactory.instance.objectNode() .put("message", "Kogito is awesome!") @@ -225,17 +211,15 @@ void executeWithParameters(String operation) { assertThat(output).hasToString(expected.toString()); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithArray(String operation) { + @Test + void executeWithArray() { mockExecuteWithArray(); - assertThat(knativeServerlessWorkflowCustomFunction.execute(UNUSED, operation, Map.of( + assertThat(knativeServerlessWorkflowCustomFunction.execute(UNUSED, SERVICENAME, Map.of( SWFConstants.CONTENT_DATA, List.of("Javierito", "Pepito")))).hasToString(JsonNodeFactory.instance.arrayNode().add(23).add(24).toString()); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithCloudEventWithIdAsPlainJson(String operation) { + @Test + void executeWithCloudEventWithIdAsPlainJson() { mockExecuteWithParametersEndpoint(); Map cloudEvent = Map.of( @@ -250,13 +234,12 @@ void executeWithCloudEventWithIdAsPlainJson(String operation) { String processInstanceId = Instant.now().toString(); assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(processInstanceId, operation, cloudEvent)) + .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(processInstanceId, SERVICENAME, cloudEvent)) .withMessage(CLOUDEVENT_SENT_AS_PLAIN_JSON_ERROR_MESSAGE); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithCloudEventWithoutIdAsPlainJson(String operation) { + @Test + void executeWithCloudEventWithoutIdAsPlainJson() { mockExecuteWithParametersEndpoint(); Map cloudEvent = Map.of( @@ -270,13 +253,12 @@ void executeWithCloudEventWithoutIdAsPlainJson(String operation) { String processInstanceId = Instant.now().toString(); assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(processInstanceId, operation, cloudEvent)) + .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(processInstanceId, SERVICENAME, cloudEvent)) .withMessage(CLOUDEVENT_SENT_AS_PLAIN_JSON_ERROR_MESSAGE); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithCloudEventThatHasOnlyIdMissingAsPlainJson(String operation) { + @Test + void executeWithCloudEventThatHasOnlyIdMissingAsPlainJson() { mockExecuteWithParametersEndpoint(); Map cloudEvent = Map.of( @@ -290,13 +272,12 @@ void executeWithCloudEventThatHasOnlyIdMissingAsPlainJson(String operation) { String processInstanceId = Instant.now().toString(); assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(processInstanceId, operation, cloudEvent)) + .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(processInstanceId, SERVICENAME, cloudEvent)) .withMessage(CLOUDEVENT_SENT_AS_PLAIN_JSON_ERROR_MESSAGE); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeCloudEvent(String operation) { + @Test + void executeCloudEvent() { mockExecuteCloudEventWithParametersEndpoint(); String source = "https://localhost:8080"; @@ -313,7 +294,7 @@ void executeCloudEvent(String operation) { String processInstanceId = Instant.now().toString(); JsonNode output = knativeServerlessWorkflowCustomFunction.execute( - processInstanceId, operation + "?asCloudEvent=true&path=" + CLOUD_EVENT_PATH, cloudEvent); + processInstanceId, SERVICENAME + "?asCloudEvent=true&path=" + CLOUD_EVENT_PATH, cloudEvent); JsonNode expected = JsonNodeFactory.instance.objectNode() .put("message", "CloudEvents are awesome!") @@ -363,12 +344,11 @@ void executeWithInvalidCloudEvent() { .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(UNUSED, operation, cloudEvent)); } - @ParameterizedTest - @MethodSource("possibleUriFormats") - void executeWithQueryParameters(String operation) { + @Test + void executeWithQueryParameters() { mockExecuteWithQueryParametersEndpoint(); - JsonNode output = knativeServerlessWorkflowCustomFunction.execute(UNUSED, operation + "?path=/hello", Map.of()); + JsonNode output = knativeServerlessWorkflowCustomFunction.execute(UNUSED, SERVICENAME + "?path=/hello", Map.of()); JsonNode expected = JsonNodeFactory.instance.objectNode() .put("message", "Hello Kogito"); @@ -401,12 +381,4 @@ void executeTimeout() { assertThatExceptionOfType(TimeoutException.class) .isThrownBy(() -> knativeServerlessWorkflowCustomFunction.execute(UNUSED, operation, payload)); } - - private static Stream possibleUriFormats() { - return Stream.of( - Arguments.of(SERVICENAME), - Arguments.of(NAMESPACE_SERVICENAME), - Arguments.of(GVK_SERVICENAME), - Arguments.of(GVK_NAMESPACE_SERVICENAME)); - } } diff --git a/quarkus/addons/kubernetes/runtime/src/test/java/org/kie/kogito/addons/quarkus/k8s/config/KubeDiscoveryConfigCacheUpdaterTest.java b/quarkus/addons/kubernetes/runtime/src/test/java/org/kie/kogito/addons/quarkus/k8s/config/KubeDiscoveryConfigCacheUpdaterTest.java index 7d3d4963746..21bfd13d422 100644 --- a/quarkus/addons/kubernetes/runtime/src/test/java/org/kie/kogito/addons/quarkus/k8s/config/KubeDiscoveryConfigCacheUpdaterTest.java +++ b/quarkus/addons/kubernetes/runtime/src/test/java/org/kie/kogito/addons/quarkus/k8s/config/KubeDiscoveryConfigCacheUpdaterTest.java @@ -47,7 +47,7 @@ class KubeDiscoveryConfigCacheUpdaterTest { @BeforeEach void beforeEach() { - createServiceIfNotExists(mockServer, remoteServiceUrl, "knative/quarkus-greeting.yaml", "test", "serverless-workflow-greeting-quarkus"); + createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", "test", "serverless-workflow-greeting-quarkus", remoteServiceUrl); kubeDiscoveryConfigCacheUpdater = new KubeDiscoveryConfigCacheUpdater(kubernetesServiceCatalog); }