aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java/org
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2025-02-11 16:22:22 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2025-02-11 16:47:23 +0000
commite3c94609eba45f2c4e10ab52024709bd9a216aca (patch)
treea36ac2bdf866636b36eb6c6e51bef6af1b4b6ab1 /models/src/test/java/org
parenta3bd73b57f83cd11d58a33f81a13139462d64563 (diff)
Add consumer producer messages support in ACM-r model
Issue-ID: POLICY-5276 Change-Id: I7f11cec08de46996d5e3f487566f7cc37f441a31 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java/org')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java50
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java90
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToDocMessageTest.java60
3 files changed, 200 insertions, 0 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java
new file mode 100644
index 000000000..bf673bed5
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageJobTest.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.persistence.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+
+class JpaMessageJobTest {
+
+ @Test
+ void testJpaMessageJobConstructor() {
+ assertThatThrownBy(() -> new JpaMessageJob(null))
+ .hasMessageMatching("identificationId is marked .*ull but is null");
+ }
+
+ @Test
+ void testJpaMessageValidation() {
+ var jpaMessageJob = new JpaMessageJob();
+
+ assertThatThrownBy(() -> jpaMessageJob.validate(null))
+ .hasMessageMatching("fieldName is marked .*ull but is null");
+
+ assertTrue(jpaMessageJob.validate("").isValid());
+
+ jpaMessageJob.setJobStarted(null);
+ assertFalse(jpaMessageJob.validate("").isValid());
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java
new file mode 100644
index 000000000..f9a19c408
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaMessageTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.persistence.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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.DeployState;
+import org.onap.policy.clamp.models.acm.document.concepts.DocMessage;
+import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
+
+class JpaMessageTest {
+
+ @Test
+ void testJpaMessageConstructor() {
+ assertThatThrownBy(() -> new JpaMessage(null, new DocMessage()))
+ .hasMessageMatching("identificationId is marked .*ull but is null");
+ assertThatThrownBy(() -> new JpaMessage(UUID.randomUUID().toString(), null))
+ .hasMessageMatching("docMessage is marked .*ull but is null");
+ }
+
+ @Test
+ void testJpaMessageValidation() {
+ var docMessage = createDocMessage();
+ var jpaMessage = new JpaMessage(docMessage.getInstanceId().toString(), docMessage);
+
+ assertThatThrownBy(() -> jpaMessage.validate(null))
+ .hasMessageMatching("fieldName is marked .*ull but is null");
+
+ assertTrue(jpaMessage.validate("").isValid());
+
+ jpaMessage.setLastMsg(null);
+ assertFalse(jpaMessage.validate("").isValid());
+ }
+
+ @Test
+ void testJpaMessage() {
+ var docMessage = createDocMessage();
+ var jpaMessage = new JpaMessage(docMessage.getInstanceId().toString(), docMessage);
+ docMessage.setMessageId(jpaMessage.getMessageId());
+
+ assertEquals(docMessage, jpaMessage.toAuthorative());
+
+ assertThatThrownBy(() -> jpaMessage.fromAuthorative(null))
+ .hasMessageMatching("docMessage is marked .*ull but is null");
+
+ assertThatThrownBy(() -> new JpaMessage((JpaMessage) null)).isInstanceOf(NullPointerException.class);
+
+ var jpaMessageFa = new JpaMessage();
+ jpaMessageFa.setIdentificationId(docMessage.getInstanceId().toString());
+ jpaMessageFa.setLastMsg(jpaMessage.getLastMsg());
+ jpaMessageFa.setMessageId(jpaMessage.getMessageId());
+ jpaMessageFa.fromAuthorative(docMessage);
+ assertEquals(jpaMessage, jpaMessageFa);
+
+ var jpaMessage2 = new JpaMessage(jpaMessage);
+ assertEquals(jpaMessage, jpaMessage2);
+ }
+
+ private DocMessage createDocMessage() {
+ var docMessage = new DocMessage();
+ docMessage.setMessageType(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
+ docMessage.setCompositionId(UUID.randomUUID());
+ docMessage.setInstanceId(UUID.randomUUID());
+ docMessage.setDeployState(DeployState.DEPLOYED);
+ return docMessage;
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToDocMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToDocMessageTest.java
new file mode 100644
index 000000000..84dc3409d
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToDocMessageTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.persistence.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.document.concepts.DocMessage;
+import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageType;
+import org.onap.policy.models.base.PfModelRuntimeException;
+
+class StringToDocMessageTest {
+
+ @Test
+ void testConvert() {
+ var stringToDocMessage = new StringToDocMessage();
+ var docMessage = new DocMessage();
+ docMessage.setMessageId(UUID.randomUUID().toString());
+ docMessage.setInstanceId(UUID.randomUUID());
+ docMessage.setCompositionId(UUID.randomUUID());
+ docMessage.setStage(0);
+ docMessage.setMessageType(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
+ var dbData = stringToDocMessage.convertToDatabaseColumn(docMessage);
+ var result = stringToDocMessage.convertToEntityAttribute(dbData);
+ assertEquals(docMessage, result);
+ }
+
+ @Test
+ void testNull() {
+ var stringToDocMessage = new StringToDocMessage();
+ var dbData = stringToDocMessage.convertToDatabaseColumn(null);
+ assertThat(dbData).isNull();
+ var map = stringToDocMessage.convertToEntityAttribute(null);
+ assertThat(map).isNotNull();
+ assertThatThrownBy(() -> stringToDocMessage.convertToEntityAttribute("1"))
+ .isInstanceOf(PfModelRuntimeException.class);
+ }
+
+}