aboutsummaryrefslogtreecommitdiffstats
path: root/models/src
diff options
context:
space:
mode:
Diffstat (limited to 'models/src')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java50
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java18
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java11
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java13
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java81
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java26
6 files changed, 158 insertions, 41 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
index a9b9a0cfd..9eb5e7a32 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,10 +28,14 @@ import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
+import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfModelRuntimeException;
@@ -47,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
public class AcDefinitionProvider {
private final AutomationCompositionDefinitionRepository acmDefinitionRepository;
+ private final NodeTemplateStateRepository nodeTemplateStateRepository;
/**
* Create Automation Composition Definition.
@@ -125,6 +130,43 @@ public class AcDefinitionProvider {
}
/**
+ * Update Ac Definition AcTypeState, StateChangeResult and restarting.
+ *
+ * @param compositionId The UUID of the automation composition definition to update
+ * @param state the AcTypeState
+ * @param stateChangeResult the StateChangeResult
+ * @param restarting restarting process
+ */
+ public void updateAcDefinitionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
+ Boolean restarting) {
+ var jpaUpdate = acmDefinitionRepository.findById(compositionId.toString());
+ if (jpaUpdate.isEmpty()) {
+ String errorMessage = "update of Automation Composition Definition \"" + compositionId
+ + "\" failed, Automation Composition Definition does not exist";
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, errorMessage);
+ }
+ var acDefinition = jpaUpdate.get();
+ acDefinition.setState(state);
+ acDefinition.setStateChangeResult(stateChangeResult);
+ acDefinition.setRestarting(restarting);
+ acmDefinitionRepository.save(acDefinition);
+ acmDefinitionRepository.flush();
+ }
+
+ /**
+ * Update Ac DefinitionElement.
+ *
+ * @param nodeTemplateState the NodeTemplateState
+ * @param compositionId The UUID of the automation composition definition
+ */
+ public void updateAcDefinitionElement(NodeTemplateState nodeTemplateState, UUID compositionId) {
+ var jpaNodeTemplateState = new JpaNodeTemplateState(
+ nodeTemplateState.getNodeTemplateStateId().toString(), compositionId.toString());
+ jpaNodeTemplateState.fromAuthorative(nodeTemplateState);
+ nodeTemplateStateRepository.save(jpaNodeTemplateState);
+ }
+
+ /**
* Delete Automation Composition Definition.
*
* @param compositionId The UUID of the automation composition definition to delete
@@ -173,13 +215,13 @@ public class AcDefinitionProvider {
}
/**
- * Get Automation Composition Definitions.
+ * Get Automation Composition Definitions in transition.
*
* @return the Automation Composition Definitions found
*/
@Transactional(readOnly = true)
- public List<AutomationCompositionDefinition> getAllAcDefinitions() {
- var jpaList = acmDefinitionRepository.findAll();
+ public List<AutomationCompositionDefinition> getAllAcDefinitionsInTransition() {
+ var jpaList = acmDefinitionRepository.findByStateIn(List.of(AcTypeState.PRIMING, AcTypeState.DEPRIMING));
return ProviderUtils.asEntityList(jpaList);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index 1ffcc1b6e..8be12960b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -127,7 +127,7 @@ public class AutomationCompositionProvider {
@NonNull final AutomationComposition automationComposition) {
var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition,
JpaAutomationComposition::new, "automation composition"));
-
+ automationCompositionRepository.flush();
// Return the saved automation composition
return result.toAuthorative();
}
@@ -145,6 +145,20 @@ public class AutomationCompositionProvider {
}
/**
+ * Get all automation compositions in transition..
+ *
+ * @return all automation compositions found
+ */
+ @Transactional(readOnly = true)
+ public List<AutomationComposition> getAcInstancesInTransition() {
+ var jpaList = automationCompositionRepository.findByDeployStateIn(List.of(DeployState.DEPLOYING,
+ DeployState.UNDEPLOYING, DeployState.DELETING, DeployState.UPDATING, DeployState.MIGRATING));
+ jpaList.addAll(automationCompositionRepository.findByLockStateIn(
+ List.of(LockState.LOCKING, LockState.UNLOCKING)));
+ return ProviderUtils.asEntityList(jpaList);
+ }
+
+ /**
* Get automation compositions.
*
* @param name the name of the automation composition to get, null to get all automation compositions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
index df4d7dffa..86de60bf2 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,16 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import java.util.Collection;
+import java.util.List;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface AutomationCompositionDefinitionRepository
- extends JpaRepository<JpaAutomationCompositionDefinition, String>,
- QueryByExampleExecutor<JpaAutomationCompositionDefinition> {
+ extends JpaRepository<JpaAutomationCompositionDefinition, String> {
+
+ List<JpaAutomationCompositionDefinition> findByStateIn(Collection<AcTypeState> states);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
index bb8b3e6d9..d61dfb41b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022,2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,15 +20,20 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import java.util.Collection;
import java.util.List;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
-public interface AutomationCompositionRepository
- extends JpaRepository<JpaAutomationComposition, String>, QueryByExampleExecutor<JpaAutomationComposition> {
+public interface AutomationCompositionRepository extends JpaRepository<JpaAutomationComposition, String> {
List<JpaAutomationComposition> findByCompositionId(String compositionId);
+
+ List<JpaAutomationComposition> findByDeployStateIn(Collection<DeployState> deployStates);
+
+ List<JpaAutomationComposition> findByLockStateIn(Collection<LockState> lockStates);
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
index 78095c907..1e067c8f6 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,9 +38,12 @@ import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
+import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -91,7 +94,7 @@ class AcDefinitionProviderTest {
when(acmDefinitionRepository.save(any(JpaAutomationCompositionDefinition.class)))
.thenReturn(new JpaAutomationCompositionDefinition(acmDefinition));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var result = acDefinitionProvider
.createAutomationCompositionDefinition(inputServiceTemplate, ELEMENT_NAME, NODE_TYPE);
@@ -101,11 +104,9 @@ class AcDefinitionProviderTest {
@Test
void testToscaWithInvalidElement() {
- var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
- var acmDefinition = getAcDefinition(docServiceTemplate);
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
assertThatThrownBy(() -> acDefinitionProvider
.createAutomationCompositionDefinition(inputServiceTemplate, INVALID_ELEMENT_NAME, NODE_TYPE))
@@ -114,11 +115,9 @@ class AcDefinitionProviderTest {
@Test
void testToscaWithInvalidNodeType() {
- var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
- var acmDefinition = getAcDefinition(docServiceTemplate);
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
assertThatThrownBy(() -> acDefinitionProvider
.createAutomationCompositionDefinition(inputServiceTemplate, ELEMENT_NAME, INVALID_NODE_TYPE))
@@ -135,7 +134,7 @@ class AcDefinitionProviderTest {
when(acmDefinitionRepository.save(any(JpaAutomationCompositionDefinition.class)))
.thenReturn(new JpaAutomationCompositionDefinition(acmDefinition));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
inputServiceTemplate.setMetadata(new HashMap<>());
var result = acDefinitionProvider
.createAutomationCompositionDefinition(inputServiceTemplate, ELEMENT_NAME, NODE_TYPE);
@@ -147,7 +146,7 @@ class AcDefinitionProviderTest {
@Test
void testUpdateServiceTemplate() {
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
acDefinitionProvider.updateServiceTemplate(UUID.randomUUID(), inputServiceTemplate, ELEMENT_NAME, NODE_TYPE);
verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class));
}
@@ -155,19 +154,45 @@ class AcDefinitionProviderTest {
@Test
void testUpdateAcDefinition() {
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate));
acDefinitionProvider.updateAcDefinition(acmDefinition, NODE_TYPE);
verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class));
}
@Test
+ void testUpdateAcDefinitionState() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
+ var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate));
+ acmDefinition.setState(AcTypeState.PRIMING);
+ var jpa = new JpaAutomationCompositionDefinition(acmDefinition);
+ when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString()))
+ .thenReturn(Optional.of(jpa));
+ acDefinitionProvider.updateAcDefinitionState(acmDefinition.getCompositionId(), AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, false);
+ verify(acmDefinitionRepository).save(jpa);
+ }
+
+ @Test
+ void testUpdateAcDefinitionElement() {
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier("name", "1.0.0"));
+ nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID());
+ nodeTemplateState.setState(AcTypeState.PRIMED);
+ var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(null, nodeTemplateStateRepository);
+ acDefinitionProvider.updateAcDefinitionElement(nodeTemplateState, UUID.randomUUID());
+ verify(nodeTemplateStateRepository).save(any(JpaNodeTemplateState.class));
+ }
+
+ @Test
void testGetAcDefinition() {
var jpa = new JpaAutomationCompositionDefinition();
jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var result = acDefinitionProvider.getAcDefinition(UUID.fromString(jpa.getCompositionId()));
assertThat(result).isNotNull();
}
@@ -175,7 +200,7 @@ class AcDefinitionProviderTest {
@Test
void testGetAcDefinitionNotFound() {
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var compositionId = UUID.randomUUID();
assertThatThrownBy(() -> acDefinitionProvider.getAcDefinition(compositionId))
.hasMessage("Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist");
@@ -187,20 +212,24 @@ class AcDefinitionProviderTest {
jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
when(acmDefinitionRepository.findById(jpa.getCompositionId())).thenReturn(Optional.of(jpa));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
- var result = acDefinitionProvider.findAcDefinition(UUID.fromString(jpa.getCompositionId()));
- assertThat(result).isNotNull();
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
+ var compositionId = UUID.fromString(jpa.getCompositionId());
+ var result = acDefinitionProvider.findAcDefinition(compositionId);
+ assertThat(result).isNotEmpty();
}
@Test
- void testGetAllAcDefinitions() {
+ void getAllAcDefinitionsInTransition() {
+ var acDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate));
+ acDefinition.setState(AcTypeState.PRIMING);
var jpa = new JpaAutomationCompositionDefinition();
- jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
+ jpa.fromAuthorative(acDefinition);
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- when(acmDefinitionRepository.findAll()).thenReturn(List.of(jpa));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
- var result = acDefinitionProvider.getAllAcDefinitions();
- assertThat(result).hasSize(1);
+ when(acmDefinitionRepository.findByStateIn(List.of(AcTypeState.PRIMING, AcTypeState.DEPRIMING)))
+ .thenReturn(List.of(jpa));
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
+ var result = acDefinitionProvider.getAllAcDefinitionsInTransition();
+ assertThat(result).isNotEmpty();
}
@Test
@@ -212,7 +241,7 @@ class AcDefinitionProviderTest {
when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString()))
.thenReturn(Optional.of(new JpaAutomationCompositionDefinition(acmDefinition)));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var result = acDefinitionProvider.deleteAcDefintion(acmDefinition.getCompositionId());
assertThat(result).isEqualTo(docServiceTemplate.toAuthorative());
@@ -222,7 +251,7 @@ class AcDefinitionProviderTest {
void testDeleteServiceTemplateEmpty() {
var compositionId = UUID.randomUUID();
var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
assertThatThrownBy(() -> acDefinitionProvider.deleteAcDefintion(compositionId))
.hasMessage("delete of Automation Composition Definition \"" + compositionId
+ "\" failed, Automation Composition Definition does not exist");
@@ -236,7 +265,7 @@ class AcDefinitionProviderTest {
when(acmDefinitionRepository.findAll(Mockito.<Example<JpaAutomationCompositionDefinition>>any()))
.thenReturn(List.of(new JpaAutomationCompositionDefinition(acmDefinition)));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var result = acDefinitionProvider.getServiceTemplateList(inputServiceTemplate.getName(),
inputServiceTemplate.getVersion());
@@ -252,7 +281,7 @@ class AcDefinitionProviderTest {
when(acmDefinitionRepository.findAll(Mockito.<Example<JpaAutomationCompositionDefinition>>any()))
.thenReturn(List.of(new JpaAutomationCompositionDefinition(acmDefinition)));
- var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository, null);
var result = acDefinitionProvider.getServiceTemplateList(null,
inputServiceTemplate.getVersion());
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
index b09ddda74..463e958f3 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -40,6 +41,8 @@ import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
@@ -177,6 +180,27 @@ class AutomationCompositionProviderTest {
}
@Test
+ void testGetAcInstancesInTransition() {
+ inputAutomationCompositions.getAutomationCompositionList().get(0).setDeployState(DeployState.DEPLOYING);
+ inputAutomationCompositions.getAutomationCompositionList().get(1).setLockState(LockState.LOCKING);
+ inputAutomationCompositionsJpa.get(0).setDeployState(DeployState.DEPLOYING);
+ inputAutomationCompositionsJpa.get(1).setLockState(LockState.LOCKING);
+
+ List<JpaAutomationComposition> res1 = new ArrayList<>();
+ res1.add(inputAutomationCompositionsJpa.get(0));
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
+ when(automationCompositionRepository.findByDeployStateIn(List.of(DeployState.DEPLOYING,
+ DeployState.UNDEPLOYING, DeployState.DELETING, DeployState.UPDATING, DeployState.MIGRATING)))
+ .thenReturn(res1);
+ when(automationCompositionRepository.findByLockStateIn(List.of(LockState.LOCKING, LockState.UNLOCKING)))
+ .thenReturn(List.of(inputAutomationCompositionsJpa.get(1)));
+ var acList = automationCompositionProvider.getAcInstancesInTransition();
+ assertEquals(inputAutomationCompositions.getAutomationCompositionList(), acList);
+ }
+
+ @Test
void testDeleteAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,