summaryrefslogtreecommitdiffstats
path: root/models/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-04 17:04:37 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-01-06 08:52:36 +0000
commit026cfefbe02cfc87c04f13d4b5ce7085f3ee360b (patch)
tree23566f2de245403b1fd0cc31978bced13eaec3ea /models/src/test/java
parentbce4edfb6a9140a07d12470d977352d7b3a4105c (diff)
Refactor register deregister a Participant and Supervise Participants
Refactor register deregister a Participant and Supervise Participants using ON_LINE/OFF_LINE as Participant Status. Issue-ID: POLICY-4497 Change-Id: If9c5b92131c99132c18340e56334fb9453745526 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java6
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java6
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java54
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java45
4 files changed, 33 insertions, 78 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
index f50bf36bc..f6eb3e0ff 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,9 +59,8 @@ class ParticipantTest {
p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
p1.setDescription("Description");
- p1.setHealthStatus(ParticipantHealthStatus.HEALTHY);
p1.setName("Name");
- p1.setParticipantState(ParticipantState.ACTIVE);
+ p1.setParticipantState(ParticipantState.ON_LINE);
p1.setVersion("0.0.1");
assertThat(p1.toString()).contains("Participant(");
@@ -75,7 +74,6 @@ class ParticipantTest {
// @formatter:off
assertThatThrownBy(() -> p2.setDefinition(null)). isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> p2.setHealthStatus(null)). isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
// @formatter:on
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
index 7bf439e3f..51331b4bb 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDef
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -59,8 +58,7 @@ class ParticipantStatusTest {
ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4");
orig.setParticipantType(type);
orig.setMessageId(UUID.randomUUID());
- orig.setState(ParticipantState.ACTIVE);
- orig.setHealthStatus(ParticipantHealthStatus.HEALTHY);
+ orig.setState(ParticipantState.ON_LINE);
orig.setTimestamp(Instant.ofEpochMilli(3000));
var acInfo = getAutomationCompositionInfo(automationCompositionId);
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 3ff614918..9d1d7ff99 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
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.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -48,58 +47,52 @@ class JpaParticipantTest {
assertThatThrownBy(() -> new JpaParticipant((PfConceptKey) null)).hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, null, null)).hasMessageMatching(NULL_KEY_ERROR);
+ assertThatThrownBy(() -> new JpaParticipant(null, null, null)).hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, null, ParticipantHealthStatus.HEALTHY))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, null))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, null, ParticipantState.ACTIVE, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, null, ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(
- () -> new JpaParticipant(null, null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY))
+ () -> new JpaParticipant(null, null, ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), null))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, null))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE,
- ParticipantHealthStatus.HEALTHY))
+ assertThatThrownBy(() -> new JpaParticipant(null, new PfConceptKey(), ParticipantState.ON_LINE))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, null, null))
+ assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, null))
.hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, null, ParticipantHealthStatus.HEALTHY))
+ assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, null))
.hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, null))
+ assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, ParticipantState.ON_LINE))
.hasMessageMatching("definition is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE,
- ParticipantHealthStatus.HEALTHY)).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(new PfConceptKey(), new PfConceptKey(), null, null))
+ assertThatThrownBy(() -> new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null))
.hasMessageMatching("participantState is marked .*ull but is null");
assertThatThrownBy(
- () -> new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY))
+ () -> new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null))
.hasMessageMatching("participantState is marked .*ull but is null");
- assertThatThrownBy(
- () -> new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, null))
- .hasMessageMatching("healthStatus is marked .*ull but is null");
-
assertNotNull(new JpaParticipant());
assertNotNull(new JpaParticipant((new PfConceptKey())));
- assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE,
- ParticipantHealthStatus.HEALTHY));
+ assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ON_LINE));
}
@Test
@@ -171,16 +164,10 @@ class JpaParticipantTest {
testJpaParticipant.setDefinition(new PfConceptKey("participantDefinitionName", "0.0.1"));
assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setParticipantState(ParticipantState.PASSIVE);
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setParticipantState(ParticipantState.UNKNOWN);
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
-
- testJpaParticipant.setHealthStatus(ParticipantHealthStatus.NOT_HEALTHY);
+ testJpaParticipant.setParticipantState(ParticipantState.OFF_LINE);
assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setHealthStatus(ParticipantHealthStatus.UNKNOWN);
+ testJpaParticipant.setParticipantState(ParticipantState.ON_LINE);
assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
-
assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
}
@@ -199,9 +186,8 @@ class JpaParticipantTest {
p1.setDefinition(new PfConceptKey("defName", "0.0.1"));
p1.setDescription("Description");
- p1.setHealthStatus(ParticipantHealthStatus.HEALTHY);
p1.setKey(new PfConceptKey("participant", "0.0.1"));
- p1.setParticipantState(ParticipantState.ACTIVE);
+ p1.setParticipantState(ParticipantState.ON_LINE);
assertThat(p1.toString()).contains("Participant(");
assertNotEquals(0, p1.hashCode());
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 c7355f002..e11541988 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,13 +40,14 @@ import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class ParticipantProviderTest {
private static final Coder CODER = new StandardCoder();
private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
+ private static final ToscaConceptIdentifier INVALID_ID = new ToscaConceptIdentifier("invalid_name", "1.0.1");
private final List<Participant> inputParticipants = new ArrayList<>();
private List<JpaParticipant> jpaParticipantList;
@@ -67,18 +68,12 @@ class ParticipantProviderTest {
}
var participantProvider = new ParticipantProvider(participantRepository);
- assertThatThrownBy(() -> participantProvider.saveParticipant(null))
- .hasMessageMatching(LIST_IS_NULL);
+ assertThatThrownBy(() -> participantProvider.saveParticipant(null)).hasMessageMatching(LIST_IS_NULL);
when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0));
assertEquals(savedParticipant, inputParticipants.get(0));
-
- when(participantRepository.save(any())).thenThrow(IllegalArgumentException.class);
-
- assertThatThrownBy(() -> participantProvider.saveParticipant(inputParticipants.get(0)))
- .hasMessageMatching("Error in save Participant");
}
@Test
@@ -98,26 +93,10 @@ class ParticipantProviderTest {
assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty();
- assertThat(participantProvider.findParticipant("invalid_name", "1.0.1")).isEmpty();
+ assertThat(participantProvider.findParticipant(INVALID_ID)).isEmpty();
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size());
-
- when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class);
-
- assertThatThrownBy(() -> participantProvider.findParticipant("notValid", "notValid"))
- .hasMessageMatching("Error in find Participant");
-
- assertThatThrownBy(() -> participantProvider.getFilteredParticipants(null))
- .hasMessageMatching("filter is marked .*ull but is null");
-
- when(participantRepository.getFiltered((JpaParticipant.class), (null), (null)))
- .thenReturn(jpaParticipantList);
-
- final ToscaTypedEntityFilter<Participant> filter = ToscaTypedEntityFilter.<Participant>builder()
- .type("org.onap.domain.pmsh.PMSHAutomationCompositionDefinition").build();
- assertEquals(1, participantProvider.getFilteredParticipants(filter).size());
-
}
@Test
@@ -125,19 +104,13 @@ class ParticipantProviderTest {
var participantRepository = mock(ParticipantRepository.class);
var participantProvider = new ParticipantProvider(participantRepository);
- assertThatThrownBy(() -> participantProvider.deleteParticipant("Invalid_name", "1.0.1"))
- .hasMessageMatching(".*.failed, participant does not exist");
-
- String name = inputParticipants.get(0).getName();
- String version = inputParticipants.get(0).getVersion();
+ assertThatThrownBy(() -> participantProvider.deleteParticipant(INVALID_ID))
+ .hasMessageMatching(".*.failed, participant does not exist");
when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0)));
- Participant deletedParticipant = participantProvider.deleteParticipant(name, version);
+ Participant deletedParticipant =
+ participantProvider.deleteParticipant(inputParticipants.get(0).getDefinition());
assertEquals(inputParticipants.get(0), deletedParticipant);
-
- when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class);
- assertThatThrownBy(() -> participantProvider.deleteParticipant(name, version))
- .hasMessageMatching("Error in delete Participant");
}
}