summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java33
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java6
-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
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java7
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java41
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java26
7 files changed, 114 insertions, 53 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
index f294d47ff..f5fb03054 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
@@ -39,6 +39,7 @@ import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
+import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.common.utils.coder.Coder;
@@ -91,31 +92,37 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Override
public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
throws PfModelException {
- var configRequest = getConfigRequest(properties);
- var restResponseMap = invokeHttpClient(configRequest);
- var failedResponseStatus = restResponseMap.values().stream()
- .filter(response -> !HttpStatus.valueOf(response.getKey()).is2xxSuccessful())
- .collect(Collectors.toList());
- if (failedResponseStatus.isEmpty()) {
+ try {
+ var configRequest = getConfigRequest(properties);
+ var restResponseMap = invokeHttpClient(configRequest);
+ var failedResponseStatus = restResponseMap.values().stream()
+ .filter(response -> !HttpStatus.valueOf(response.getKey()).is2xxSuccessful())
+ .collect(Collectors.toList());
+ if (failedResponseStatus.isEmpty()) {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.DEPLOYED, null, "Deployed");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null, "Error on Invoking the http request: " + failedResponseStatus);
+ }
+ } catch (AutomationCompositionException e) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
- } else {
- throw new PfModelException(Status.BAD_REQUEST, "Error on Invoking the http request: {}",
- failedResponseStatus);
+ DeployState.UNDEPLOYED, null, e.getMessage());
}
}
- private ConfigRequest getConfigRequest(Map<String, Object> properties) throws PfModelException {
+ private ConfigRequest getConfigRequest(Map<String, Object> properties) throws AutomationCompositionException {
try {
var configRequest = CODER.convert(properties, ConfigRequest.class);
var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest);
if (!violations.isEmpty()) {
LOGGER.error("Violations found in the config request parameters: {}", violations);
- throw new PfModelException(Status.BAD_REQUEST, "Constraint violations in the config request");
+ throw new AutomationCompositionException(Status.BAD_REQUEST,
+ "Constraint violations in the config request");
}
return configRequest;
} catch (CoderException e) {
- throw new PfModelException(Status.BAD_REQUEST, "Error extracting ConfigRequest ", e);
+ throw new AutomationCompositionException(Status.BAD_REQUEST, "Error extracting ConfigRequest ", e);
}
}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java
index c71d73f22..a88f93aa5 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/webclient/AcHttpClient.java
@@ -38,6 +38,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
@@ -88,9 +89,12 @@ public class AcHttpClient {
new ImmutablePair<>(request.getExpectedResponse(), response));
} catch (HttpWebClientException ex) {
- LOGGER.error("Error occurred on the HTTP request ", ex);
+ LOGGER.error("Error occurred on the HTTP response ", ex);
responseMap.put(request.getRestRequestId(),
new ImmutablePair<>(ex.getStatusCode().value(), ex.getResponseBodyAsString()));
+ } catch (WebClientRequestException ex) {
+ LOGGER.error("Error occurred on the HTTP request ", ex);
+ responseMap.put(request.getRestRequestId(), new ImmutablePair<>(404, ex.getMessage()));
}
}
}
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));
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 627f79131..5eb997e52 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -154,7 +154,9 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
var automationCompositionDefinition = element.getToscaServiceTemplateFragment();
if (automationCompositionDefinition.getToscaTopologyTemplate() == null) {
- throw new PfModelException(Status.BAD_REQUEST, "ToscaTopologyTemplate not defined");
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null, "ToscaTopologyTemplate not defined");
+ return;
}
serviceTemplateMap.put(element.getId(), automationCompositionDefinition);
if (automationCompositionDefinition.getPolicyTypes() != null) {
@@ -174,7 +176,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
var policyList = getPolicyList(automationCompositionDefinition);
deployPolicies(policyList, automationCompositionId, element.getId());
} else {
- throw new PfModelException(Status.BAD_REQUEST,
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
+ DeployState.UNDEPLOYED, null,
"Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
}
}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java
index 5ba598cc8..1111f20b2 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java
@@ -22,7 +22,6 @@
package org.onap.policy.clamp.acm.participant.policy.endtoend;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Instant;
import java.util.Collections;
@@ -39,11 +38,9 @@ import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestDa
import org.onap.policy.clamp.acm.participant.policy.main.utils.TestListenerUtils;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.springframework.beans.factory.annotation.Autowired;
@@ -66,13 +63,12 @@ class ParticipantMessagesTest {
@Test
void testSendParticipantRegisterMessage() {
- final ParticipantRegister participantRegisterMsg = new ParticipantRegister();
+ final var participantRegisterMsg = new ParticipantRegister();
participantRegisterMsg.setParticipantId(CommonTestData.getParticipantId());
participantRegisterMsg.setTimestamp(Instant.now());
synchronized (lockit) {
- ParticipantMessagePublisher participantMessagePublisher =
- new ParticipantMessagePublisher();
+ var participantMessagePublisher = new ParticipantMessagePublisher();
participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
assertThatCode(() -> participantMessagePublisher.sendParticipantRegister(participantRegisterMsg))
.doesNotThrowAnyException();
@@ -81,14 +77,13 @@ class ParticipantMessagesTest {
@Test
void testReceiveParticipantRegisterAckMessage() {
- final ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck();
+ final var participantRegisterAckMsg = new ParticipantRegisterAck();
participantRegisterAckMsg.setMessage("ParticipantRegisterAck message");
participantRegisterAckMsg.setResponseTo(UUID.randomUUID());
participantRegisterAckMsg.setResult(true);
synchronized (lockit) {
- ParticipantRegisterAckListener participantRegisterAckListener =
- new ParticipantRegisterAckListener(participantHandler);
+ var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
assertThatCode(() -> participantRegisterAckListener.onTopicEvent(INFRA, TOPIC, null,
participantRegisterAckMsg)).doesNotThrowAnyException();
}
@@ -96,13 +91,12 @@ class ParticipantMessagesTest {
@Test
void testSendParticipantDeregisterMessage() {
- final ParticipantDeregister participantDeregisterMsg = new ParticipantDeregister();
+ final var participantDeregisterMsg = new ParticipantDeregister();
participantDeregisterMsg.setParticipantId(CommonTestData.getParticipantId());
participantDeregisterMsg.setTimestamp(Instant.now());
synchronized (lockit) {
- ParticipantMessagePublisher participantMessagePublisher =
- new ParticipantMessagePublisher();
+ var participantMessagePublisher = new ParticipantMessagePublisher();
participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
assertThatCode(() -> participantMessagePublisher.sendParticipantDeregister(participantDeregisterMsg))
.doesNotThrowAnyException();
@@ -111,14 +105,13 @@ class ParticipantMessagesTest {
@Test
void testReceiveParticipantDeregisterAckMessage() {
- final ParticipantDeregisterAck participantDeregisterAckMsg = new ParticipantDeregisterAck();
+ final var participantDeregisterAckMsg = new ParticipantDeregisterAck();
participantDeregisterAckMsg.setMessage("ParticipantDeregisterAck message");
participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
participantDeregisterAckMsg.setResult(true);
synchronized (lockit) {
- ParticipantDeregisterAckListener participantDeregisterAckListener =
- new ParticipantDeregisterAckListener(participantHandler);
+ var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
assertThatCode(() -> participantDeregisterAckListener.onTopicEvent(INFRA, TOPIC, null,
participantDeregisterAckMsg)).doesNotThrowAnyException();
}
@@ -126,26 +119,24 @@ class ParticipantMessagesTest {
@Test
void testReceiveParticipantUpdateMessage() {
- ParticipantPrime participantPrimeMsg = TestListenerUtils.createParticipantPrimeMsg();
+ var participantPrimeMsg = TestListenerUtils.createParticipantPrimeMsg();
synchronized (lockit) {
- ParticipantPrimeListener participantPrimeListener = new ParticipantPrimeListener(participantHandler);
- participantPrimeListener.onTopicEvent(INFRA, TOPIC, null, participantPrimeMsg);
+ var participantPrimeListener = new ParticipantPrimeListener(participantHandler);
+ assertThatCode(() -> participantPrimeListener.onTopicEvent(INFRA, TOPIC, null, participantPrimeMsg))
+ .doesNotThrowAnyException();
}
-
- // Verify the result of GET participants with what is stored
- assertEquals(CommonTestData.getParticipantId(), participantHandler.getParticipantId());
}
@Test
void testSendParticipantPrimeAckMessage() {
- final ParticipantPrimeAck participantPrimeAckMsg = new ParticipantPrimeAck();
+ final var participantPrimeAckMsg = new ParticipantPrimeAck();
participantPrimeAckMsg.setMessage("ParticipantPrimeAck message");
participantPrimeAckMsg.setResponseTo(UUID.randomUUID());
participantPrimeAckMsg.setResult(true);
synchronized (lockit) {
- ParticipantMessagePublisher participantMessagePublisher = new ParticipantMessagePublisher();
+ var participantMessagePublisher = new ParticipantMessagePublisher();
participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
assertThatCode(() -> participantMessagePublisher.sendParticipantPrimeAck(participantPrimeAckMsg))
.doesNotThrowAnyException();
@@ -154,9 +145,9 @@ class ParticipantMessagesTest {
@Test
void testParticipantStatusHeartbeat() {
- final ParticipantStatus heartbeat = participantHandler.makeHeartbeat(true);
+ final var heartbeat = participantHandler.makeHeartbeat(true);
synchronized (lockit) {
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
+ var publisher = new ParticipantMessagePublisher();
publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
assertThatCode(() -> publisher.sendHeartbeat(heartbeat)).doesNotThrowAnyException();
}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index d3b27ae10..4cf5a5847 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
@@ -53,7 +53,7 @@ class AutomationCompositionElementHandlerTest {
private static final ToscaConceptIdentifier DEFINITION = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
@Test
- void testHandlerUndeploy() throws PfModelException {
+ void testHandlerUndeployNoPolicy() throws PfModelException {
var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
mock(PolicyPapHttpClient.class));
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -94,6 +94,24 @@ class AutomationCompositionElementHandlerTest {
handler.deploy(AC_ID, getTestingAcElement(), Map.of());
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
DeployState.DEPLOYED, null, "Deployed");
+
+ handler.undeploy(AC_ID, automationCompositionElementId);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.UNDEPLOYED, null, "Undeployed");
+ }
+
+ @Test
+ void testDeployNoPolicy() throws PfModelException {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ var acElement = getTestingAcElement();
+ acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
+ handler.deploy(AC_ID, acElement, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.UNDEPLOYED, null, "ToscaTopologyTemplate not defined");
}
@Test
@@ -111,8 +129,10 @@ class AutomationCompositionElementHandlerTest {
var element = getTestingAcElement();
// Mock failure in policy type creation
- assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
- .hasMessageMatching("Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
+ handler.deploy(AC_ID, element, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.UNDEPLOYED, null,
+ "Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
}
@Test