aboutsummaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-impl/participant-impl-acelement/pom.xml2
-rw-r--r--participant/participant-impl/participant-impl-cds/pom.xml2
-rw-r--r--participant/participant-impl/participant-impl-http/pom.xml2
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockRestEndpoint.java66
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockServerRest.java65
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java70
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/pom.xml2
-rw-r--r--participant/participant-impl/participant-impl-policy/pom.xml2
-rw-r--r--participant/participant-impl/pom.xml2
-rw-r--r--participant/participant-intermediary/pom.xml2
-rw-r--r--participant/pom.xml2
11 files changed, 162 insertions, 55 deletions
diff --git a/participant/participant-impl/participant-impl-acelement/pom.xml b/participant/participant-impl/participant-impl-acelement/pom.xml
index 0a3087ae0..e6e5eb9d7 100644
--- a/participant/participant-impl/participant-impl-acelement/pom.xml
+++ b/participant/participant-impl/participant-impl-acelement/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant-impl</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-acm-element-impl</artifactId>
diff --git a/participant/participant-impl/participant-impl-cds/pom.xml b/participant/participant-impl/participant-impl-cds/pom.xml
index 5acbb1750..3beb75a49 100644
--- a/participant/participant-impl/participant-impl-cds/pom.xml
+++ b/participant/participant-impl/participant-impl-cds/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant-impl</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-impl-cds</artifactId>
diff --git a/participant/participant-impl/participant-impl-http/pom.xml b/participant/participant-impl/participant-impl-http/pom.xml
index 2ab11320b..06a0caa66 100644
--- a/participant/participant-impl/participant-impl-http/pom.xml
+++ b/participant/participant-impl/participant-impl-http/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant-impl</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-impl-http</artifactId>
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockRestEndpoint.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockRestEndpoint.java
new file mode 100644
index 000000000..037e62986
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockRestEndpoint.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.http.utils;
+
+import java.util.List;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+/**
+ * The Class MockRestEndpoint creates rest server endpoints for simulating Rest calls.
+ */
+@Path("/")
+@Produces("application/json")
+public class MockRestEndpoint {
+
+ /**
+ * Get dummy endpoint.
+ *
+ * @param name the name
+ * @param version the version
+ * @return the response
+ */
+ @Path("get")
+ @GET
+ public Response getMessages(@QueryParam("name") String name, @QueryParam("version") String version) {
+ String createRequest = "dummy body";
+ return Response.status(200).entity(List.of(createRequest)).build();
+ }
+
+ /**
+ * Post dummy endpoint.
+ *
+ * @param name the name
+ * @param version the version
+ * @param jsonString the message
+ * @return the response
+ */
+ @Path("post")
+ @POST
+ public Response policyMessage(@QueryParam("name") String name, @QueryParam("version") String version,
+ final String jsonString) {
+ return Response.status(200).build();
+ }
+}
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockServerRest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockServerRest.java
new file mode 100644
index 000000000..1ac52124a
--- /dev/null
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/MockServerRest.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.participant.http.utils;
+
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.utils.network.NetworkUtil;
+
+/**
+ * The Class MockServerRest that manages test servers for REST requests for the test.
+ */
+public class MockServerRest implements AutoCloseable {
+ private static final String HOST = "localhost";
+ private HttpServletServer restServer;
+ private int restServerPort = 0;
+
+ /**
+ * Instantiates a new REST simulator.
+ */
+ public MockServerRest(int restServerPort) {
+ this.restServerPort = restServerPort;
+ restServer = HttpServletServerFactoryInstance.getServerFactory().build("MockRestEndpoint", false, HOST,
+ restServerPort, "/", false, false);
+ restServer.addServletClass(null, MockRestEndpoint.class.getName());
+ restServer.setSerializationProvider(GsonMessageBodyHandler.class.getName());
+ restServer.start();
+ }
+
+ /**
+ * Validate the Rest server.
+ * @throws InterruptedException if is not alive
+ */
+ public void validate() throws InterruptedException {
+ if (!NetworkUtil.isTcpPortOpen(HOST, restServerPort, 50, 200L)) {
+ throw new IllegalStateException("port " + restServerPort + " is still not in use");
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (restServer != null) {
+ restServer.stop();
+ restServer = null;
+ }
+ }
+}
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java
index e0a04a12a..3ddd7b17c 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java
@@ -22,26 +22,20 @@ package org.onap.policy.clamp.acm.participant.http.webclient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.mockserver.model.HttpRequest.request;
-import static org.mockserver.model.HttpResponse.response;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.ws.rs.core.MediaType;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockserver.integration.ClientAndServer;
-import org.mockserver.model.Parameter;
import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
-import org.onap.policy.clamp.acm.participant.http.main.models.ConfigurationEntity;
import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData;
+import org.onap.policy.clamp.acm.participant.http.utils.MockServerRest;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -55,75 +49,57 @@ class AcHttpClientTest {
private final String testMockUrl = "http://localhost";
- private static ClientAndServer mockServer;
+ private static MockServerRest mockServer;
/**
* Set up Mock server.
*/
@BeforeAll
- static void setUpMockServer() throws IOException {
+ static void setUpMockServer() throws IOException, InterruptedException {
mockServerPort = NetworkUtil.allocPort();
- mockServer = ClientAndServer.startClientAndServer(mockServerPort);
+ mockServer = new MockServerRest(mockServerPort);
+ mockServer.validate();
commonTestData = new CommonTestData();
- List<Parameter> queryParams = new ArrayList<>();
- commonTestData.getQueryParams().forEach((k, v) -> queryParams.add(new Parameter(k, v)));
-
- mockServer.when(request().withMethod("GET").withPath("/get")
- .withHeader("Content-type", MediaType.APPLICATION_JSON)
- .withHeader("Accept", MediaType.APPLICATION_JSON).withQueryStringParameters(queryParams))
- .respond(response().withBody("dummy body").withStatusCode(200)
- .withHeader("Content-Type", MediaType.APPLICATION_JSON));
-
- mockServer.when(request().withMethod("POST").withPath("/post")
- .withHeader("Content-type", MediaType.APPLICATION_JSON)
- .withHeader("Accept", MediaType.APPLICATION_JSON).withQueryStringParameters(queryParams)
- .withBody("Test body"))
- .respond(response().withStatusCode(200));
}
@AfterAll
- public static void stopServer() {
- mockServer.stop();
+ public static void stopServer() throws Exception {
+ mockServer.close();
mockServer = null;
}
-
@Test
void test_validRequest() {
- //Add valid rest requests POST, GET
- ConfigurationEntity configurationEntity = commonTestData.getConfigurationEntity();
+ // Add valid rest requests POST, GET
+ var configurationEntity = commonTestData.getConfigurationEntity();
Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap = new HashMap<>();
- Map<String, String> headers = commonTestData.getHeaders();
- ConfigRequest configRequest = new ConfigRequest(testMockUrl + ":" + mockServerPort, headers,
- List.of(configurationEntity), 10);
+ var headers = commonTestData.getHeaders();
+ var configRequest =
+ new ConfigRequest(testMockUrl + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
- AcHttpClient client = new AcHttpClient(configRequest, responseMap);
+ var client = new AcHttpClient(configRequest, responseMap);
assertDoesNotThrow(client::run);
- assertThat(responseMap).hasSize(2).containsKey(commonTestData
- .restParamsWithGet().getRestRequestId());
+ assertThat(responseMap).hasSize(2).containsKey(commonTestData.restParamsWithGet().getRestRequestId());
- Pair<Integer, String> restResponseMap = responseMap.get(commonTestData
- .restParamsWithGet().getRestRequestId());
+ var restResponseMap = responseMap.get(commonTestData.restParamsWithGet().getRestRequestId());
assertThat(restResponseMap.getKey()).isEqualTo(200);
}
@Test
void test_invalidRequest() {
- //Add rest requests Invalid POST, Valid GET
- ConfigurationEntity configurationEntity = commonTestData.getInvalidConfigurationEntity();
+ // Add rest requests Invalid POST, Valid GET
+ var configurationEntity = commonTestData.getInvalidConfigurationEntity();
Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap = new HashMap<>();
- Map<String, String> headers = commonTestData.getHeaders();
- ConfigRequest configRequest = new ConfigRequest(testMockUrl + ":" + mockServerPort, headers,
- List.of(configurationEntity), 10);
+ var headers = commonTestData.getHeaders();
+ var configRequest =
+ new ConfigRequest(testMockUrl + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
- AcHttpClient client = new AcHttpClient(configRequest, responseMap);
+ var client = new AcHttpClient(configRequest, responseMap);
assertDoesNotThrow(client::run);
- assertThat(responseMap).hasSize(2).containsKey(commonTestData
- .restParamsWithGet().getRestRequestId());
- Pair<Integer, String> response = responseMap
- .get(commonTestData.restParamsWithInvalidPost().getRestRequestId());
+ assertThat(responseMap).hasSize(2).containsKey(commonTestData.restParamsWithGet().getRestRequestId());
+ var response = responseMap.get(commonTestData.restParamsWithInvalidPost().getRestRequestId());
assertThat(response.getKey()).isEqualTo(404);
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/pom.xml b/participant/participant-impl/participant-impl-kubernetes/pom.xml
index 47a0acbc4..29c139ffe 100644
--- a/participant/participant-impl/participant-impl-kubernetes/pom.xml
+++ b/participant/participant-impl/participant-impl-kubernetes/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant-impl</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-impl-kubernetes</artifactId>
diff --git a/participant/participant-impl/participant-impl-policy/pom.xml b/participant/participant-impl/participant-impl-policy/pom.xml
index c8fe79ed7..bb83dda8b 100644
--- a/participant/participant-impl/participant-impl-policy/pom.xml
+++ b/participant/participant-impl/participant-impl-policy/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant-impl</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-impl-policy</artifactId>
diff --git a/participant/participant-impl/pom.xml b/participant/participant-impl/pom.xml
index c75c8c7bd..772509cdb 100644
--- a/participant/participant-impl/pom.xml
+++ b/participant/participant-impl/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-impl</artifactId>
diff --git a/participant/participant-intermediary/pom.xml b/participant/participant-intermediary/pom.xml
index da02544de..6ce2b6698 100644
--- a/participant/participant-intermediary/pom.xml
+++ b/participant/participant-intermediary/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-intermediary</artifactId>
diff --git a/participant/pom.xml b/participant/pom.xml
index 7f5a89ae1..6eda29191 100644
--- a/participant/pom.xml
+++ b/participant/pom.xml
@@ -26,7 +26,7 @@
<parent>
<groupId>org.onap.policy.clamp</groupId>
<artifactId>policy-clamp</artifactId>
- <version>6.3.0-SNAPSHOT</version>
+ <version>6.3.1-SNAPSHOT</version>
</parent>
<groupId>org.onap.policy.clamp.participant</groupId>