aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'models/src/test')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java10
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java49
2 files changed, 9 insertions, 50 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java
index 579631604..1aa67f425 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java
@@ -25,15 +25,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class InstantiationCommandTest {
@Test
void testInstantiationCommandLombok() {
assertNotNull(new InstantiationCommand());
- InstantiationCommand ic0 = new InstantiationCommand();
+ var ic0 = new InstantiationCommand();
assertThat(ic0.toString()).contains("InstantiationCommand(");
assertNotEquals(0, ic0.hashCode());
@@ -41,9 +41,9 @@ class InstantiationCommandTest {
assertNotEquals(null, ic0);
- InstantiationCommand ic1 = new InstantiationCommand();
+ var ic1 = new InstantiationCommand();
- ic1.setAutomationCompositionIdentifierList(new ArrayList<>());
+ ic1.setAutomationCompositionIdentifier(new ToscaConceptIdentifier());
ic1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
assertThat(ic1.toString()).contains("InstantiationCommand(");
@@ -53,7 +53,7 @@ class InstantiationCommandTest {
assertNotEquals(ic1, ic0);
- InstantiationCommand ic2 = new InstantiationCommand();
+ var ic2 = new InstantiationCommand();
assertEquals(ic2, ic0);
}
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 5be603d0d..5b12eee17 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
@@ -45,13 +45,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class AutomationCompositionProviderTest {
- private static final String LIST_IS_NULL = "automationCompositions is marked .*ull but is null";
private static final String OBJECT_IS_NULL = "automationComposition is marked non-null but is null";
private static final String ID_NAME = "PMSHInstance1";
private static final String ID_VERSION = "1.0.1";
private static final String ID_NAME_NOT_EXTST = "not_exist";
- private static final String ID_NAME_NOT_VALID = "not_valid";
private static final Coder CODER = new StandardCoder();
private static final String AUTOMATION_COMPOSITION_JSON =
@@ -70,31 +68,7 @@ class AutomationCompositionProviderTest {
}
@Test
- void testAutomationCompositionsSave() throws Exception {
- var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
-
- assertThatThrownBy(() -> automationCompositionProvider.saveAutomationCompositions(null))
- .hasMessageMatching(LIST_IS_NULL);
-
- when(automationCompositionRepository.saveAll(inputAutomationCompositionsJpa))
- .thenReturn(inputAutomationCompositionsJpa);
-
- var createdAutomationCompositions = new AutomationCompositions();
- createdAutomationCompositions.setAutomationCompositionList(automationCompositionProvider
- .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()));
-
- assertEquals(inputAutomationCompositions, createdAutomationCompositions);
-
- when(automationCompositionRepository.saveAll(any())).thenThrow(IllegalArgumentException.class);
-
- assertThatThrownBy(() -> automationCompositionProvider
- .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()))
- .hasMessageMatching("Error in save AutomationCompositions");
- }
-
- @Test
- void testAutomationCompositionSave() throws Exception {
+ void testAutomationCompositionSave() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
@@ -108,27 +82,16 @@ class AutomationCompositionProviderTest {
.saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0));
assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), createdAutomationComposition);
-
- when(automationCompositionRepository.save(any())).thenThrow(IllegalArgumentException.class);
-
- assertThatThrownBy(() -> automationCompositionProvider
- .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)))
- .hasMessageMatching("Error in save automationComposition");
}
@Test
void testGetAutomationCompositions() throws Exception {
- var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
-
- automationCompositionProvider
- .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList());
-
var automationComposition0 = inputAutomationCompositions.getAutomationCompositionList().get(1);
var name = automationComposition0.getName();
var version = automationComposition0.getVersion();
var automationComposition1 = inputAutomationCompositions.getAutomationCompositionList().get(1);
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
when(automationCompositionRepository.getFiltered(eq(JpaAutomationComposition.class), any(), any()))
.thenReturn(List.of(new JpaAutomationComposition(automationComposition0),
new JpaAutomationComposition(automationComposition1)));
@@ -141,6 +104,7 @@ class AutomationCompositionProviderTest {
when(automationCompositionRepository.findById(automationComposition1.getKey().asIdentifier().asConceptKey()))
.thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1)));
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
assertEquals(1, automationCompositionProvider.getAutomationCompositions(name, version).size());
var ac = automationCompositionProvider
@@ -163,15 +127,10 @@ class AutomationCompositionProviderTest {
assertThat(automationCompositionProvider
.findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty();
-
- when(automationCompositionRepository.findById(any())).thenThrow(IllegalArgumentException.class);
-
- assertThatThrownBy(() -> automationCompositionProvider.findAutomationComposition(ID_NAME_NOT_VALID, ID_VERSION))
- .hasMessageMatching("Not valid parameter");
}
@Test
- void testDeleteAutomationComposition() throws Exception {
+ void testDeleteAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);