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/concepts/AutomationCompositionDefinitionTest.java47
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java41
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java23
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java15
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java102
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java22
6 files changed, 213 insertions, 37 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java
new file mode 100644
index 000000000..aa084b4f2
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinitionTest.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.concepts;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class AutomationCompositionDefinitionTest {
+
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML = "clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
+
+ @Test
+ void testCopyContructor() {
+ var acDefinition = new AutomationCompositionDefinition();
+ acDefinition.setCompositionId(UUID.randomUUID());
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier());
+ acDefinition.setElementStateMap(Map.of("key", nodeTemplateState));
+ acDefinition.setServiceTemplate(CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
+ acDefinition.setState(AcTypeState.COMMISSIONED);
+ var result = new AutomationCompositionDefinition(acDefinition);
+ assertEquals(result, acDefinition);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java
new file mode 100644
index 000000000..a850c88dc
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateStateTest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.concepts;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class NodeTemplateStateTest {
+
+ @Test
+ void testCopyContructor() {
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier());
+ nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID());
+ nodeTemplateState.setParticipantId(UUID.randomUUID());
+ nodeTemplateState.setState(AcTypeState.COMMISSIONED);
+ var result = new NodeTemplateState(nodeTemplateState);
+ assertEquals(result, nodeTemplateState);
+ }
+}
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 0ae1a90e2..c6af96742 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
@@ -26,6 +26,8 @@ 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.Map;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
@@ -34,7 +36,7 @@ class ParticipantTest {
@Test
void testParticipantLombok() {
assertNotNull(new Participant());
- Participant p0 = new Participant();
+ var p0 = new Participant();
assertThat(p0.toString()).contains("Participant(");
assertThat(p0.hashCode()).isNotZero();
@@ -42,7 +44,7 @@ class ParticipantTest {
assertNotEquals(null, p0);
- Participant p1 = new Participant();
+ var p1 = new Participant();
p1.setParticipantId(CommonTestData.getParticipantId());
p1.setParticipantState(ParticipantState.ON_LINE);
@@ -54,7 +56,7 @@ class ParticipantTest {
assertNotEquals(p1, p0);
- Participant p2 = new Participant();
+ var p2 = new Participant();
// @formatter:off
assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
@@ -62,4 +64,19 @@ class ParticipantTest {
assertEquals(p2, p0);
}
+
+ @Test
+ void testCopyConstructor() {
+ var p0 = new Participant();
+ p0.setParticipantId(UUID.randomUUID());
+ p0.setParticipantState(ParticipantState.ON_LINE);
+ var supportedElementType = new ParticipantSupportedElementType();
+ supportedElementType.setId(UUID.randomUUID());
+ supportedElementType.setTypeName("type");
+ supportedElementType.setTypeVersion("1.0.0");
+ p0.setParticipantSupportedElementTypes(Map.of(supportedElementType.getId(), supportedElementType));
+
+ var p2 = new Participant(p0);
+ assertEquals(p2, p0);
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java
index fac98043d..5a82466d6 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantsSupportedElementTypesTest.java
@@ -31,16 +31,15 @@ import org.junit.jupiter.api.Test;
public class ParticipantsSupportedElementTypesTest {
private static final String ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e";
- private static final String PARTICIPANT_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a";
@Test
void testParticipant() {
- ParticipantSupportedElementType p0 = new ParticipantSupportedElementType();
+ var p0 = new ParticipantSupportedElementType();
p0.setId(UUID.fromString(ID));
assertEquals(ID, p0.getId().toString());
- ParticipantSupportedElementType p1 = new ParticipantSupportedElementType(p0);
+ var p1 = new ParticipantSupportedElementType(p0);
assertThat(p0).usingRecursiveComparison().isEqualTo(p1);
}
@@ -48,27 +47,27 @@ public class ParticipantsSupportedElementTypesTest {
@Test
void testParticipantLombok() {
assertNotNull(new ParticipantSupportedElementType());
- ParticipantSupportedElementType p0 = new ParticipantSupportedElementType();
+ var p0 = new ParticipantSupportedElementType();
- assertThat(p0.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType");
+ assertThat(p0.toString()).contains("ParticipantSupportedElementType");
assertThat(p0.hashCode()).isNotZero();
assertThat(p0).usingRecursiveComparison().isEqualTo(new ParticipantSupportedElementType(p0));
assertNotEquals(null, p0);
- ParticipantSupportedElementType p1 = new ParticipantSupportedElementType();
+ var p1 = new ParticipantSupportedElementType();
p1.setId(UUID.fromString(ID));
p1.setTypeName("name");
p1.setTypeVersion("1.0.0");
- assertThat(p1.toString()).contains("org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType");
+ assertThat(p1.toString()).contains("ParticipantSupportedElementType");
assertNotEquals(0, p1.hashCode());
assertNotEquals(p1, p0);
assertNotEquals(null, p1);
- ParticipantSupportedElementType p2 = new ParticipantSupportedElementType();
+ var p2 = new ParticipantSupportedElementType();
p2.setId(p0.getId());
assertThat(p0).usingRecursiveComparison().isEqualTo(p2);
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 59e3767d1..a27a74be4 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-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.
@@ -22,24 +22,26 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
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.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardYamlCoder;
-import org.onap.policy.common.utils.resources.ResourceUtils;
+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;
import org.springframework.data.domain.Example;
@@ -49,19 +51,17 @@ class AcDefinitionProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML_PROP =
"clamp/acm/test/tosca-template-additional-properties.yaml";
- private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
-
private static ToscaServiceTemplate inputServiceTemplate;
@BeforeAll
static void loadServiceTemplate() {
- inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ inputServiceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
}
@Test
void testDocCopyCompare() {
- var inputServiceTemplateProperties = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP);
+ var inputServiceTemplateProperties = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP);
var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplateProperties);
var docServiceTemplateCopy = new DocToscaServiceTemplate(docServiceTemplate);
@@ -71,8 +71,8 @@ class AcDefinitionProviderTest {
var acmDefinition = getAcDefinition(docServiceTemplate);
var acmDefinitionCopy = getAcDefinition(docServiceTemplateCopy);
- assertThat(acmDefinition.getServiceTemplate().getName()).isEqualTo(
- acmDefinitionCopy.getServiceTemplate().getName());
+ assertThat(acmDefinition.getServiceTemplate().getName())
+ .isEqualTo(acmDefinitionCopy.getServiceTemplate().getName());
}
@@ -92,6 +92,65 @@ class AcDefinitionProviderTest {
}
@Test
+ void testUpdateServiceTemplate() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ acDefinitionProvider.updateServiceTemplate(UUID.randomUUID(), inputServiceTemplate);
+ verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.class));
+ }
+
+ @Test
+ void testUpdateAcDefinition() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var acmDefinition = getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate));
+ acDefinitionProvider.updateAcDefinition(acmDefinition);
+ verify(acmDefinitionRepository).save(any(JpaAutomationCompositionDefinition.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 result = acDefinitionProvider.getAcDefinition(UUID.fromString(jpa.getCompositionId()));
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ void testGetAcDefinitionNotFound() {
+ var acmDefinitionRepository = mock(AutomationCompositionDefinitionRepository.class);
+ var acDefinitionProvider = new AcDefinitionProvider(acmDefinitionRepository);
+ var compositionId = UUID.randomUUID();
+ assertThatThrownBy(() -> acDefinitionProvider.getAcDefinition(compositionId))
+ .hasMessage("Get serviceTemplate \"" + compositionId + "\" failed, serviceTemplate does not exist");
+ }
+
+ @Test
+ void testFindAcDefinition() {
+ 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 result = acDefinitionProvider.findAcDefinition(UUID.fromString(jpa.getCompositionId()));
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ void testGetAllAcDefinitions() {
+ var jpa = new JpaAutomationCompositionDefinition();
+ jpa.fromAuthorative(getAcDefinition(new DocToscaServiceTemplate(inputServiceTemplate)));
+ 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);
+ }
+
+ @Test
void testDeleteAcDefintion() {
var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplate);
var acmDefinition = getAcDefinition(docServiceTemplate);
@@ -135,22 +194,13 @@ class AcDefinitionProviderTest {
private AutomationCompositionDefinition getAcDefinition(DocToscaServiceTemplate docServiceTemplate) {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
+ acmDefinition.setState(AcTypeState.COMMISSIONED);
acmDefinition.setServiceTemplate(docServiceTemplate.toAuthorative());
+ var nodeTemplateState = new NodeTemplateState();
+ nodeTemplateState.setNodeTemplateStateId(UUID.randomUUID());
+ nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier("name", "1.0.0"));
+ nodeTemplateState.setState(AcTypeState.COMMISSIONED);
+ acmDefinition.setElementStateMap(Map.of(nodeTemplateState.getNodeTemplateId().getName(), nodeTemplateState));
return acmDefinition;
}
-
- /**
- * Get ToscaServiceTemplate from resource.
- *
- * @param path path of the resource
- */
- public static ToscaServiceTemplate getToscaServiceTemplate(String path) {
-
- try {
- return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class);
- } catch (CoderException e) {
- fail("Cannot read or decode " + path);
- return null;
- }
- }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
index 88ace1706..21666e484 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
@@ -20,7 +20,13 @@
package org.onap.policy.clamp.models.acm.utils;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.UUID;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Class to hold/create all parameters for test cases.
@@ -29,6 +35,8 @@ import java.util.UUID;
public class CommonTestData {
public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
+ private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
+
/**
* Returns participantId for test cases.
@@ -56,4 +64,18 @@ public class CommonTestData {
public static UUID getRndParticipantId() {
return UUID.randomUUID();
}
+
+ /**
+ * Get ToscaServiceTemplate from resource.
+ *
+ * @param path path of the resource
+ */
+ public static ToscaServiceTemplate getToscaServiceTemplate(String path) {
+ try {
+ return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class);
+ } catch (CoderException e) {
+ fail("Cannot read or decode " + path);
+ return null;
+ }
+ }
}