aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test
diff options
context:
space:
mode:
authorsaul.gill <saul.gill@est.tech>2023-01-10 11:11:08 +0000
committersaul.gill <saul.gill@est.tech>2023-01-12 13:44:44 +0000
commitadfe6d2d2e5b11a24208b3bce5383f1c38cec61e (patch)
treea9dd70e6e6a5f759bce1936201820aadb62ff280 /models/src/test
parent0b1764cac4b0071b66295cf14bf43b22ed3bc20d (diff)
Add participant controller in ACM
Added participant controller Altered openapi spec Added participantId Issue-ID: POLICY-4496 Change-Id: I0c0ea93dacb6927e6f16bd4638d03db6266be3bd Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'models/src/test')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java51
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java36
-rw-r--r--models/src/test/resources/providers/TestParticipant.json1
3 files changed, 66 insertions, 22 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
index 9d1d7ff99..0fbdaa2bc 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
@@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
@@ -47,52 +48,54 @@ class JpaParticipantTest {
assertThatThrownBy(() -> new JpaParticipant((PfConceptKey) null)).hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, null)).hasMessageMatching(NULL_KEY_ERROR);
+ assertThatThrownBy(() -> new JpaParticipant(null, null, null, null)).hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, null, null))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, ParticipantState.ON_LINE))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(
- () -> new JpaParticipant(null, null, ParticipantState.ON_LINE))
+ () -> new JpaParticipant(null, null, null, ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), null))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), ParticipantState.ON_LINE))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), ParticipantState.ON_LINE))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, new PfConceptKey(), ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, null))
.hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, null))
.hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, ParticipantState.ON_LINE))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, ParticipantState.ON_LINE))
.hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, ParticipantState.ON_LINE
- )).hasMessageMatching("definition is marked .*ull but is null");
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, ParticipantState.ON_LINE
+ )).hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null))
.hasMessageMatching("participantState is marked .*ull but is null");
assertThatThrownBy(
- () -> new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null))
+ () -> new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), null))
.hasMessageMatching("participantState is marked .*ull but is null");
assertNotNull(new JpaParticipant());
assertNotNull(new JpaParticipant((new PfConceptKey())));
- assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ON_LINE));
+ assertNotNull(new JpaParticipant(null, new PfConceptKey(), new PfConceptKey(), ParticipantState.ON_LINE));
+ assertNotNull(new JpaParticipant(UUID.randomUUID().toString(), new PfConceptKey(),
+ new PfConceptKey(), ParticipantState.ON_LINE));
}
@Test
@@ -100,6 +103,9 @@ class JpaParticipantTest {
JpaParticipant testJpaParticipant = createJpaParticipantInstance();
Participant participant = createParticipantInstance();
+
+ participant.setParticipantId(testJpaParticipant.toAuthorative().getParticipantId());
+
assertEquals(participant, testJpaParticipant.toAuthorative());
assertThatThrownBy(() -> testJpaParticipant.fromAuthorative(null))
@@ -110,6 +116,7 @@ class JpaParticipantTest {
JpaParticipant testJpaParticipantFa = new JpaParticipant();
testJpaParticipantFa.setKey(null);
testJpaParticipantFa.fromAuthorative(participant);
+ testJpaParticipantFa.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, testJpaParticipantFa);
testJpaParticipantFa.setKey(PfConceptKey.getNullKey());
testJpaParticipantFa.fromAuthorative(participant);
@@ -119,9 +126,9 @@ class JpaParticipantTest {
assertEquals(testJpaParticipant, testJpaParticipantFa);
assertEquals("participant", testJpaParticipant.getKey().getName());
- assertEquals("participant", new JpaParticipant(createParticipantInstance()).getKey().getName());
+ assertEquals("participant", new JpaParticipant(createJpaParticipantInstance()).getKey().getName());
assertEquals("participant",
- ((PfConceptKey) new JpaParticipant(createParticipantInstance()).getKeys().get(0)).getName());
+ ((PfConceptKey) new JpaParticipant(createJpaParticipantInstance()).getKeys().get(0)).getName());
testJpaParticipant.clean();
assertEquals("participant", testJpaParticipant.getKey().getName());
@@ -131,6 +138,7 @@ class JpaParticipantTest {
assertEquals("A Message", testJpaParticipant.getDescription());
JpaParticipant testJpaParticipant2 = new JpaParticipant(testJpaParticipant);
+ testJpaParticipant2.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, testJpaParticipant2);
}
@@ -149,6 +157,7 @@ class JpaParticipantTest {
JpaParticipant testJpaParticipant = createJpaParticipantInstance();
JpaParticipant otherJpaParticipant = new JpaParticipant(testJpaParticipant);
+ otherJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
assertEquals(-1, testJpaParticipant.compareTo(null));
assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant));
@@ -169,6 +178,10 @@ class JpaParticipantTest {
testJpaParticipant.setParticipantState(ParticipantState.ON_LINE);
assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
+
+ JpaParticipant newJpaParticipant = new JpaParticipant(testJpaParticipant);
+ newJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
+ assertEquals(testJpaParticipant, newJpaParticipant);
}
@Test
@@ -197,6 +210,7 @@ class JpaParticipantTest {
assertNotEquals(p1, p0);
JpaParticipant p2 = new JpaParticipant();
+ p2.setParticipantId(p0.getParticipantId());
assertEquals(p2, p0);
}
@@ -204,6 +218,7 @@ class JpaParticipantTest {
Participant testParticipant = createParticipantInstance();
JpaParticipant testJpaParticipant = new JpaParticipant();
testJpaParticipant.setKey(null);
+ testParticipant.setParticipantId(UUID.fromString(testJpaParticipant.getParticipantId()));
testJpaParticipant.fromAuthorative(testParticipant);
testJpaParticipant.setKey(PfConceptKey.getNullKey());
testJpaParticipant.fromAuthorative(testParticipant);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
index e11541988..6e6637c7e 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
@@ -64,7 +64,7 @@ class ParticipantProviderTest {
var participantRepository = mock(ParticipantRepository.class);
for (var participant : jpaParticipantList) {
when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion())))
- .thenReturn(participant);
+ .thenReturn(participant);
}
var participantProvider = new ParticipantProvider(participantRepository);
@@ -73,10 +73,30 @@ class ParticipantProviderTest {
when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0));
+ savedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId());
assertEquals(savedParticipant, inputParticipants.get(0));
}
@Test
+ void testParticipantUpdate() throws Exception {
+ var participantRepository = mock(ParticipantRepository.class);
+ for (var participant : jpaParticipantList) {
+ when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion())))
+ .thenReturn(participant);
+ }
+ var participantProvider = new ParticipantProvider(participantRepository);
+
+ assertThatThrownBy(() -> participantProvider.updateParticipant(null))
+ .hasMessageMatching(LIST_IS_NULL);
+
+ when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
+
+ Participant updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0));
+ updatedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId());
+ assertEquals(updatedParticipant, inputParticipants.get(0));
+ }
+
+ @Test
void testGetAutomationCompositions() throws Exception {
var participantRepository = mock(ParticipantRepository.class);
var participantProvider = new ParticipantProvider(participantRepository);
@@ -88,7 +108,7 @@ class ParticipantProviderTest {
String name = inputParticipants.get(0).getName();
String version = inputParticipants.get(0).getVersion();
when(participantRepository.getFiltered(any(), eq(name), eq(version)))
- .thenReturn(List.of(jpaParticipantList.get(0)));
+ .thenReturn(List.of(jpaParticipantList.get(0)));
assertEquals(1, participantProvider.getParticipants(name, version).size());
assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty();
@@ -97,6 +117,14 @@ class ParticipantProviderTest {
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size());
+
+ when(participantRepository.findByParticipantId(any())).thenReturn(
+ Optional.ofNullable(jpaParticipantList.get(0)));
+
+ var participant = participantProvider.getParticipantById(inputParticipants.get(0)
+ .getParticipantId().toString());
+
+ assertThat(participant).isEqualTo(inputParticipants.get(0));
}
@Test
@@ -105,12 +133,12 @@ class ParticipantProviderTest {
var participantProvider = new ParticipantProvider(participantRepository);
assertThatThrownBy(() -> participantProvider.deleteParticipant(INVALID_ID))
- .hasMessageMatching(".*.failed, participant does not exist");
+ .hasMessageMatching(".*.failed, participant does not exist");
when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0)));
Participant deletedParticipant =
- participantProvider.deleteParticipant(inputParticipants.get(0).getDefinition());
+ participantProvider.deleteParticipant(inputParticipants.get(0).getDefinition());
assertEquals(inputParticipants.get(0), deletedParticipant);
}
}
diff --git a/models/src/test/resources/providers/TestParticipant.json b/models/src/test/resources/providers/TestParticipant.json
index 5d8a7ea09..99284cb6a 100644
--- a/models/src/test/resources/providers/TestParticipant.json
+++ b/models/src/test/resources/providers/TestParticipant.json
@@ -7,6 +7,7 @@
},
"participantState": "ON_LINE",
"description": "A dummy PMSH participant1",
+ "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6",
"participantType":{
"name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition",
"version": "1.0.0"