aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-http/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-05-22 10:53:27 +0100
committerLiam Fallon <liam.fallon@est.tech>2023-05-23 15:25:11 +0000
commit290d7273d4df9f956c5e48284d09d306e31c706f (patch)
tree844b4a7d3cb1436ef6e1b2f3ae58eab06586ff69 /participant/participant-impl/participant-impl-http/src/test/java
parent4539ab951ef81839d38641fa09f2cbd490d71a63 (diff)
Refactor failure handling in http-participant
In the case, a http-participant fails to deploy an element, it should responds with UNDEPLOYED on a DEPLOY order. Issue-ID: POLICY-4694 Change-Id: I97d2660c7b91e4407ff3fa2cc51557b6c96a3a9e Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-http/src/test/java')
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java30
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/webclient/AcHttpClientTest.java24
2 files changed, 45 insertions, 9 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
index e0d6c805f..b0e05d709 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
@@ -20,7 +20,6 @@
package org.onap.policy.clamp.acm.participant.http.handler;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.mock;
@@ -37,6 +36,7 @@ import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData;
import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.models.base.PfModelException;
class AcElementHandlerTest {
@@ -61,16 +61,35 @@ class AcElementHandlerTest {
}
@Test
- void testDeployError() throws IOException {
+ void testDeployConstraintViolations() throws IOException, PfModelException {
var instanceId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
try (var automationCompositionElementHandler =
new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
- automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
Map<String, Object> map = new HashMap<>();
- assertThatThrownBy(() -> automationCompositionElementHandler.deploy(instanceId, element, map))
- .hasMessage("Constraint violations in the config request");
+ automationCompositionElementHandler.deploy(instanceId, element, map);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.UNDEPLOYED, null, "Constraint violations in the config request");
+ }
+ }
+
+ @Test
+ void testDeployError() throws IOException, PfModelException {
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var element = commonTestData.getAutomationCompositionElement();
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ Map<String, Object> map = new HashMap<>();
+ map.put("httpHeaders", 1);
+ automationCompositionElementHandler.deploy(instanceId, element, map);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.UNDEPLOYED, null, "Error extracting ConfigRequest ");
}
}
@@ -91,6 +110,5 @@ class AcElementHandlerTest {
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
DeployState.DEPLOYED, null, "Deployed");
}
-
}
}
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 d8e0c9b58..56170eb3e 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
@@ -47,7 +47,8 @@ class AcHttpClientTest {
private static int mockServerPort;
- private final String testMockUrl = "http://localhost";
+ private static final String MOCK_URL = "http://localhost";
+ private static final String WRONG_URL = "http://wrong-url";
private static MockServerRest mockServer;
@@ -76,7 +77,7 @@ class AcHttpClientTest {
var headers = commonTestData.getHeaders();
var configRequest =
- new ConfigRequest(testMockUrl + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
+ new ConfigRequest(MOCK_URL + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
var client = new AcHttpClient();
assertDoesNotThrow(() -> client.run(configRequest, responseMap));
@@ -94,7 +95,24 @@ class AcHttpClientTest {
var headers = commonTestData.getHeaders();
var configRequest =
- new ConfigRequest(testMockUrl + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
+ new ConfigRequest(MOCK_URL + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
+
+ var client = new AcHttpClient();
+ assertDoesNotThrow(() -> client.run(configRequest, responseMap));
+ assertThat(responseMap).hasSize(2).containsKey(commonTestData.restParamsWithGet().getRestRequestId());
+ var response = responseMap.get(commonTestData.restParamsWithInvalidPost().getRestRequestId());
+ assertThat(response.getKey()).isEqualTo(404);
+ }
+
+ @Test
+ void test_WrongUrl() {
+ // Add rest requests Invalid URL
+ var configurationEntity = commonTestData.getInvalidConfigurationEntity();
+ Map<ToscaConceptIdentifier, Pair<Integer, String>> responseMap = new HashMap<>();
+
+ var headers = commonTestData.getHeaders();
+ var configRequest =
+ new ConfigRequest(WRONG_URL + ":" + mockServerPort, headers, List.of(configurationEntity), 10);
var client = new AcHttpClient();
assertDoesNotThrow(() -> client.run(configRequest, responseMap));