Skip to content

Commit

Permalink
KOGITO-9145 Added prefix to config property and added integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Helber Belmiro <[email protected]>
  • Loading branch information
hbelmiro committed Aug 17, 2023
1 parent 2ffab7e commit 73ec3e5
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,10 @@
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-kubernetes</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand All @@ -81,16 +68,6 @@
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-fabric8-kubernetes-service-catalog-test-utils</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"id": "emptyParamsKnativeFunction",
"version": "1.0",
"name": "Test Knative function",
"description": "This workflow tests a Knative function",
"start": "invokeFunction",
"functions": [
{
"name": "greet",
"type": "custom",
"operation": "knative:services.v1.serving.knative.dev/default/serverless-workflow-greeting-quarkus?path=/emptyParamsKnativeFunction"
}
],
"states": [
{
"name": "invokeFunction",
"type": "operation",
"actions": [
{
"functionRef": {
"refName": "greet"
}
}
],
"end": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,21 @@

import java.net.HttpURLConnection;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;

import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import io.restassured.http.ContentType;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.kie.kogito.addons.quarkus.k8s.test.utils.KnativeResourceDiscoveryTestUtil.createServiceIfNotExists;

@QuarkusTest
@WithKubernetesTestServer
@QuarkusTestResource(ServiceMock.class)
class MicroProfileConfigServiceAddonIT {

private static final String NAMESPACE = "default";

private static final String SERVICENAME = "serverless-workflow-greeting-quarkus";

private static WireMockServer wireMockServer;

private static String remoteServiceUrl;

@KubernetesTestServer
KubernetesServer mockServer;

@BeforeAll
static void beforeAll() {
createWiremockServer();
}

@BeforeEach
void beforeEach() {
createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", NAMESPACE, SERVICENAME, remoteServiceUrl);
}

@AfterAll
static void afterAll() {
if (wireMockServer != null) {
wireMockServer.stop();
}
}

@Test
void executeWithEmptyParameters() {
mockExecuteWithEmptyParametersEndpoint();

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
Expand All @@ -85,20 +42,4 @@ void executeWithEmptyParameters() {
.body("workflowdata.org", is("Acme"))
.body("workflowdata.project", is("Kogito"));
}

private void mockExecuteWithEmptyParametersEndpoint() {
wireMockServer.stubFor(post(urlEqualTo("/emptyParamsKnativeFunction"))
.willReturn(aResponse()
.withStatus(HttpURLConnection.HTTP_OK)
.withHeader("Content-Type", "application/json")
.withJsonBody(JsonNodeFactory.instance.objectNode()
.put("org", "Acme")
.put("project", "Kogito"))));
}

private static void createWiremockServer() {
wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort());
wireMockServer.start();
remoteServiceUrl = wireMockServer.baseUrl();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.microprofile.config.service.catalog.it;

import java.net.HttpURLConnection;
import java.util.Map;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.github.tomakehurst.wiremock.WireMockServer;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;

public class ServiceMock implements QuarkusTestResourceLifecycleManager {

private WireMockServer wireMockServer;

@Override
public Map<String, String> start() {
wireMockServer = new WireMockServer(8089);
wireMockServer.start();

wireMockServer.stubFor(post(urlEqualTo("/emptyParamsKnativeFunction"))
.willReturn(aResponse()
.withStatus(HttpURLConnection.HTTP_OK)
.withHeader("Content-Type", "application/json")
.withJsonBody(JsonNodeFactory.instance.objectNode()
.put("org", "Acme")
.put("project", "Kogito"))));

return Map.of("serverMockUrl", wireMockServer.baseUrl());
}

@Override
public void stop() {
if (wireMockServer != null) {
wireMockServer.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.kie.kogito.addons.discovery.knative\:services.v1.serving.knative.dev\/default\/serverless-workflow-greeting-quarkus=${serverMockUrl}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
@ApplicationScoped
public class MicroProfileConfigServiceCatalog implements KubernetesServiceCatalog {

private static final String CONFIG_PREFIX = "org.kie.kogito.addons.discovery.";

@Inject
Config config;

@Override
public Optional<URI> getServiceAddress(KubernetesServiceCatalogKey key) {

return config.getOptionalValue(key.getProtocol().getValue() + ":" + key.getCoordinates(), String.class)
return config.getOptionalValue(CONFIG_PREFIX + key.getProtocol().getValue() + ":" + key.getCoordinates(), String.class)
.map(URI::create);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# limitations under the License.
#

knative\:serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
knative\:test\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
knative\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
knative\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.knative\:serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.knative\:test\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.knative\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.knative\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io

kubernetes\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus-kubernetes = http\:\/\/serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io
kubernetes\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus-kubernetes = http\:\/\/serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.kubernetes\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus-kubernetes = http\:\/\/serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.kubernetes\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus-kubernetes = http\:\/\/serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io

openshift\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus-openshift = http\:\/\/serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io
openshift\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus-openshift = http\:\/\/serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.openshift\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus-openshift = http\:\/\/serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io
org.kie.kogito.addons.discovery.openshift\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus-openshift = http\:\/\/serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io

0 comments on commit 73ec3e5

Please sign in to comment.