summaryrefslogtreecommitdiffstats
path: root/asdctool/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src/test/java')
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java130
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java257
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java9
3 files changed, 268 insertions, 128 deletions
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java
index 2b169e9db8..4813cff764 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java
@@ -21,77 +21,71 @@
package org.openecomp.sdc.asdctool.impl.validator.config;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Properties;
-
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ReportManager.class})
public class ValidationConfigManagerTest {
- private ValidationConfigManager createTestSubject() {
- return new ValidationConfigManager();
- }
-
-
- @Test
- public void testGetOutputFilePath() {
- String result;
-
- // default test
- result = ValidationConfigManager.getOutputFilePath();
- }
-
- @Test
- public void testGetCsvReportFilePath() {
- String result;
-
- // default test
- result = ValidationConfigManager.getCsvReportFilePath();
- }
-
-
- @Test
- public void testSetCsvReportFilePath() {
- String outputPath = "";
-
- // default test
- ValidationConfigManager.setCsvReportFilePath(outputPath);
- }
-
-
- @Test
- public void testSetValidationConfiguration() {
- String path = "";
- Properties result;
-
- // default test
- result = ValidationConfigManager.setValidationConfiguration(path);
- }
-
-
- @Test
- public void testGetValidationConfiguration() {
- Properties result;
-
- // default test
- result = ValidationConfigManager.getValidationConfiguration();
- }
-
-
- @Test
- public void testGetOutputFullFilePath() throws Exception {
- String result;
-
- // default test
- result=ValidationConfigManager.getOutputFullFilePath();
- }
-
-
- @Test
- public void testSetOutputFullFilePath() throws Exception {
- String outputPath = "";
-
-
- // default test
- ValidationConfigManager.setOutputFullFilePath(outputPath);
- }
+ @Test
+ public void testGetOutputFilePath() {
+ String result;
+
+ // default test
+ result = ValidationConfigManager.getOutputFilePath();
+ }
+
+ @Test
+ public void testGetCsvReportFilePath() {
+ String result;
+
+ // default test
+ result = ValidationConfigManager.getCsvReportFilePath();
+ }
+
+ @Test
+ public void testSetCsvReportFilePath() {
+ String outputPath = "";
+
+ // default test
+ ValidationConfigManager.setCsvReportFilePath(outputPath);
+ }
+
+ @Test
+ public void testSetValidationConfiguration() {
+ String path = "";
+ Properties result;
+
+ // default test
+ result = ValidationConfigManager.setValidationConfiguration(path);
+ }
+
+ @Test
+ public void testGetValidationConfiguration() {
+ Properties result;
+
+ // default test
+ result = ValidationConfigManager.getValidationConfiguration();
+ }
+
+ @Test
+ public void testGetOutputFullFilePath() throws Exception {
+ String result;
+
+ // default test
+ result = ValidationConfigManager.getOutputFullFilePath();
+ }
+
+ @Test
+ public void testSetOutputFullFilePath() throws Exception {
+ String outputPath = "";
+
+ // default test
+ ValidationConfigManager.setOutputFullFilePath(outputPath);
+ }
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
index 5053f4b9e3..2dca89f2fa 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
@@ -3,13 +3,14 @@
* SDC
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (c) 2019 Samsung
* ================================================================================
* 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.
@@ -20,69 +21,209 @@
package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts;
-import static org.mockito.Mockito.mock;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
+import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
-
-import java.util.List;
-import java.util.Map;
+import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import fj.data.Either;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(MockitoJUnitRunner.class)
+@PrepareForTest({ReportManager.class})
public class ArtifactValidationUtilsTest {
+
+ @Mock
+ private ArtifactCassandraDao artifactCassandraDao;
+ @Mock
+ private TopologyTemplateOperation topologyTemplateOperation;
+ @InjectMocks
+ private ArtifactValidationUtils testSubject;
+
+ @Mock
+ private GraphVertex vertex;
+ @Mock
+ private MapArtifactDataDefinition mapToscaDataDefinition;
+ @Mock
+ private ArtifactDataDefinition artifactDataDefinition;
+ @Mock
+ private ArtifactDataDefinition artifactDataDefinitionNotInCassandra;
+ @Mock
+ private ArtifactDataDefinition artifactDataDefinitionDummy;
+ @Mock
+ private TopologyTemplate topologyTemplate;
+
+ private static final String ES_ID = "testEsInCassandra";
+ private static final String ES_ID_NOT_IN_CASS = "testEsNotInCassandra";
+ private static final String TASK_NAME = "testTaskName";
+ private static final String UNIQUE_ID = "4321";
+ private static final String UNIQUE_ID_VERTEX = "321";
+
+ public void initReportManager() {
+ String resourcePath = new File(Objects
+ .requireNonNull(ArtifactValidationUtilsTest.class.getClassLoader().getResource(""))
+ .getFile()).getAbsolutePath();
+ ValidationConfigManager.setOutputFullFilePath(resourcePath);
+ new ReportManager();
+ }
+
+ @Before
+ public void setup() {
+ initReportManager();
+ when(artifactCassandraDao.getCountOfArtifactById(ES_ID)).thenReturn(Either.left(1L));
+ when(artifactCassandraDao.getCountOfArtifactById(ES_ID_NOT_IN_CASS))
+ .thenReturn(Either.right(CassandraOperationStatus.NOT_FOUND));
+
+ when(artifactDataDefinition.getEsId()).thenReturn(ES_ID);
+ when(artifactDataDefinitionNotInCassandra.getEsId()).thenReturn(ES_ID_NOT_IN_CASS);
+
+ when(artifactDataDefinitionNotInCassandra.getUniqueId()).thenReturn(UNIQUE_ID);
+ when(vertex.getUniqueId()).thenReturn(UNIQUE_ID_VERTEX);
+ }
+
+ @Test
+ public void testValidateArtifactsAreInCassandra() {
+ // given
+ List<ArtifactDataDefinition> artifacts = new ArrayList<>();
+ artifacts.add(artifactDataDefinition);
+
+ // when
+ ArtifactsVertexResult result =
+ testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts);
+
+ // then
+ assertTrue(result.getStatus());
+ assertEquals(0, result.notFoundArtifacts.size());
+ }
+
+ @Test
+ public void testValidateArtifactsNotInCassandra() {
+ // given
+ List<ArtifactDataDefinition> artifacts = new ArrayList<>();
+ artifacts.add(artifactDataDefinition);
+ artifacts.add(artifactDataDefinitionNotInCassandra);
+
+ // when
+ ArtifactsVertexResult result =
+ testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts);
+
+ // then
+ assertFalse(result.getStatus());
+ assertEquals(1, result.notFoundArtifacts.size());
+ assertEquals(UNIQUE_ID, result.notFoundArtifacts.iterator().next());
+ }
+
+ @Test
+ public void testIsArtifactsInCassandra() {
+ // when
+ boolean notInCass = testSubject.isArtifactInCassandra(ES_ID_NOT_IN_CASS);
+ boolean inCass = testSubject.isArtifactInCassandra(ES_ID);
+
+ // then
+ assertFalse(notInCass);
+ assertTrue(inCass);
+ }
+
+ @Test
+ public void testAddRelevantArtifacts() {
+ // given
+ Map<String, ArtifactDataDefinition> artifactsMap = new HashMap<>();
+ artifactsMap.put(ES_ID_NOT_IN_CASS, artifactDataDefinitionNotInCassandra);
+ artifactsMap.put(ES_ID, artifactDataDefinition);
+
+ // when
+ List<ArtifactDataDefinition> result = testSubject.addRelevantArtifacts(artifactsMap);
+
+ // then
+ result.forEach(Assert::assertNotNull);
+ }
+
+ @Test
+ public void testAddRelevantArtifactsWithNullEsId() {
+ // given
+ Map<String, ArtifactDataDefinition> artifactsMap = new HashMap<>();
+ artifactsMap.put("", artifactDataDefinitionDummy);
+
+ // when
+ List<ArtifactDataDefinition> result = testSubject.addRelevantArtifacts(artifactsMap);
+
+ // then
+ assertEquals(0, result.size());
+ }
+
+ @Test
+ public void testValidateTopologyTemplateArtifacts() {
+ // given
+ Map<String, ArtifactDataDefinition> artifacts = new HashMap<>();
+ artifacts.put(ES_ID, artifactDataDefinition);
+
+ when(topologyTemplate.getDeploymentArtifacts()).thenReturn(artifacts);
+ when(topologyTemplate.getArtifacts()).thenReturn(artifacts);
+ when(topologyTemplate.getServiceApiArtifacts()).thenReturn(artifacts);
+
+ when(mapToscaDataDefinition.getMapToscaDataDefinition()).thenReturn(artifacts);
+ Map<String, MapArtifactDataDefinition> artifactsMap = new HashMap<>();
+ artifactsMap.put(ES_ID, mapToscaDataDefinition);
+
+ when(topologyTemplate.getInstanceArtifacts()).thenReturn(artifactsMap);
+ when(topologyTemplate.getInstDeploymentArtifacts()).thenReturn(artifactsMap);
+
+ when(topologyTemplateOperation.getToscaElement(eq(vertex.getUniqueId()), any()))
+ .thenReturn(Either.left(topologyTemplate));
+
+ // when
+ ArtifactsVertexResult result =
+ testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME);
+
+ // then
+ assertTrue(result.getStatus());
+ assertEquals(0, result.notFoundArtifacts.size());
+ }
+
+ @Test
+ public void testValidateTopologyTemplateArtifactsNotFoundToscaElement() {
+ // given
+ when(topologyTemplateOperation.getToscaElement(eq(vertex.getUniqueId()), any()))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+
+ // when
+ ArtifactsVertexResult result =
+ testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME);
- private ArtifactValidationUtils createTestSubject() {
- ArtifactCassandraDao artifactCassandraDao = mock(ArtifactCassandraDao.class);
- TopologyTemplateOperation topologyTemplateOperation = mock(TopologyTemplateOperation.class);
- return new ArtifactValidationUtils(artifactCassandraDao, topologyTemplateOperation);
- }
-
- @Test(expected=NullPointerException.class)
- public void testValidateArtifactsAreInCassandra() throws Exception {
- ArtifactValidationUtils testSubject;
- GraphVertex vertex = null;
- String taskName = "";
- List<ArtifactDataDefinition> artifacts = null;
- ArtifactsVertexResult result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.validateArtifactsAreInCassandra(vertex, taskName, artifacts);
- }
-
- @Test(expected=NullPointerException.class)
- public void testIsArtifcatInCassandra() throws Exception {
- ArtifactValidationUtils testSubject;
- String uniueId = "";
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isArtifcatInCassandra(uniueId);
- }
-
- @Test
- public void testAddRelevantArtifacts() throws Exception {
- ArtifactValidationUtils testSubject;
- Map<String, ArtifactDataDefinition> artifactsMap = null;
- List<ArtifactDataDefinition> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.addRelevantArtifacts(artifactsMap);
- }
-
- @Test(expected=NullPointerException.class)
- public void testValidateTopologyTemplateArtifacts() throws Exception {
- ArtifactValidationUtils testSubject;
- GraphVertex vertex = null;
- String taskName = "";
- ArtifactsVertexResult result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.validateTopologyTemplateArtifacts(vertex, taskName);
- }
+ // then
+ assertFalse(result.getStatus());
+ }
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java
index 7f67334da6..1da3d6d551 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java
@@ -20,11 +20,16 @@
package org.openecomp.sdc.asdctool.impl.validator.utils;
+import java.util.Set;
+
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
-import java.util.Set;
-
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ReportManager.class})
public class ReportManagerTest {
@Test