summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-11-15 17:03:34 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2022-11-18 08:57:36 +0000
commita2e99e7df02837d8270228c330bed4915043b996 (patch)
tree2864318cdd99e18fd1cbb2322318b3e89fe7454c /runtime-acm/src/test
parent5f72a385593d3ca906c8f3a6c382db213fce206c (diff)
Link the existing CommissioningController with the generated code
Link the existing CommissioningController endpoint implementation code with the generated code in Acm. Issue-ID: POLICY-4454 Change-Id: Ie10296b6af8c8bfdbfa7f54714b22ca4804a2eef Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java109
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java118
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java238
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java16
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java16
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java16
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java10
7 files changed, 213 insertions, 310 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index 4058c68b6..dabb05347 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -22,7 +22,6 @@
package org.onap.policy.clamp.acm.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -30,23 +29,18 @@ import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVIC
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
-import org.onap.policy.common.utils.coder.Coder;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class CommissioningProviderTest {
- private static final Coder CODER = new StandardCoder();
-
/**
* Test the fetching of automation composition definitions (ToscaServiceTemplates).
*
@@ -56,18 +50,17 @@ class CommissioningProviderTest {
void testGetAutomationCompositionDefinitions() throws Exception {
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
- List<ToscaNodeTemplate> listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
+ var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
+ assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
- when(acProvider.getFilteredNodeTemplates(any()))
- .thenReturn(List.of(new ToscaNodeTemplate(), new ToscaNodeTemplate()));
- listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
+ when(acDefinitionProvider.getServiceTemplateList(null, null))
+ .thenReturn(List.of(new ToscaServiceTemplate()));
+ serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
+ assertThat(serviceTemplates.getServiceTemplates()).hasSize(1);
}
/**
@@ -77,29 +70,21 @@ class CommissioningProviderTest {
*/
@Test
void testCreateAutomationCompositionDefinitions() throws Exception {
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
- var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
-
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
-
- List<ToscaNodeTemplate> listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).isEmpty();
-
- ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setServiceTemplate(serviceTemplate);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition);
// Response should return the number of node templates present in the service template
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var participantProvider = mock(ParticipantProvider.class);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
List<ToscaConceptIdentifier> affectedDefinitions = provider
.createAutomationCompositionDefinitions(serviceTemplate).getAffectedAutomationCompositionDefinitions();
+ verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
assertThat(affectedDefinitions).hasSize(13);
-
- when(acProvider.getFilteredNodeTemplates(any()))
- .thenReturn(List.of(new ToscaNodeTemplate(), new ToscaNodeTemplate()));
-
- listOfTemplates = provider.getAutomationCompositionDefinitions(null, null);
- assertThat(listOfTemplates).hasSize(2);
}
/**
@@ -108,56 +93,18 @@ class CommissioningProviderTest {
*
*/
@Test
- void testGetToscaServiceTemplate() throws Exception {
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
+ void testGetToscaServiceTemplateList() throws Exception {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
+ var provider =
+ new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
- when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
-
- provider.createAutomationCompositionDefinitions(serviceTemplate);
- verify(serviceTemplateProvider).createServiceTemplate(serviceTemplate);
-
- when(serviceTemplateProvider.getToscaServiceTemplate(null, null)).thenReturn(serviceTemplate);
+ when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
- ToscaServiceTemplate returnedServiceTemplate = provider.getToscaServiceTemplate(null, null);
+ var returnedServiceTemplate = provider.getAutomationCompositionDefinitions(null, null);
assertThat(returnedServiceTemplate).isNotNull();
-
- Map<String, ToscaNodeTemplate> nodeTemplates =
- returnedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
-
- assertThat(nodeTemplates).hasSize(7);
- }
-
- /**
- * Test the fetching of a reduced ToscaServiceTemplate with only some of the objects from the full template.
- * The reduced template does not contain: DataTypesAsMap or PolicyTypesAsMap.
- *
- */
- @Test
- void testGetToscaServiceTemplateReduced() throws Exception {
- var serviceTemplateProvider = mock(ServiceTemplateProvider.class);
- var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
-
- CommissioningProvider provider =
- new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider);
- ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
- when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
-
- provider.createAutomationCompositionDefinitions(serviceTemplate);
-
- when(serviceTemplateProvider.getServiceTemplateList(any(), any()))
- .thenReturn(List.of(Objects.requireNonNull(serviceTemplate)));
-
- String returnedServiceTemplate = provider
- .getToscaServiceTemplateReduced(null, null, null);
- assertThat(returnedServiceTemplate).isNotNull();
- ToscaServiceTemplate parsedServiceTemplate = CODER.decode(returnedServiceTemplate, ToscaServiceTemplate.class);
-
- assertThat(parsedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()).hasSize(7);
+ assertThat(returnedServiceTemplate.getServiceTemplates()).isNotEmpty();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index f34e5eff0..0ded4ec0f 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -27,9 +27,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
-import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
+import java.util.HashMap;
import java.util.List;
+import java.util.UUID;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
@@ -43,7 +44,9 @@ import org.junit.jupiter.api.parallel.ExecutionMode;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -60,10 +63,10 @@ class CommissioningControllerTest extends CommonRestController {
private static final String COMMISSIONING_ENDPOINT = "commission";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
- private static ToscaServiceTemplate commonPropertiesServiceTemplate = new ToscaServiceTemplate();
+ private UUID compositionId;
@Autowired
- private ServiceTemplateProvider serviceTemplateProvider;
+ private AcDefinitionProvider acDefinitionProvider;
@LocalServerPort
private int randomServerPort;
@@ -74,7 +77,6 @@ class CommissioningControllerTest extends CommonRestController {
@BeforeAll
public static void setUpBeforeClass() {
serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- commonPropertiesServiceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
}
@BeforeEach
@@ -103,48 +105,16 @@ class CommissioningControllerTest extends CommonRestController {
}
@Test
- void testUnauthorizedQueryElements() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/elements");
- }
-
- @Test
void testUnauthorizedDelete() {
assertUnauthorizedDelete(COMMISSIONING_ENDPOINT);
}
@Test
- void testUnauthorizedQueryToscaServiceTemplate() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
- }
-
- @Test
- void testUnauthorizedQueryToscaServiceTemplateSchema() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/toscaServiceTemplateSchema");
- }
-
- @Test
- void testUnauthorizedQueryToscaServiceCommonOrInstanceProperties() {
- assertUnauthorizedGet(COMMISSIONING_ENDPOINT + "/getCommonOrInstanceProperties");
- }
-
- @Test
- void testQueryToscaServiceTemplate() throws Exception {
- createFullEntryInDbWithCommonProps();
-
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
- Response rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- ToscaServiceTemplate template = rawresp.readEntity(ToscaServiceTemplate.class);
- assertNotNull(template);
- assertThat(template.getNodeTypes()).hasSize(7);
- }
-
- @Test
void testCreateBadRequest() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json("NotToscaServiceTempalte"));
- assertThat(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).isEqualTo(resp.getStatus());
+ assertThat(Response.Status.BAD_REQUEST.getStatusCode()).isEqualTo(resp.getStatus());
CommissioningResponse commissioningResponse = resp.readEntity(CommissioningResponse.class);
assertThat(commissioningResponse.getErrorDetails()).isNotNull();
assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).isNull();
@@ -154,9 +124,41 @@ class CommissioningControllerTest extends CommonRestController {
void testCreate() {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
- assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ assertEquals(Response.Status.CREATED.getStatusCode(), resp.getStatus());
CommissioningResponse commissioningResponse = resp.readEntity(CommissioningResponse.class);
+ compositionId = commissioningResponse.getCompositionId();
+ assertNotNull(commissioningResponse);
+ assertNull(commissioningResponse.getErrorDetails());
+ // Response should return the number of node templates present in the service template
+ assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).hasSize(13);
+ for (String nodeTemplateName : serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().keySet()) {
+ assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
+ .anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
+ }
+ }
+ @Test
+ void testUpdate() {
+ var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
+ var resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.CREATED.getStatusCode(), resp.getStatus());
+ var commissioningResponse = resp.readEntity(CommissioningResponse.class);
+ compositionId = commissioningResponse.getCompositionId();
+
+ var toscaDataType = new ToscaDataType();
+ toscaDataType.setName("org.onap.datatypes.policy.clamp.Configuration");
+ toscaDataType.setDerivedFrom("tosca.datatypes.Root");
+ toscaDataType.setProperties(new HashMap<>());
+ var toscaProperty = new ToscaProperty();
+ toscaProperty.setName("configurationEntityId");
+ toscaProperty.setType("onap.datatypes.ToscaConceptIdentifier");
+ toscaDataType.getProperties().put(toscaProperty.getName(), toscaProperty);
+
+ serviceTemplate.getDataTypes().put(toscaDataType.getName(), toscaDataType);
+ invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
+ resp = invocationBuilder.put(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ commissioningResponse = resp.readEntity(CommissioningResponse.class);
assertNotNull(commissioningResponse);
assertNull(commissioningResponse.getErrorDetails());
// Response should return the number of node templates present in the service template
@@ -165,6 +167,12 @@ class CommissioningControllerTest extends CommonRestController {
assertTrue(commissioningResponse.getAffectedAutomationCompositionDefinitions().stream()
.anyMatch(ac -> ac.getName().equals(nodeTemplateName)));
}
+
+ invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
+ resp = invocationBuilder.buildGet().invoke();
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ var entity = resp.readEntity(ToscaServiceTemplate.class);
+ assertThat(entity.getDataTypes()).containsKey(toscaDataType.getName());
}
@Test
@@ -174,8 +182,8 @@ class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name=noResultWithThisName");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List<?> entityList = rawresp.readEntity(List.class);
- assertThat(entityList).isEmpty();
+ var entityList = rawresp.readEntity(ToscaServiceTemplate.class);
+ assertThat(entityList.getNodeTypes()).isNull();
}
@Test
@@ -185,50 +193,44 @@ class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- List<?> entityList = rawresp.readEntity(List.class);
+ var entityList = rawresp.readEntity(ToscaServiceTemplate.class);
assertNotNull(entityList);
- assertThat(entityList).hasSize(2);
}
@Test
void testDeleteBadRequest() throws Exception {
createEntryInDB();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
+ Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + UUID.randomUUID());
// Call delete with no info
Response resp = invocationBuilder.delete();
- assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
}
@Test
void testDelete() throws Exception {
- var serviceTemplateCreated = createEntryInDB();
+ createEntryInDB();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name="
- + serviceTemplateCreated.getName() + "&version=" + serviceTemplateCreated.getVersion());
+ Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + compositionId);
// Call delete with no info
Response resp = invocationBuilder.delete();
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
- List<ToscaServiceTemplate> templatesInDB = serviceTemplateProvider.getAllServiceTemplates();
+ List<ToscaServiceTemplate> templatesInDB = acDefinitionProvider.getAllServiceTemplates();
assertThat(templatesInDB).isEmpty();
}
- private synchronized ToscaServiceTemplate createEntryInDB() throws Exception {
+ private synchronized void createEntryInDB() throws Exception {
deleteEntryInDB();
- return serviceTemplateProvider.createServiceTemplate(serviceTemplate);
+ var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate);
+ compositionId = acmDefinition.getCompositionId();
}
// Delete entries from the DB after relevant tests
private synchronized void deleteEntryInDB() throws Exception {
- var list = serviceTemplateProvider.getAllServiceTemplates();
+ var list = acDefinitionProvider.getAllServiceTemplates();
if (!list.isEmpty()) {
- serviceTemplateProvider.deleteServiceTemplate(list.get(0).getName(), list.get(0).getVersion());
+ acDefinitionProvider.deleteAcDefintion(compositionId);
}
}
-
- private synchronized void createFullEntryInDbWithCommonProps() throws Exception {
- deleteEntryInDB();
- serviceTemplateProvider.createServiceTemplate(commonPropertiesServiceTemplate);
- }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 016ec6c5e..040fabe27 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -23,16 +23,16 @@ package org.onap.policy.clamp.acm.runtime.instantiation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import java.util.List;
import java.util.Optional;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.onap.policy.clamp.acm.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
@@ -41,9 +41,12 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
/**
* Class to perform unit test of {@link AutomationCompositionInstantiationProvider}}.
@@ -51,34 +54,40 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
*/
class AutomationCompositionInstantiationProviderTest {
private static final String AC_INSTANTIATION_CREATE_JSON =
- "src/test/resources/rest/acm/AutomationCompositions.json";
+ "src/test/resources/rest/acm/AutomationCompositions.json";
private static final String AC_INSTANTIATION_UPDATE_JSON =
- "src/test/resources/rest/acm/AutomationCompositionsUpdate.json";
+ "src/test/resources/rest/acm/AutomationCompositionsUpdate.json";
private static final String AC_INSTANTIATION_CHANGE_STATE_JSON = "src/test/resources/rest/acm/PassiveCommand.json";
private static final String AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON =
- "src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json";
+ "src/test/resources/rest/acm/AutomationCompositionElementsNotFound.json";
private static final String AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON =
- "src/test/resources/rest/acm/AutomationCompositionsNotFound.json";
+ "src/test/resources/rest/acm/AutomationCompositionsNotFound.json";
private static final String AUTOMATION_COMPOSITION_NOT_FOUND = "Automation composition not found";
private static final String DELETE_BAD_REQUEST = "Automation composition state is still %s";
private static final String ORDERED_STATE_INVALID = "ordered state invalid or not specified on command";
private static final String AC_ELEMENT_NAME_NOT_FOUND =
- "\"AutomationCompositions\" INVALID, item has status INVALID\n"
- + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
- + "INVALID, item has status INVALID\n"
- + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
- + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
- + "INVALID, item has status INVALID\n"
- + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n";
+ "\"AutomationCompositions\" INVALID, item has status INVALID\n"
+ + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
+ + "INVALID, item has status INVALID\n"
+ + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
+ + " {2}\"entry org.onap.domain.pmsh.PMSHAutomationCompositionDefinition\" "
+ + "INVALID, item has status INVALID\n"
+ + " {4}\"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n";
private static final String AC_DEFINITION_NOT_FOUND =
- "\"AutomationCompositions\" INVALID, item has status INVALID\n"
- + " {2}\"entry org.onap.domain.PMSHAutomationCompositionDefinition\" INVALID, item has status INVALID\n"
- + " {4}item \"AutomationComposition\" value \"org.onap.domain.PMSHAutomationCompositionDefinition\""
- + " INVALID, Commissioned automation composition definition not found\n"
- + " {2}\"entry org.onap.domain.PMSHAutomationCompositionDefinition\" INVALID, item has status INVALID\n"
- + " {4}item \"AutomationComposition\" value \"org.onap.domain.PMSHAutomationCompositionDefinition\""
- + " INVALID, Commissioned automation composition definition not found\n";
+ "\"AutomationCompositions\" INVALID, item has status INVALID\n"
+ + " item \"ServiceTemplate\" value \"\" INVALID,"
+ + " Commissioned automation composition definition not found\n";
+
+ private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+
+ @BeforeAll
+ public static void setUpBeforeClass() {
+ serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var jpa =
+ ProviderUtils.getJpaAndValidate(serviceTemplate, JpaToscaServiceTemplate::new, "toscaServiceTemplate");
+ serviceTemplate = jpa.toAuthorative();
+ }
@Test
void testInstantiationCrud() throws Exception {
@@ -86,51 +95,32 @@ class AutomationCompositionInstantiationProviderTest {
var participants = CommonTestData.createParticipants();
when(participantProvider.getParticipants()).thenReturn(participants);
- var commissioningProvider = mock(CommissioningProvider.class);
- var toscaNodeTemplate1 = new ToscaNodeTemplate();
- toscaNodeTemplate1.setName("org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement");
- toscaNodeTemplate1.setVersion("1.2.3");
- when(commissioningProvider.getAutomationCompositionDefinitions(anyString(), anyString()))
- .thenReturn(List.of(toscaNodeTemplate1));
-
- var toscaNodeTemplate2 = new ToscaNodeTemplate();
- toscaNodeTemplate2.setName("org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement");
- toscaNodeTemplate2.setVersion("1.2.3");
- var toscaNodeTemplate3 = new ToscaNodeTemplate();
- toscaNodeTemplate3.setName("org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement");
- toscaNodeTemplate3.setVersion("1.2.3");
- var toscaNodeTemplate4 = new ToscaNodeTemplate();
- toscaNodeTemplate4.setName("org.onap.domain.pmsh.PMSH_DCAEMicroservice");
- toscaNodeTemplate4.setVersion("1.2.3");
-
- when(commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplate1))
- .thenReturn(List.of(toscaNodeTemplate1, toscaNodeTemplate2, toscaNodeTemplate3, toscaNodeTemplate4));
-
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates()).thenReturn(List.of(serviceTemplate));
var supervisionHandler = mock(SupervisionHandler.class);
var acProvider = mock(AutomationCompositionProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
- AutomationCompositions automationCompositionsCreate =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- InstantiationResponse instantiationResponse =
- instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
+ var automationCompositionsCreate =
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ var instantiationResponse = instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionsCreate);
verify(acProvider).saveAutomationCompositions(automationCompositionsCreate.getAutomationCompositionList());
for (var automationComposition : automationCompositionsCreate.getAutomationCompositionList()) {
when(acProvider.getAutomationCompositions(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(List.of(automationComposition));
+ automationComposition.getVersion())).thenReturn(List.of(automationComposition));
- AutomationCompositions automationCompositionsGet = instantiationProvider
- .getAutomationCompositions(automationComposition.getName(), automationComposition.getVersion());
+ var automationCompositionsGet = instantiationProvider
+ .getAutomationCompositions(automationComposition.getName(), automationComposition.getVersion());
assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
assertThat(automationComposition)
- .isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
+ .isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
}
- AutomationCompositions automationCompositionsUpdate =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ var automationCompositionsUpdate =
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
instantiationResponse = instantiationProvider.updateAutomationCompositions(automationCompositionsUpdate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionsUpdate);
@@ -139,33 +129,33 @@ class AutomationCompositionInstantiationProviderTest {
for (var automationComposition : automationCompositionsUpdate.getAutomationCompositionList()) {
when(acProvider.findAutomationComposition(automationComposition.getKey().asIdentifier()))
- .thenReturn(Optional.of(automationComposition));
+ .thenReturn(Optional.of(automationComposition));
when(acProvider.findAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
+ automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
when(acProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(automationComposition);
+ automationComposition.getVersion())).thenReturn(automationComposition);
}
- InstantiationCommand instantiationCommand =
- InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
+ var instantiationCommand =
+ InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
instantiationResponse = instantiationProvider.issueAutomationCompositionCommand(instantiationCommand);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, instantiationCommand);
verify(supervisionHandler)
- .triggerAutomationCompositionSupervision(instantiationCommand.getAutomationCompositionIdentifierList());
+ .triggerAutomationCompositionSupervision(instantiationCommand.getAutomationCompositionIdentifierList());
// in order to delete a automationComposition the state must be UNINITIALISED
automationCompositionsCreate.getAutomationCompositionList()
- .forEach(ac -> ac.setState(AutomationCompositionState.UNINITIALISED));
+ .forEach(ac -> ac.setState(AutomationCompositionState.UNINITIALISED));
instantiationProvider.updateAutomationCompositions(automationCompositionsCreate);
for (AutomationComposition automationComposition : automationCompositionsCreate
- .getAutomationCompositionList()) {
+ .getAutomationCompositionList()) {
instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion());
+ automationComposition.getVersion());
verify(acProvider).deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion());
+ automationComposition.getVersion());
}
}
@@ -173,19 +163,19 @@ class AutomationCompositionInstantiationProviderTest {
void testInstantiationDelete() throws Exception {
AutomationCompositions automationCompositions =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");
AutomationComposition automationComposition0 = automationCompositions.getAutomationCompositionList().get(0);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition0.getName(),
- automationComposition0.getVersion())).hasMessageMatching(AUTOMATION_COMPOSITION_NOT_FOUND);
+ automationComposition0.getVersion())).hasMessageMatching(AUTOMATION_COMPOSITION_NOT_FOUND);
for (AutomationCompositionState state : AutomationCompositionState.values()) {
if (!AutomationCompositionState.UNINITIALISED.equals(state)) {
@@ -196,147 +186,111 @@ class AutomationCompositionInstantiationProviderTest {
for (AutomationComposition automationComposition : automationCompositions.getAutomationCompositionList()) {
when(acProvider.findAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
+ automationComposition.getVersion())).thenReturn(Optional.of(automationComposition));
when(acProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(automationComposition);
+ automationComposition.getVersion())).thenReturn(automationComposition);
instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion());
+ automationComposition.getVersion());
}
}
private void assertThatDeleteThrownBy(AutomationCompositions automationCompositions,
- AutomationCompositionState state) throws Exception {
+ AutomationCompositionState state) throws Exception {
AutomationComposition automationComposition = automationCompositions.getAutomationCompositionList().get(0);
automationComposition.setState(state);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion()))
- .thenReturn(Optional.of(automationComposition));
+ .thenReturn(Optional.of(automationComposition));
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
+ automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
}
@Test
void testCreateAutomationCompositions_NoDuplicates() throws Exception {
- var commissioningProvider = mock(CommissioningProvider.class);
-
- var toscaNodeTemplate1 = new ToscaNodeTemplate();
- toscaNodeTemplate1.setName("org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement");
- toscaNodeTemplate1.setVersion("1.2.3");
- when(commissioningProvider.getAutomationCompositionDefinitions(anyString(), anyString()))
- .thenReturn(List.of(toscaNodeTemplate1));
-
- var toscaNodeTemplate2 = new ToscaNodeTemplate();
- toscaNodeTemplate2.setName("org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement");
- toscaNodeTemplate2.setVersion("1.2.3");
- var toscaNodeTemplate3 = new ToscaNodeTemplate();
- toscaNodeTemplate3.setName("org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement");
- toscaNodeTemplate3.setVersion("1.2.3");
- var toscaNodeTemplate4 = new ToscaNodeTemplate();
- toscaNodeTemplate4.setName("org.onap.domain.pmsh.PMSH_DCAEMicroservice");
- toscaNodeTemplate4.setVersion("1.2.3");
-
- when(commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplate1))
- .thenReturn(List.of(toscaNodeTemplate1, toscaNodeTemplate2, toscaNodeTemplate3, toscaNodeTemplate4));
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates()).thenReturn(List.of(serviceTemplate));
AutomationCompositions automationCompositionsCreate =
- InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates");
+ InstantiationUtils.getAutomationCompositionsFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates");
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
InstantiationResponse instantiationResponse =
- instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
+ instantiationProvider.createAutomationCompositions(automationCompositionsCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionsCreate);
when(acProvider.findAutomationComposition(
- automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()))
- .thenReturn(Optional.of(automationCompositionsCreate.getAutomationCompositionList().get(0)));
+ automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()))
+ .thenReturn(Optional.of(automationCompositionsCreate.getAutomationCompositionList().get(0)));
assertThatThrownBy(() -> instantiationProvider.createAutomationCompositions(automationCompositionsCreate))
- .hasMessageMatching(
- automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()
- + " already defined");
+ .hasMessageMatching(
+ automationCompositionsCreate.getAutomationCompositionList().get(0).getKey().asIdentifier()
+ + " already defined");
}
@Test
void testCreateAutomationCompositions_CommissionedAcElementNotFound() throws Exception {
- var toscaNodeTemplate1 = new ToscaNodeTemplate();
- toscaNodeTemplate1.setName("org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement");
- toscaNodeTemplate1.setVersion("1.2.3");
-
- var toscaNodeTemplate2 = new ToscaNodeTemplate();
- toscaNodeTemplate2.setName("org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement");
- toscaNodeTemplate2.setVersion("1.2.3");
- var toscaNodeTemplate3 = new ToscaNodeTemplate();
- toscaNodeTemplate3.setName("org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement");
- toscaNodeTemplate3.setVersion("1.2.3");
- var commissioningProvider = mock(CommissioningProvider.class);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates()).thenReturn(List.of(serviceTemplate));
AutomationCompositions automationCompositions = InstantiationUtils.getAutomationCompositionsFromResource(
- AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "AcElementNotFound");
-
- when(commissioningProvider.getAutomationCompositionDefinitions(
- automationCompositions.getAutomationCompositionList().get(0).getDefinition().getName(),
- automationCompositions.getAutomationCompositionList().get(0).getDefinition().getVersion()))
- .thenReturn(List.of(toscaNodeTemplate1));
-
- when(commissioningProvider.getAutomationCompositionElementDefinitions(toscaNodeTemplate1))
- .thenReturn(List.of(toscaNodeTemplate1, toscaNodeTemplate2, toscaNodeTemplate3));
+ AC_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "AcElementNotFound");
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var provider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> provider.createAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
+ .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
assertThatThrownBy(() -> provider.updateAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
+ .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
}
@Test
void testCreateAutomationCompositions_CommissionedAcNotFound() throws Exception {
AutomationCompositions automationCompositions = InstantiationUtils
- .getAutomationCompositionsFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
+ .getAutomationCompositionsFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
- var provider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> provider.createAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
assertThatThrownBy(() -> provider.updateAutomationCompositions(automationCompositions))
- .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
}
@Test
- void testIssueAutomationCompositionCommand_OrderedStateInvalid()
- throws AutomationCompositionRuntimeException {
+ void testIssueAutomationCompositionCommand_OrderedStateInvalid() throws AutomationCompositionRuntimeException {
var participantProvider = Mockito.mock(ParticipantProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
- var commissioningProvider = mock(CommissioningProvider.class);
- var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, commissioningProvider,
- supervisionHandler, participantProvider);
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
+ participantProvider, acDefinitionProvider);
assertThatThrownBy(() -> instantiationProvider.issueAutomationCompositionCommand(new InstantiationCommand()))
- .hasMessageMatching(ORDERED_STATE_INVALID);
+ .hasMessageMatching(ORDERED_STATE_INVALID);
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index 7cdc8a975..228412133 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
+import java.util.UUID;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
@@ -44,8 +45,8 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -65,9 +66,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ActiveProfiles("test")
class InstantiationControllerTest extends CommonRestController {
- private static final String ID_NAME = "PMSH_Test_Instance";
- private static final String ID_VERSION = "1.2.3";
-
private static final String AC_INSTANTIATION_CREATE_JSON =
"src/test/resources/rest/acm/AutomationCompositions.json";
@@ -80,12 +78,13 @@ class InstantiationControllerTest extends CommonRestController {
private static final String INSTANTIATION_COMMAND_ENDPOINT = "instantiation/command";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+ private UUID compositionId;
@Autowired
private AutomationCompositionRepository automationCompositionRepository;
@Autowired
- private ServiceTemplateProvider serviceTemplateProvider;
+ private AcDefinitionProvider acDefinitionProvider;
@Autowired
private AutomationCompositionInstantiationProvider instantiationProvider;
@@ -347,14 +346,15 @@ class InstantiationControllerTest extends CommonRestController {
private synchronized void deleteEntryInDB() throws Exception {
automationCompositionRepository.deleteAll();
- var list = serviceTemplateProvider.getAllServiceTemplates();
+ var list = acDefinitionProvider.getAllServiceTemplates();
if (!list.isEmpty()) {
- serviceTemplateProvider.deleteServiceTemplate(list.get(0).getName(), list.get(0).getVersion());
+ acDefinitionProvider.deleteAcDefintion(compositionId);
}
}
private synchronized void createEntryInDB() throws Exception {
deleteEntryInDB();
- serviceTemplateProvider.createServiceTemplate(serviceTemplate);
+ var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate);
+ compositionId = acmDefinition.getCompositionId();
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index 7e9b102a8..e4d382133 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -54,9 +54,9 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -119,15 +119,15 @@ class SupervisionHandlerTest {
.thenReturn(Optional.of(automationComposition));
when(automationCompositionProvider.getAutomationComposition(identifier)).thenReturn(automationComposition);
- var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
- when(serviceTemplateProvider.getAllServiceTemplates())
+ var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getAllServiceTemplates())
.thenReturn(List.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(
TOSCA_SERVICE_TEMPLATE_YAML))));
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
- serviceTemplateProvider, mock(AutomationCompositionUpdatePublisher.class),
+ acDefinitionProvider, mock(AutomationCompositionUpdatePublisher.class),
automationCompositionStateChangePublisher, mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class));
@@ -355,18 +355,18 @@ class SupervisionHandlerTest {
.thenReturn(Optional.of(automationComposition));
when(automationCompositionProvider.getAutomationComposition(identifier)).thenReturn(automationComposition);
- var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
- when(serviceTemplateProvider.getServiceTemplateList(any(), any()))
+ var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.getServiceTemplateList(any(), any()))
.thenReturn(List.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(
TOSCA_SERVICE_TEMPLATE_YAML))));
- when(serviceTemplateProvider.getAllServiceTemplates())
+ when(acDefinitionProvider.getAllServiceTemplates())
.thenReturn(List.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(
TOSCA_SERVICE_TEMPLATE_YAML))));
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
return new SupervisionHandler(automationCompositionProvider, participantProvider,
- serviceTemplateProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
+ acDefinitionProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index cc3a95e81..50d5246b0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -45,9 +45,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -57,7 +57,7 @@ class SupervisionScannerTest {
private static final String AC_JSON = "src/test/resources/rest/acm/AutomationCompositionsSmoke.json";
- private static final ServiceTemplateProvider serviceTemplateProvider = mock(ServiceTemplateProvider.class);
+ private static final AcDefinitionProvider acDefinitionProvider = mock(AcDefinitionProvider.class);
private static final String PARTICIPANT_NAME = "Participant0";
private static final String PARTICIPANT_VERSION = "1.0.0";
@@ -68,7 +68,7 @@ class SupervisionScannerTest {
@BeforeAll
public static void setUpBeforeAll() throws Exception {
ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML);
- when(serviceTemplateProvider.getAllServiceTemplates())
+ when(acDefinitionProvider.getAllServiceTemplates())
.thenReturn(List.of(Objects.requireNonNull(serviceTemplate)));
}
@@ -86,7 +86,7 @@ class SupervisionScannerTest {
InstantiationUtils.getAutomationCompositionsFromResource(AC_JSON, "Crud").getAutomationCompositionList();
when(automationCompositionProvider.getAutomationCompositions()).thenReturn(automationCompositions);
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
supervisionScanner.run(false);
@@ -110,7 +110,7 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
supervisionScanner.run(false);
@@ -136,7 +136,7 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
@@ -173,7 +173,7 @@ class SupervisionScannerTest {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
@@ -207,7 +207,7 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var supervisionScanner = new SupervisionScanner(automationCompositionProvider, serviceTemplateProvider,
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index ad97201e2..11a060029 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -43,9 +43,9 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.models.base.PfModelException;
@@ -68,14 +68,14 @@ class SupervisionMessagesTest extends CommonRestController {
public static void setupDbProviderParameters() throws PfModelException {
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- var serviceTemplateProvider = Mockito.mock(ServiceTemplateProvider.class);
+ var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
var automationCompositionUpdatePublisher = Mockito.mock(AutomationCompositionUpdatePublisher.class);
var automationCompositionStateChangePublisher = Mockito.mock(AutomationCompositionStateChangePublisher.class);
var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
supervisionHandler = new SupervisionHandler(acProvider, participantProvider,
- serviceTemplateProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
+ acDefinitionProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
}
@@ -157,7 +157,7 @@ class SupervisionMessagesTest extends CommonRestController {
@Test
void testParticipantUpdatePublisherDecomisioning() {
- var publisher = new ParticipantUpdatePublisher(mock(ServiceTemplateProvider.class));
+ var publisher = new ParticipantUpdatePublisher(mock(AcDefinitionProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
publisher.sendDecomisioning();
@@ -166,7 +166,7 @@ class SupervisionMessagesTest extends CommonRestController {
@Test
void testParticipantUpdatePublisherComissioning() {
- var publisher = new ParticipantUpdatePublisher(mock(ServiceTemplateProvider.class));
+ var publisher = new ParticipantUpdatePublisher(mock(AcDefinitionProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
publisher.sendComissioningBroadcast("NAME", "1.0.0");