summaryrefslogtreecommitdiffstats
path: root/asdctool/src/test/java
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-07-29 16:13:45 +0300
committerMichael Lando <ml636r@att.com>2018-07-29 16:20:34 +0300
commit5b593496b8f1b8e8be8d7d2dbcc223332e65a49b (patch)
tree2f9dfc45191e723da69cf74be7829784e9741b94 /asdctool/src/test/java
parent9200382f2ce7b4bb729aa287d0878004b2d2b4f9 (diff)
re base code
Change-Id: I12a5ca14a6d8a87e9316b9ff362eb131105f98a5 Issue-ID: SDC-1566 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'asdctool/src/test/java')
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/AppTest.java56
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java10
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/mocks/es/ESCatalogDAOMockTest.java5
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java89
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java6
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/DataMigrationTest.java295
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphJsonValidatorTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java7
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/UpdatePropertyOnVertexTest.java7
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/VrfObjectFixHandlerTest.java60
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java15
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java10
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java6
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/VfModuleArtifactPayloadExTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImportTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineMockTest.java23
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/DBVersionTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationToolTest.java12
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java6
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDaoTest.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolverTest.java16
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/scanner/ClassScanner.java14
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java12
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/task/MigrationTasksTest.java22
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandlerTest.java93
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java525
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java69
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServletTest.java8
33 files changed, 1013 insertions, 393 deletions
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/AppTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/AppTest.java
new file mode 100644
index 0000000000..36f5e076b0
--- /dev/null
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/AppTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.asdctool;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest extends TestCase {
+ /**
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+ public AppTest(String testName) {
+ super(testName);
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite() {
+ return new TestSuite(AppTest.class);
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp() {
+ assertTrue(true);
+ }
+}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java
index ac93b92fd1..020696c42d 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/UtilsTest.java
@@ -1,16 +1,14 @@
package org.openecomp.sdc.asdctool;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.core.Response;
-
+import com.thinkaurelius.titan.core.TitanGraph;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.junit.Assert;
import org.junit.Test;
-import com.thinkaurelius.titan.core.TitanGraph;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Map;
public class UtilsTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/mocks/es/ESCatalogDAOMockTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/mocks/es/ESCatalogDAOMockTest.java
index 86ee638c72..f069f6cf97 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/mocks/es/ESCatalogDAOMockTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/configuration/mocks/es/ESCatalogDAOMockTest.java
@@ -1,12 +1,11 @@
package org.openecomp.sdc.asdctool.configuration.mocks.es;
-import java.util.List;
-
+import fj.data.Either;
import org.junit.Test;
import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import fj.data.Either;
+import java.util.List;
public class ESCatalogDAOMockTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java
index 2d1c6a8e57..5638c4581d 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/enums/SchemaZipFileEnumTest.java
@@ -1,8 +1,5 @@
package org.openecomp.sdc.asdctool.enums;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -23,44 +20,6 @@ public class SchemaZipFileEnumTest {
result = null;
}
- @Test
- public void setGetFileName_shouldSetCustomFileName() {
- String fileName = "customFileName";
- testSubject.setFileName(fileName);
- assertEquals(fileName, testSubject.getFileName());
- }
-
- @Test
- public void setGetSourceFolderName_shouldSetCustomSourceFolderName() {
- String sourceFolderName = "customSourceFolderName";
- testSubject.setSourceFolderName(sourceFolderName);
- assertEquals(sourceFolderName, testSubject.getSourceFolderName());
- }
-
- @Test
- public void setGetSourceFileName_shouldSetCustomSourceFileName() {
- String sourceFileName = "customSourceFileName";
- testSubject.setSourceFileName(sourceFileName);
- assertEquals(sourceFileName, testSubject.getSourceFileName());
- }
-
- @Test
- public void setGetCollectionTitle_shouldSetCustomCollectionTitle() {
- String collectionTitle = "customCollectionTitle";
- testSubject.setCollectionTitle(collectionTitle);
- assertEquals(collectionTitle, testSubject.getCollectionTitle());
- }
-
- @Test
- public void setGetImportFileList_shouldSetGetFile1File2() {
- String[] importFileList = new String[] { "File1", "File2" };
- String[] receivedImportFileList;
- testSubject.setImportFileList(importFileList);
- receivedImportFileList = testSubject.getImportFileList();
- assertNotNull(receivedImportFileList);
- assertEquals("File1", receivedImportFileList[0]);
- assertEquals("File2", receivedImportFileList[1]);
- }
private SchemaZipFileEnum createTestSubject() {
return SchemaZipFileEnum.DATA;
@@ -77,16 +36,6 @@ public class SchemaZipFileEnumTest {
}
@Test
- public void testSetFileName() throws Exception {
- SchemaZipFileEnum testSubject;
- String fileName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setFileName(fileName);
- }
-
- @Test
public void testGetSourceFolderName() throws Exception {
SchemaZipFileEnum testSubject;
String result;
@@ -96,15 +45,6 @@ public class SchemaZipFileEnumTest {
result = testSubject.getSourceFolderName();
}
- @Test
- public void testSetSourceFolderName() throws Exception {
- SchemaZipFileEnum testSubject;
- String sourceFolderName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setSourceFolderName(sourceFolderName);
- }
@Test
public void testGetSourceFileName() throws Exception {
@@ -117,16 +57,6 @@ public class SchemaZipFileEnumTest {
}
@Test
- public void testSetSourceFileName() throws Exception {
- SchemaZipFileEnum testSubject;
- String sourceFileName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setSourceFileName(sourceFileName);
- }
-
- @Test
public void testGetCollectionTitle() throws Exception {
SchemaZipFileEnum testSubject;
String result;
@@ -137,16 +67,6 @@ public class SchemaZipFileEnumTest {
}
@Test
- public void testSetCollectionTitle() throws Exception {
- SchemaZipFileEnum testSubject;
- String collectionTitle = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setCollectionTitle(collectionTitle);
- }
-
- @Test
public void testGetImportFileList() throws Exception {
SchemaZipFileEnum testSubject;
String[] result;
@@ -156,13 +76,4 @@ public class SchemaZipFileEnumTest {
result = testSubject.getImportFileList();
}
- @Test
- public void testSetImportFileList() throws Exception {
- SchemaZipFileEnum testSubject;
- String[] importFileList = new String[] { "" };
-
- // default test
- testSubject = createTestSubject();
- testSubject.setImportFileList(importFileList);
- }
} \ No newline at end of file
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java
index d8fec34e30..3fce1b6d66 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java
@@ -1,14 +1,14 @@
package org.openecomp.sdc.asdctool.impl;
-import java.util.List;
-import java.util.Map;
-
import org.junit.Assert;
import org.junit.Test;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.model.Component;
+import java.util.List;
+import java.util.Map;
+
public class ArtifactUuidFixTest {
private ArtifactUuidFix createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/DataMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/DataMigrationTest.java
index af93fc2414..c8d7c9953a 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/DataMigrationTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/DataMigrationTest.java
@@ -1,61 +1,250 @@
package org.openecomp.sdc.asdctool.impl;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.cassandra.schema.Table;
+import org.openecomp.sdc.be.resources.data.auditing.*;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
+
+import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.EnumMap;
-import java.util.TimeZone;
+import java.util.Date;
+import java.util.HashMap;
-import org.elasticsearch.common.settings.SettingsException;
-import org.junit.Test;
-import org.openecomp.sdc.asdctool.impl.DataMigration.TypeToTableMapping;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.openecomp.sdc.common.datastructure.AuditingFieldsKey.*;
+@RunWith(MockitoJUnitRunner.class)
public class DataMigrationTest {
+ private final static String DESCRIPTION = "OK";
+ private final static String STATUS = "200";
+ private final static String SERVICE_INSTANCE_ID = "SERVICE_INSTANCE_ID";
+ private final static String MODIFIER = "MODIFIER";
+ private final static String REQUEST_ID = "REQUEST_ID";
+ private final static String USER = "USER";
+ private final static String USER_BEFORE = "USER_BEFORE";
+ private final static String USER_AFTER = "USER_AFTER";
+ private final static String ARTIFACT_UUID = "ARTIFACT_UUID";
+
+ private final static String PREV_STATE = "PREV_STATE";
+ private final static String CURR_STATE = "CURR_STATE";
+ private final static String PREV_VERSION = "PREV_VERSION";
+ private final static String CURR_VERSION = "CURR_VERSION";
+ private final static String DPREV_STATUS = "DPREV_STATUS";
+ private final static String DCURR_STATUS = "CURR_STATUS";
+ private final static String INVARIANT_UUID = "INVARIANT_UUID";
+ private final static String ARTIFACT_DATA = "ARTIFACT_DATA";
+ private final static String COMMENT = "COMMENT";
+ private final static String DISTRIBUTION_ID = "DISTRIBUTION_ID";
+ private final static String TOSCA_NODE_TYPE = "TOSCA_NODE_TYPE";
+ private final static String CONSUMER_ID = "CONSUMER_ID";
+ private final static String RESOURCE_URL = "RESOURCE_URL";
+ private final static String ENV_ID = "ENV_ID";
+ private final static String VNF_WORKLOAD_CONTEXT = "VNF_WORKLOAD_CONTEXT";
+ private final static String TENANT = "TENANT";
+ private final static String RESOURCE_NAME = "RESOURCE_NAME";
+ private final static String RESOURCE_TYPE = "RESOURCE_TYPE";
+ private final static String AUTH_URL = "AUTH_URL";
+ private final static String AUTH_RELM = "AUTH_RELM";
+ private final static String TOPIC_NAME = "TOPIC_NAME";
+
+ private final static String dateFormatPattern = "yyyy-MM-dd HH:mm:ss.SSS z";
+
+ private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
+
+ private static DataMigration dataMigration = new DataMigration();
+
+ private final static String ES_STRING = "{\"" + AuditingFieldsKey.AUDIT_ACTION + "\":\"%s\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_NAME + "\":\"" + RESOURCE_NAME + "\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_TOSCA_NODE_TYPE + "\":\"" + TOSCA_NODE_TYPE +
+ "\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_PREV_VERSION + "\":\"" + PREV_VERSION + "\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_PREV_STATE + "\":\"" + PREV_STATE +
+ "\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_TYPE + "\":\"" + RESOURCE_TYPE + "\", \"" + AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID + "\":\"" + SERVICE_INSTANCE_ID +
+ "\", \"" + AuditingFieldsKey.AUDIT_INVARIANT_UUID + "\":\"" + INVARIANT_UUID + "\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_CURR_VERSION + "\":\"" + CURR_VERSION +
+ "\", \"" + AuditingFieldsKey.AUDIT_RESOURCE_CURR_STATE + "\":\"" + CURR_STATE + "\", \"" + AuditingFieldsKey.AUDIT_MODIFIER_UID + "\":\"" + MODIFIER +
+ "\", \"" + AuditingFieldsKey.AUDIT_DESC + "\":\"" + DESCRIPTION + "\", \"" + AuditingFieldsKey.AUDIT_STATUS + "\":\"" + STATUS +
+ "\", \"" + AuditingFieldsKey.AUDIT_REQUEST_ID + "\":\"" + REQUEST_ID + "\", \"" + AuditingFieldsKey.AUDIT_CURR_ARTIFACT_UUID + "\":\"" + ARTIFACT_UUID +
+ "\", \"" + AuditingFieldsKey.AUDIT_PREV_ARTIFACT_UUID + "\":\"" + ARTIFACT_UUID + "\", \"" + AuditingFieldsKey.AUDIT_ARTIFACT_DATA + "\":\"" + ARTIFACT_DATA +
+ "\", \"" + AuditingFieldsKey.AUDIT_TIMESTAMP + "\":\"%s\"}";
+
+
+ private String timestampStr;
+
+ private HashMap<AuditingFieldsKey, String> dataMap = new HashMap<>();
+
+ @Before
+ public void setUp() {
+ dataMap.put(AUDIT_DESC, DESCRIPTION);
+ dataMap.put(AUDIT_STATUS, STATUS);
+ dataMap.put(AUDIT_REQUEST_ID, REQUEST_ID);
+ dataMap.put(AUDIT_SERVICE_INSTANCE_ID, SERVICE_INSTANCE_ID);
+ dataMap.put(AUDIT_MODIFIER_UID, MODIFIER);
+ dataMap.put(AUDIT_USER_BEFORE, USER_BEFORE);
+ dataMap.put(AUDIT_USER_UID, USER);
+ dataMap.put(AUDIT_USER_AFTER, USER_AFTER);
+ dataMap.put(AUDIT_AUTH_URL, AUTH_URL);
+ dataMap.put(AUDIT_AUTH_REALM, AUTH_RELM);
+ dataMap.put(AUDIT_PREV_ARTIFACT_UUID, ARTIFACT_UUID);
+ dataMap.put(AUDIT_CURR_ARTIFACT_UUID, ARTIFACT_UUID);
+ dataMap.put(AUDIT_RESOURCE_PREV_STATE, PREV_STATE);
+ dataMap.put(AUDIT_RESOURCE_PREV_VERSION, PREV_VERSION);
+ dataMap.put(AUDIT_RESOURCE_CURR_STATE, CURR_STATE);
+ dataMap.put(AUDIT_RESOURCE_CURR_VERSION, CURR_VERSION);
+ dataMap.put(AUDIT_RESOURCE_DPREV_STATUS, DPREV_STATUS);
+ dataMap.put(AUDIT_RESOURCE_DCURR_STATUS, DCURR_STATUS);
+ dataMap.put(AUDIT_INVARIANT_UUID, INVARIANT_UUID);
+ dataMap.put(AUDIT_ARTIFACT_DATA, ARTIFACT_DATA);
+ dataMap.put(AUDIT_RESOURCE_COMMENT, COMMENT);
+ dataMap.put(AUDIT_DISTRIBUTION_ID, DISTRIBUTION_ID);
+ dataMap.put(AUDIT_RESOURCE_TOSCA_NODE_TYPE, TOSCA_NODE_TYPE);
+ dataMap.put(AUDIT_DISTRIBUTION_CONSUMER_ID, CONSUMER_ID);
+ dataMap.put(AUDIT_RESOURCE_URL, RESOURCE_URL);
+ dataMap.put(AUDIT_DISTRIBUTION_ENVIRONMENT_ID, ENV_ID);
+ dataMap.put(AUDIT_DISTRIBUTION_VNF_WORKLOAD_CONTEXT, VNF_WORKLOAD_CONTEXT);
+ dataMap.put(AUDIT_DISTRIBUTION_TENANT, TENANT);
+ dataMap.put(AUDIT_RESOURCE_NAME, RESOURCE_NAME);
+ dataMap.put(AUDIT_RESOURCE_TYPE, RESOURCE_TYPE);
+ timestampStr = simpleDateFormat.format(new Date());
+ dataMap.put(AUDIT_TIMESTAMP, timestampStr);
+ dataMap.put(AUDIT_DISTRIBUTION_TOPIC_NAME, TOPIC_NAME);
+
+ }
+
+ @Test
+ public void createUserAdminEvent() {
+ dataMap.put(AUDIT_ACTION, AuditingActionEnum.ADD_USER.getName());
+ AuditingGenericEvent event = dataMigration.createAuditEvent(dataMap, Table.USER_ADMIN_EVENT);
+ assertThat(AuditingActionEnum.ADD_USER.getName()).isEqualTo(event.getAction());
+ verifyCommonData(event, true);
+ verifyUserAdminEvent((UserAdminEvent) event);
+ }
+
+ @Test
+ public void createResourceAdminEvent() {
+ dataMap.put(AUDIT_ACTION, AuditingActionEnum.UPDATE_RESOURCE_METADATA.getName());
+ AuditingGenericEvent event = dataMigration.createAuditEvent(dataMap, Table.RESOURCE_ADMIN_EVENT);
+ assertThat(AuditingActionEnum.UPDATE_RESOURCE_METADATA.getName()).isEqualTo(event.getAction());
+ verifyCommonData(event, true);
+ verifyResourceAdminEvent((ResourceAdminEvent)event);
+ }
+
+ @Test
+ public void createDistributionNotificationEvent() {
+ dataMap.put(AUDIT_ACTION, AuditingActionEnum.DISTRIBUTION_NOTIFY.getName());
+ AuditingGenericEvent event = dataMigration.createAuditEvent(dataMap, Table.DISTRIBUTION_NOTIFICATION_EVENT);
+ assertThat(AuditingActionEnum.DISTRIBUTION_NOTIFY.getName()).isEqualTo(event.getAction());
+ verifyCommonData(event, true);
+ verifyDistributionNotificationEvent((DistributionNotificationEvent)event);
+ }
+
+
+ @Test
+ public void createEventForNoneAuditTable() {
+ assertThat(dataMigration.createAuditEvent(dataMap, Table.COMPONENT_CACHE)).isNull();
+
+ }
+
+ @Test
+ public void createEventWhenSomeFieldValuesNotSet() {
+ dataMap.clear();
+ dataMap.put(AUDIT_ACTION, AuditingActionEnum.AUTH_REQUEST.getName());
+ AuditingGenericEvent event = dataMigration.createAuditEvent(dataMap, Table.AUTH_EVENT);
+ assertThat(AuditingActionEnum.AUTH_REQUEST.getName()).isEqualTo(event.getAction());
+ assertThat(event.getStatus()).isNull();
+ assertThat(event.getDesc()).isNull();
+ assertThat(event.getRequestId()).isNull();
+ }
+
+ @Test
+ public void createAuthEvent() {
+ dataMap.put(AUDIT_ACTION, AuditingActionEnum.AUTH_REQUEST.getName());
+ AuditingGenericEvent event = dataMigration.createAuditEvent(dataMap, Table.AUTH_EVENT);
+ assertThat(AuditingActionEnum.AUTH_REQUEST.getName()).isEqualTo(event.getAction());
+ verifyCommonData(event, false);
+ verifyAuthEvent((AuthEvent) event);
+ }
+
+ @Test
+ public void createImportResourceEventFromEsObject() throws IOException{
+ AuditingGenericEvent event = dataMigration.createAuditRecordForCassandra(String.format(ES_STRING, AuditingActionEnum.IMPORT_RESOURCE.getName(), timestampStr), Table.RESOURCE_ADMIN_EVENT);
+ assertThat(AuditingActionEnum.IMPORT_RESOURCE.getName()).isEqualTo(event.getAction());
+ verifyCommonData(event, true);
+ verifyResourceAdminEvent((ResourceAdminEvent)event);
+ }
+
+ @Test
+ public void createGetUserListEventFromEsObject() throws IOException{
+ AuditingGenericEvent event = dataMigration.createAuditRecordForCassandra(String.format(ES_STRING, AuditingActionEnum.GET_USERS_LIST.getName(), timestampStr),
+ Table.GET_USERS_LIST_EVENT);
+ assertThat(AuditingActionEnum.GET_USERS_LIST.getName()).isEqualTo(event.getAction());
+ verifyCommonData(event, false);
+ assertThat(((GetUsersListEvent)event).getModifier()).isEqualTo(MODIFIER);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void createEventFromEsFailedWhenActionDoesNotExist() throws IOException {
+ dataMigration.createAuditRecordForCassandra(String.format(ES_STRING, "WRONG", timestampStr),
+ Table.CONSUMER_EVENT);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void createRecordWhenJsonIsEmpty() throws IOException{
+ dataMigration.createAuditRecordForCassandra("{}",
+ Table.CONSUMER_EVENT);
+ }
+
+ private void verifyCommonData(AuditingGenericEvent event, boolean isServiceInstanceProvided) {
+ assertThat(STATUS).isEqualTo(event.getStatus());
+ if (isServiceInstanceProvided) {
+ assertThat(SERVICE_INSTANCE_ID).isEqualTo(event.getServiceInstanceId());
+ }
+ else {
+ assertThat(event.getServiceInstanceId()).isNull();
+ }
+ assertThat(DESCRIPTION).isEqualTo(event.getDesc());
+ assertThat(REQUEST_ID).isEqualTo(event.getRequestId());
+ }
+
+ private void verifyUserAdminEvent(UserAdminEvent event) {
+ assertThat(USER_AFTER).isEqualTo(event.getUserAfter());
+ assertThat(USER_BEFORE).isEqualTo(event.getUserBefore());
+ verifyTimestamp(event.getTimestamp1());
+ }
+
+ private void verifyAuthEvent(AuthEvent event) {
+ assertThat(USER).isEqualTo(event.getUser());
+ assertThat(AUTH_URL).isEqualTo(event.getUrl());
+ assertThat(event.getAuthStatus()).isNull();
+ assertThat(AUTH_RELM).isEqualTo(event.getRealm());
+ }
+
+ private void verifyTimestamp(Date date) {
+ assertThat(timestampStr).isEqualTo(simpleDateFormat.format(date));
+ }
+
+ private void verifyResourceAdminEvent(ResourceAdminEvent event) {
+ assertThat(CURR_STATE).isEqualTo(event.getCurrState());
+ assertThat(CURR_VERSION).isEqualTo(event.getCurrVersion());
+ assertThat(ARTIFACT_UUID).isEqualTo(event.getCurrArtifactUUID());
+ assertThat(PREV_STATE).isEqualTo(event.getPrevState());
+ assertThat(PREV_VERSION).isEqualTo(event.getPrevVersion());
+ assertThat(ARTIFACT_UUID).isEqualTo(event.getPrevArtifactUUID());
+ assertThat(INVARIANT_UUID).isEqualTo(event.getInvariantUUID());
+ assertThat(ARTIFACT_DATA).isEqualTo(event.getArtifactData());
+ assertThat(RESOURCE_NAME).isEqualTo(event.getResourceName());
+ assertThat(RESOURCE_TYPE).isEqualTo(event.getResourceType());
+ verifyTimestamp(event.getTimestamp1());
+ assertThat(TOSCA_NODE_TYPE).isEqualTo( event.getToscaNodeType());
+ }
+
+ private void verifyDistributionNotificationEvent(DistributionNotificationEvent event) {
+ assertThat(CURR_STATE).isEqualTo(event.getCurrState());
+ assertThat(CURR_VERSION).isEqualTo(event.getCurrVersion());
+ assertThat(TOPIC_NAME).isEqualTo(event.getTopicName());
+ assertThat(DISTRIBUTION_ID).isEqualTo(event.getDid());
+ assertThat(ENV_ID).isEqualTo(event.getEnvId());
+ assertThat(VNF_WORKLOAD_CONTEXT).isEqualTo(event.getVnfWorkloadContext());
+ assertThat(TENANT).isEqualTo(event.getTenant());
+ verifyTimestamp(event.getTimestamp1());
+ }
- private DataMigration createTestSubject() {
- return new DataMigration();
- }
-
- /*@Test(expected=IllegalArgumentException.class)
- public void testMigrateDataEsToCassandra() throws Exception {
- DataMigration testSubject;
- String appConfigDir = "src/main/resources/config/";
- boolean exportFromEs = false;
- boolean importToCassandra = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.migrateDataEsToCassandra(appConfigDir, exportFromEs, importToCassandra);
- }*/
-
- @Test(expected=NullPointerException.class)
- public void testCreateAuditRecord() throws Exception {
- DataMigration testSubject;
-
- EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>(AuditingFieldsKeysEnum.class);
- auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ACTION, AuditingActionEnum.GET_CATEGORY_HIERARCHY.getName());
-
- String DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS z";
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN);
- simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- auditingFields.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, "2018-05-02 06:06:18.294 UTC");
-
- // default test
- testSubject = createTestSubject();
- testSubject.createAuditRecord(auditingFields);
- }
-
- @Test
- public void testTypeToTableMapping() throws Exception {
- TypeToTableMapping[] values = TypeToTableMapping.values();
-
- for (TypeToTableMapping typeToTableMapping : values) {
- TypeToTableMapping.getTableByType(typeToTableMapping.getTypeName());
- typeToTableMapping.getTable();
-
- }
-
- TypeToTableMapping.getTableByType("stam");
- }
} \ No newline at end of file
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphJsonValidatorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphJsonValidatorTest.java
index 51dfca33a2..ab6c49cdc9 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphJsonValidatorTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphJsonValidatorTest.java
@@ -1,9 +1,9 @@
package org.openecomp.sdc.asdctool.impl;
-import java.nio.file.NoSuchFileException;
-
import org.junit.Test;
+import java.nio.file.NoSuchFileException;
+
public class GraphJsonValidatorTest {
private GraphJsonValidator createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java
index 3f5d3e144d..fb003e8012 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/GraphMLConverterTest.java
@@ -1,13 +1,12 @@
package org.openecomp.sdc.asdctool.impl;
-import java.util.List;
-import java.util.Map;
-
+import com.thinkaurelius.titan.core.TitanGraph;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.junit.Test;
-import com.thinkaurelius.titan.core.TitanGraph;
+import java.util.List;
+import java.util.Map;
public class GraphMLConverterTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/UpdatePropertyOnVertexTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/UpdatePropertyOnVertexTest.java
index 503f52a5af..4db5c06262 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/UpdatePropertyOnVertexTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/UpdatePropertyOnVertexTest.java
@@ -1,11 +1,10 @@
package org.openecomp.sdc.asdctool.impl;
-import java.util.List;
-import java.util.Map;
-
+import com.thinkaurelius.titan.core.TitanGraph;
import org.junit.Test;
-import com.thinkaurelius.titan.core.TitanGraph;
+import java.util.List;
+import java.util.Map;
public class UpdatePropertyOnVertexTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/VrfObjectFixHandlerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/VrfObjectFixHandlerTest.java
new file mode 100644
index 0000000000..c0ae55a607
--- /dev/null
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/VrfObjectFixHandlerTest.java
@@ -0,0 +1,60 @@
+package org.openecomp.sdc.asdctool.impl;
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class VrfObjectFixHandlerTest {
+
+ private TitanDao titanDao;
+
+ private VrfObjectFixHandler vrfObjectFixHandler;
+
+ @Before
+ public void init(){
+ titanDao = Mockito.mock(TitanDao.class);
+ vrfObjectFixHandler = new VrfObjectFixHandler(titanDao);
+ }
+
+ @Test
+ public void handleInvalidModeTest(){
+ assertThat(vrfObjectFixHandler.handle("invalid mode", null)).isFalse();
+ }
+
+ @Test
+ public void handleDetectNotFoundTest(){
+ when(titanDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ assertThat(vrfObjectFixHandler.handle("detect", null)).isTrue();
+ }
+
+ @Test
+ public void handleDetectTitanNotConnectedTest(){
+ when(titanDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(TitanOperationStatus.NOT_CONNECTED));
+ assertThat(vrfObjectFixHandler.handle("detect", null)).isFalse();
+ }
+
+ @Test
+ public void handleFixNotFoundTest(){
+ when(titanDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ assertThat(vrfObjectFixHandler.handle("fix", null)).isTrue();
+ }
+
+ @Test
+ public void handleFixNotCreatedTest(){
+ when(titanDao.getByCriteria(eq(VertexTypeEnum.NODE_TYPE), anyMap())).thenReturn(Either.right(TitanOperationStatus.NOT_CREATED));
+ assertThat(vrfObjectFixHandler.handle("fix", null)).isFalse();
+ }
+
+}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
index 32aec782c1..4f8d96491c 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.impl.validator;
-import java.util.LinkedList;
-
import org.junit.Test;
import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter;
+import java.util.LinkedList;
+
public class ArtifactToolBLTest {
private ArtifactToolBL createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
index bb74c70423..69b77415a3 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.impl.validator;
-import java.util.LinkedList;
-
import org.junit.Test;
import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter;
+import java.util.LinkedList;
+
public class ValidationToolBLTest {
private ValidationToolBL createTestSubject() {
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 f639c8a7de..ffdf306520 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
@@ -1,9 +1,9 @@
package org.openecomp.sdc.asdctool.impl.validator.config;
-import java.util.Properties;
-
import org.junit.Test;
+import java.util.Properties;
+
public class ValidationConfigManagerTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java
index da1ef90a40..ece89dbd21 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java
@@ -3,11 +3,7 @@ package org.openecomp.sdc.asdctool.impl.validator.config;
import org.junit.Test;
import org.openecomp.sdc.asdctool.impl.validator.ArtifactToolBL;
import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL;
-import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter;
-import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceToscaArtifactsValidatorExecutor;
-import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter;
-import org.openecomp.sdc.asdctool.impl.validator.executers.VFToscaArtifactValidatorExecutor;
-import org.openecomp.sdc.asdctool.impl.validator.executers.VfValidatorExecuter;
+import org.openecomp.sdc.asdctool.impl.validator.executers.*;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValidationTask;
@@ -18,14 +14,7 @@ import org.openecomp.sdc.be.dao.cassandra.CassandraClient;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
import org.openecomp.sdc.be.model.DerivedNodeTypeResolver;
-import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations;
-import org.openecomp.sdc.be.model.jsontitan.operations.CategoryOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.GroupsOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaDataOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsontitan.operations.*;
public class ValidationToolConfigurationTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java
index e14530212a..06f557dbc3 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java
@@ -1,16 +1,16 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
import org.junit.Test;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.Resource;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
public class ArtifactValidatorExecuterTest {
private ArtifactValidatorExecuter createTestSubject() {
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 27deb6bce8..50ee75abd9 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
@@ -1,12 +1,12 @@
package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts;
-import java.util.List;
-import java.util.Map;
-
import org.junit.Test;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
+import java.util.List;
+import java.util.Map;
+
public class ArtifactValidationUtilsTest {
private ArtifactValidationUtils createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java
index 163994e423..15cfc36fa6 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java
@@ -1,9 +1,9 @@
package org.openecomp.sdc.asdctool.impl.validator.utils;
-import java.util.List;
-
import org.junit.Test;
+import java.util.List;
+
public class ElementTypeEnumTest {
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 a50af44a8c..1ad0906949 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
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.impl.validator.utils;
-import java.util.Set;
-
import org.junit.Test;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import java.util.Set;
+
public class ReportManagerTest {
@Test
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/VfModuleArtifactPayloadExTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/VfModuleArtifactPayloadExTest.java
index 50c01b074c..2e72c9e74d 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/VfModuleArtifactPayloadExTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/VfModuleArtifactPayloadExTest.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.impl.validator.utils;
+import org.junit.Test;
+
import java.util.List;
import java.util.Map;
-import org.junit.Test;
-
public class VfModuleArtifactPayloadExTest {
private VfModuleArtifactPayloadEx createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImportTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImportTest.java
index 791aeb922d..c3851a5b83 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImportTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/main/SdcSchemaFileImportTest.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.main;
-import java.nio.file.NoSuchFileException;
-
import org.junit.Test;
import org.openecomp.sdc.asdctool.enums.SchemaZipFileEnum;
+import java.nio.file.NoSuchFileException;
+
public class SdcSchemaFileImportTest {
private SdcSchemaFileImport createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineMockTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineMockTest.java
index feea79fdd1..0d2c4711c6 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineMockTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineMockTest.java
@@ -1,12 +1,15 @@
package org.openecomp.sdc.asdctool.migration.config.mocks;
+import org.junit.Ignore;
import org.junit.Test;
import org.openecomp.sdc.be.components.distribution.engine.INotificationData;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
+@Ignore ("This class does not test anything, there is not a single assertion and the code with reflection fails")
public class DistributionEngineMockTest {
private DistributionEngineMock createTestSubject() {
@@ -31,8 +34,8 @@ public class DistributionEngineMockTest {
INotificationData notificationData = null;
String envName = "";
String userId = "";
- String modifierName = "";
ActionStatus result;
+ User modifierName=new User();
// default test
testSubject = createTestSubject();
@@ -48,12 +51,12 @@ public class DistributionEngineMockTest {
String envId = "";
String envName = "";
String userId = "";
- String modifierName = "";
+ User modifierName = new User();
ActionStatus result;
// default test
testSubject = createTestSubject();
- result = testSubject.notifyService(distributionId, service, notificationData, envId, envName, userId,
+ result = testSubject.notifyService(distributionId, service, notificationData, envId, envName,
modifierName);
}
@@ -88,6 +91,7 @@ public class DistributionEngineMockTest {
testSubject.disableEnvironment(envName);
}
+ @Ignore
@Test
public void testIsReadyForDistribution() throws Exception {
DistributionEngineMock testSubject;
@@ -97,7 +101,7 @@ public class DistributionEngineMockTest {
// default test
testSubject = createTestSubject();
- result = testSubject.isReadyForDistribution(service, envName);
+ result = testSubject.isReadyForDistribution(envName);
}
@Test
@@ -114,17 +118,6 @@ public class DistributionEngineMockTest {
}
@Test
- public void testVerifyServiceHasDeploymentArtifacts() throws Exception {
- DistributionEngineMock testSubject;
- Service service = null;
- StorageOperationStatus result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.verifyServiceHasDeploymentArtifacts(service);
- }
-
- @Test
public void testGetEnvironmentById() throws Exception {
DistributionEngineMock testSubject;
String opEnvId = "";
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/DBVersionTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/DBVersionTest.java
index d5473cd121..830edd7fb2 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/DBVersionTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/DBVersionTest.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.migration.core;
-import static org.testng.Assert.assertEquals;
-
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+
public class DBVersionTest {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationToolTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationToolTest.java
index da6122c5f0..3af664569f 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationToolTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/SdcMigrationToolTest.java
@@ -1,12 +1,5 @@
package org.openecomp.sdc.asdctool.migration.core;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.Collections;
-
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -19,6 +12,11 @@ import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.mockito.Mockito.*;
+
public class SdcMigrationToolTest {
@InjectMocks
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java
index 3f9766d9c5..86ce9b2ccc 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/execution/MigrationExecutorImplTest.java
@@ -1,13 +1,13 @@
package org.openecomp.sdc.asdctool.migration.core.execution;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
import org.openecomp.sdc.asdctool.migration.DummyMigrationFactory;
import org.openecomp.sdc.asdctool.migration.core.task.Migration;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
import org.testng.annotations.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
public class MigrationExecutorImplTest {
@Test
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDaoTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDaoTest.java
index 73f50f4ec6..a21356637a 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDaoTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/dao/MigrationTasksDaoTest.java
@@ -1,10 +1,10 @@
package org.openecomp.sdc.asdctool.migration.dao;
-import java.math.BigInteger;
-
import org.junit.Test;
import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
+import java.math.BigInteger;
+
public class MigrationTasksDaoTest {
private MigrationTasksDao createTestSubject() {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolverTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolverTest.java
index 47bf9c9c74..b6267d3950 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolverTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/resolver/SpringBeansMigrationResolverTest.java
@@ -1,13 +1,5 @@
package org.openecomp.sdc.asdctool.migration.resolver;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -20,6 +12,14 @@ import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
public class SpringBeansMigrationResolverTest {
@InjectMocks
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/scanner/ClassScanner.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/scanner/ClassScanner.java
index c50cae0673..38cf068cbb 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/scanner/ClassScanner.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/scanner/ClassScanner.java
@@ -1,16 +1,12 @@
package org.openecomp.sdc.asdctool.migration.scanner;
+import org.apache.commons.io.FileUtils;
+import org.openecomp.sdc.asdctool.migration.core.MigrationException;
+
import java.io.File;
import java.lang.reflect.Modifier;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import org.apache.commons.io.FileUtils;
-import org.openecomp.sdc.asdctool.migration.core.MigrationException;
+import java.util.*;
/**
* scan and instantiate classes of given type in the class path
@@ -76,6 +72,4 @@ public class ClassScanner {
String classes = "classes.";
return asPackage.substring(asPackage.indexOf(classes) + classes.length());
}
-
-
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java
index 2745f59006..dbaf443935 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/service/SdcRepoServiceTest.java
@@ -1,11 +1,5 @@
package org.openecomp.sdc.asdctool.migration.service;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
-
-import java.math.BigInteger;
-
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -16,6 +10,12 @@ import org.openecomp.sdc.be.resources.data.MigrationTaskEntry;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.math.BigInteger;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+
public class SdcRepoServiceTest {
@InjectMocks
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/task/MigrationTasksTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/task/MigrationTasksTest.java
index 52dc7c9fcd..8d48a5e9ad 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/task/MigrationTasksTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/task/MigrationTasksTest.java
@@ -1,11 +1,5 @@
package org.openecomp.sdc.asdctool.migration.task;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.asdctool.migration.core.DBVersion;
import org.openecomp.sdc.asdctool.migration.core.task.Migration;
@@ -14,6 +8,12 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
public class MigrationTasksTest {
@@ -21,13 +21,13 @@ public class MigrationTasksTest {
private List<Migration> migrations;
@BeforeMethod
- public void setUp() {
+ public void setUp() throws Exception {
ClassScanner classScanner = new ClassScanner();
migrations = classScanner.getAllClassesOfType(MIGRATIONS_BASE_PACKAGE, Migration.class);
}
@Test
- public void testNoTasksWithSameVersion() {
+ public void testNoTasksWithSameVersion() throws Exception {
Map<DBVersion, List<Migration>> migrationsByVersion = migrations.stream().collect(Collectors.groupingBy(Migration::getVersion));
migrationsByVersion.forEach((version, migrations) -> {
if (migrations.size() > 1) {
@@ -38,14 +38,14 @@ public class MigrationTasksTest {
}
@Test
- public void testNoTaskWithVersionGreaterThanCurrentVersion() {
+ public void testNoTaskWithVersionGreaterThanCurrentVersion() throws Exception {
Set<Migration> migrationsWithVersionsGreaterThanCurrent = migrations.stream().filter(mig -> mig.getVersion().compareTo(DBVersion.CURRENT_VERSION) > 0)
.collect(Collectors.toSet());
if (!migrationsWithVersionsGreaterThanCurrent.isEmpty()) {
Assert.fail(String.format("migrations tasks %s have version which is greater than DBVersion.CURRENT_VERSION %s. did you forget to update current version?",
- getMigrationsNameAsString(migrationsWithVersionsGreaterThanCurrent),
- DBVersion.CURRENT_VERSION.toString()));
+ getMigrationsNameAsString(migrationsWithVersionsGreaterThanCurrent),
+ DBVersion.CURRENT_VERSION.toString()));
}
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandlerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandlerTest.java
index 66d9b15e4b..19f6f26ac8 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandlerTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/handlers/XlsOutputHandlerTest.java
@@ -1,40 +1,65 @@
package org.openecomp.sdc.asdctool.migration.tasks.handlers;
+import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.class)
public class XlsOutputHandlerTest {
- private XlsOutputHandler createTestSubject() {
- return new XlsOutputHandler(new Object());
- }
-
- @Test
- public void testInitiate() throws Exception {
- XlsOutputHandler testSubject;
- Object[] title = new Object[] { null };
-
- // default test
- testSubject = createTestSubject();
- testSubject.initiate(title);
- }
-
- @Test
- public void testAddRecord() throws Exception {
- XlsOutputHandler testSubject;
- Object[] record = new Object[] { null };
-
- // default test
- testSubject = createTestSubject();
- testSubject.addRecord(record);
- }
-
- @Test
- public void testWriteOutput() throws Exception {
- XlsOutputHandler testSubject;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.writeOutput();
- }
-} \ No newline at end of file
+ @Spy
+ private XlsOutputHandler handler = new XlsOutputHandler(null, "mock");
+
+ @Mock
+ private Workbook workbook;
+ @Mock
+ private FileOutputStream xlsFile;
+
+ @Test
+ public void verifyThatFileIsNotCreatedIfNoRecordsAdded() throws IOException {
+ assertFalse(handler.writeOutputAndCloseFile());
+ verify(workbook, times(0)).write(any());
+ }
+
+ @Test
+ public void verifyThatFileIsCreatedIfSomeRecordsAdded() throws IOException {
+ handler.addRecord("mock");
+ doReturn(xlsFile).when(handler).getXlsFile();
+ assertTrue(handler.writeOutputAndCloseFile());
+ }
+
+
+ private XlsOutputHandler createTestSubject() {
+ return new XlsOutputHandler("mock", "mockPath", new Object());
+ }
+
+ @Test
+ public void testInitiate() throws Exception {
+ XlsOutputHandler testSubject;
+ Object[] title = new Object[] { null };
+ // default test
+ testSubject = createTestSubject();
+ testSubject.initiate("mock", title);
+ }
+
+ @Test
+ public void testAddRecord() throws Exception {
+ XlsOutputHandler testSubject;
+ Object[] record = new Object[] { null };
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.addRecord(record);
+ }
+}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java
index f2a0a3c716..df5761d893 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java
@@ -1,21 +1,9 @@
package org.openecomp.sdc.asdctool.migration.tasks.mig1710;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
+import com.google.common.collect.Lists;
+import fj.data.Either;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -25,35 +13,56 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
import org.openecomp.sdc.asdctool.migration.tasks.handlers.XlsOutputHandler;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.CsarOperation;
import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.http.client.api.HttpRequestHandler;
import org.openecomp.sdc.exception.ResponseFormat;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
-import fj.data.Either;
@RunWith(MockitoJUnitRunner.class)
public class UpgradeMigration1710Test {
- private final static String USER = "jh0003";
- private final static String CONF_LEVEL = "5.0";
+ private static final String USER = "jh0003";
+ private static final String CONF_LEVEL = "5.0";
+ private static final String COMPONENT_UNIQUE_ID = "12345";
+ private static final String OLD_VERSION = "1.0";
+ private static final String UPDATED_VERSION = "2.0";
+ private static final String CSAR_UUID = "1234578";
+ private static HttpRequestHandler originHandler;
private final User user = new User();
@@ -70,18 +79,40 @@ public class UpgradeMigration1710Test {
@Mock
private ComponentsUtils componentUtils;
@Mock
+ private CsarOperation csarOperation;
+ @Mock
private ConfigurationSource configurationSource;
+ //don't remove - it is intended to avoid the xls file generating
@Mock
private XlsOutputHandler outputHandler;
+ @Mock
+ private ResourceBusinessLogic resourceBusinessLogic;
+ @Mock
+ private ServiceBusinessLogic serviceBusinessLogic;
+ @Mock
+ private ResponseFormat responseFormat;
+ @Mock
+ private ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
private static ConfigurationManager configurationManager;
private static List<String> resources = Stream.of("org.openecomp.resource.cp.extCP").collect(Collectors.toList());
private static Map<String, List<String>> resourcesForUpgrade;
+ private Resource resource;
+ private Service service;
+ private List<String> vfList = new ArrayList<>();
+
@BeforeClass
public static void setUpClass() {
resourcesForUpgrade = new HashMap<>();
resourcesForUpgrade.put(CONF_LEVEL, resources);
+ originHandler = HttpRequestHandler.get();
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ //put the origin handler back
+ HttpRequestHandler.setTestInstance(originHandler);
}
@Before
@@ -92,43 +123,112 @@ public class UpgradeMigration1710Test {
configurationManager.getConfiguration().setSkipUpgradeVSPs(true);
configurationManager.getConfiguration().setSkipUpgradeFailedVfs(true);
configurationManager.getConfiguration().setAutoHealingOwner(USER);
+ configurationManager.getConfiguration().setSupportAllottedResourcesAndProxy(true);
+ configurationManager.getConfiguration().setDeleteLockTimeoutInSeconds(10);
+ configurationManager.getConfiguration().setMaxDeleteComponents(5);
+ configurationManager.getConfiguration().setEnableAutoHealing(true);
+ configurationManager.getConfiguration().setToscaConformanceLevel("5.0");
+ HashMap<String, List<String>> resourcesForUpgrade = new HashMap();
+ resourcesForUpgrade.put("5.0", Lists.newArrayList("port"));
+ configurationManager.getConfiguration().setResourcesForUpgrade(resourcesForUpgrade);
+
+ migration.init();
+ migration.setNodeTypesSupportOnly(false);
+ when(componentsCleanBusinessLogic.lockDeleteOperation()).thenReturn(StorageOperationStatus.OK);
+
+ resource = new Resource();
+ resource.setCsarUUID(CSAR_UUID);
+ resource.setVersion(OLD_VERSION);
+ resource.setUniqueId(COMPONENT_UNIQUE_ID);
+ service = new Service();
+ service.setVersion(OLD_VERSION);
+ service.setUniqueId(COMPONENT_UNIQUE_ID);
+
+ vfList.add(COMPONENT_UNIQUE_ID);
+
+ when(responseFormat.getFormattedMessage())
+ .thenReturn("");
+ when(componentUtils.getResponseFormat(any(ActionStatus.class), any()))
+ .thenReturn(responseFormat);
+ when(componentUtils.convertFromStorageResponse(any(), any())).thenCallRealMethod();
+ mockChangeComponentState();
}
@Test
public void nodeTypesUpgradeFailed() {
+ migration.setNodeTypesSupportOnly(true);
resolveUserAndDefineUpgradeLevel();
when(titanDao.getByCriteria(any(), any(), any(), any()))
- .thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ .thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ assertEquals(MigrationResult.MigrationStatus.FAILED, migration.migrate().getMigrationStatus());
+ }
+
+ @Test
+ public void migrationDisabled() {
+ configurationManager.getConfiguration().setEnableAutoHealing(false);
+ migration.init();
+ assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
+ verify(titanDao, times(0)).commit();
+ verify(titanDao, times(0)).rollback();
+ }
+
+ @Test
+ public void migrationFailedIfDeleteNodeLockFailed() {
+ when(componentsCleanBusinessLogic.lockDeleteOperation())
+ .thenReturn(StorageOperationStatus.BAD_REQUEST);
+ assertEquals(MigrationResult.MigrationStatus.FAILED, migration.migrate().getMigrationStatus());
+ }
+
+ @Test
+ public void migrationFailedIfDeleteNodeLockRetryFailed() {
+ when(componentsCleanBusinessLogic.lockDeleteOperation())
+ .thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT)
+ .thenReturn(StorageOperationStatus.BAD_REQUEST);
assertEquals(MigrationResult.MigrationStatus.FAILED, migration.migrate().getMigrationStatus());
}
@Test
+ public void nodeTypesOnlyUpgradePassed() {
+ migration.setNodeTypesSupportOnly(true);
+ upgradeAllScenario(false);
+ assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
+ verify(titanDao, times(2)).commit();
+ verify(titanDao, times(0)).rollback();
+ }
+
+ @Test
public void nodeTypesUpgradePassedAndVFsUpgradeFailedWhenSkipFailedVFsIsNotSupported() {
final boolean failOnVfUpgrade = true;
final boolean upgradeServices = false;
final boolean exceptionOnVfUpgrade = false;
final boolean upgradeVFC = false;
+ final boolean isFailed = true;
configurationManager.getConfiguration().setSkipUpgradeFailedVfs(false);
+ migration.init();
+ migration.setNodeTypesSupportOnly(false);
resolveUserAndDefineUpgradeLevel();
- upgradeRules(failOnVfUpgrade, exceptionOnVfUpgrade, upgradeServices, upgradeVFC);
+ upgradeRules(failOnVfUpgrade, exceptionOnVfUpgrade, upgradeServices, upgradeVFC, isFailed);
assertEquals(MigrationResult.MigrationStatus.FAILED, migration.migrate().getMigrationStatus());
verify(titanDao, times(1)).commit();
verify(titanDao, times(2)).rollback();
}
+
@Test
public void upgradeAllVFsUpgradeFailedOnExceptionWhenSkipFailedVFsIsNotSupported() {
final boolean failOnVfUpgrade = false;
final boolean upgradeServices = false;
final boolean exceptionOnVfUpgrade = true;
final boolean upgradeVFC = false;
+ final boolean isFailed = true;
configurationManager.getConfiguration().setSkipUpgradeFailedVfs(false);
resolveUserAndDefineUpgradeLevel();
- upgradeRules(failOnVfUpgrade, exceptionOnVfUpgrade, upgradeServices, upgradeVFC);
- assertEquals(MigrationResult.MigrationStatus.FAILED, migration.migrate().getMigrationStatus());
- verify(titanDao, times(1)).commit();
- verify(titanDao, times(2)).rollback();
+ upgradeRules(failOnVfUpgrade, exceptionOnVfUpgrade, upgradeServices, upgradeVFC, isFailed);
+ migration.init();
+ assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
+ verify(titanDao, times(2)).commit();
+ verify(titanDao, times(0)).rollback();
}
@Test
@@ -137,26 +237,33 @@ public class UpgradeMigration1710Test {
final boolean upgradeServices = true;
final boolean exceptionOnFvUpgrade = true;
final boolean upgradeVFC = false;
+ final boolean isFailed = false;
configurationManager.getConfiguration().setSkipUpgradeFailedVfs(true);
resolveUserAndDefineUpgradeLevel();
- upgradeRules(failOnVfUpgrade, exceptionOnFvUpgrade, upgradeServices, upgradeVFC);
+ upgradeRules(failOnVfUpgrade, exceptionOnFvUpgrade, upgradeServices, upgradeVFC, isFailed);
assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
- verify(titanDao, times(2)).commit();
- verify(titanDao, times(3)).rollback();
+ verify(titanDao, times(3)).commit();
+ verify(titanDao, times(1)).rollback();
}
@Test
public void upgradeAll() {
- final boolean failOnVfUpgrade = false;
- final boolean upgradeServices = true;
- final boolean exceptionOnFvUpgrade = false;
- final boolean upgradeVFC = false;
- resolveUserAndDefineUpgradeLevel();
- upgradeRules(failOnVfUpgrade, exceptionOnFvUpgrade, upgradeServices, upgradeVFC);
+ upgradeAllScenario(true);
assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
- verify(titanDao, times(2)).commit();
- verify(titanDao, times(3)).rollback();
+ verify(titanDao, times(4)).commit();
+ verify(titanDao, times(0)).rollback();
+ }
+
+ @Test
+ public void upgradeAllWhenDeleteLockRetrySucceeded() {
+ when(componentsCleanBusinessLogic.lockDeleteOperation())
+ .thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT)
+ .thenReturn(StorageOperationStatus.OK);
+ upgradeAllScenario(true);
+ assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
+ verify(titanDao, times(4)).commit();
+ verify(titanDao, times(0)).rollback();
}
@Test
@@ -165,10 +272,10 @@ public class UpgradeMigration1710Test {
final boolean upgradeServices = true;
final boolean exceptionOnFvUpgrade = false;
final boolean upgradeVFC = true;
+ final boolean isFailed = true;
resolveUserAndDefineUpgradeLevel();
- upgradeRules(failOnVfUpgrade, exceptionOnFvUpgrade, upgradeServices, upgradeVFC);
+ upgradeRules(failOnVfUpgrade, exceptionOnFvUpgrade, upgradeServices, upgradeVFC, isFailed);
configurationManager.getConfiguration().setSkipUpgradeVSPs(false);
-// migration.setComponentsUtils(componentUtils);
assertEquals(MigrationResult.MigrationStatus.COMPLETED, migration.migrate().getMigrationStatus());
}
@@ -179,70 +286,306 @@ public class UpgradeMigration1710Test {
assertEquals(MigrationResult.MigrationStatus.FAILED, migration.migrate().getMigrationStatus());
}
+ @Test
+ public void verifyThatCheckedOutResourcesMarkedAsDeletedIfUpgradeFailed() {
+ mockCheckoutFlow();
+ when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(),
+ any()))
+ .thenThrow(new ComponentException(responseFormat));
+ when(resourceBusinessLogic.deleteResource(anyString(), any()))
+ .thenReturn(responseFormat);
+ mockChangeComponentState();
+ migration.upgradeVFs(vfList, false);
+ verify(resourceBusinessLogic).deleteResource(anyString(), any());
+ }
+
+ @Test
+ public void verifyThatCheckedOutAllottedResourcesMarkedAsDeletedIfUpgradeFailed() {
+ mockCheckoutFlow();
+ when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(),
+ any()))
+ .thenThrow(new ComponentException(responseFormat));
+ when(resourceBusinessLogic.deleteResource(anyString(), any()))
+ .thenReturn(responseFormat);
+ mockChangeComponentState();
+ migration.upgradeVFs(vfList, true);
+ verify(resourceBusinessLogic).deleteResource(anyString(), any());
+ }
+
+ @Test
+ public void verifyThatCheckedOutResourceIsNotMarkedAsDeletedIfUpgradeSucceeded() {
+ mockCheckoutFlow();
+ resource.setVersion(UPDATED_VERSION);
+ when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(),
+ any()))
+ .thenReturn(resource);
+ mockChangeComponentState();
+ migration.upgradeVFs(vfList, true);
+ verify(resourceBusinessLogic, times(0)).deleteResource(anyString(), any());
+ }
+
+ @Test
+ public void verifyThatCheckedOutServicesMarkedAsDeletedIfUpgradeFailed() {
+ List<String> servicesForUpgrade = new ArrayList<>();
+ servicesForUpgrade.add(COMPONENT_UNIQUE_ID);
+
+ Either<Resource, StorageOperationStatus> foundServices = Either.left(resource);
+ mockCheckoutFlow();
+ when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(toscaOperationFacade.getLatestCertifiedByToscaResourceName(any(), any(), any()))
+ .thenReturn(foundServices);
+ migration.upgradeServices(servicesForUpgrade, component -> true, "services");
+ verify(serviceBusinessLogic, times(0)).deleteService(anyString(), any());
+ }
+
+ @Test
+ public void verifyThatCheckedOutServicesIsNotMarkedAsDeletedIfUpgradeSucceeded() {
+ List<String> servicesForUpgrade = new ArrayList<>();
+ servicesForUpgrade.add(COMPONENT_UNIQUE_ID);
+
+ mockCheckoutFlow();
+ when(toscaOperationFacade.getLatestCertifiedByToscaResourceName(anyString(), any(VertexTypeEnum.class), any(JsonParseFlagEnum.class)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(serviceBusinessLogic.deleteService(anyString(), any()))
+ .thenReturn(responseFormat);
+ migration.upgradeServices(servicesForUpgrade, component -> true, "services");
+ verify(serviceBusinessLogic).deleteService(anyString(), any());
+ }
+
+
+ @Test
+ public void unlockDeleteOperationIsPerformedIfItWasLocked() {
+ migration.isLockDeleteOperationSucceeded();
+ migration.unlockDeleteOperation();
+ verify(componentsCleanBusinessLogic).unlockDeleteOperation();
+ }
+
+ @Test
+ public void unlockDeleteOperationIsNotPerformedIfItWasNotLocked() {
+ when(componentsCleanBusinessLogic.lockDeleteOperation()).thenReturn(StorageOperationStatus.GENERAL_ERROR);
+ migration.isLockDeleteOperationSucceeded();
+ migration.unlockDeleteOperation();
+ verify(componentsCleanBusinessLogic, times(0)).unlockDeleteOperation();
+ }
+
+ @Test
+ public void deleteLockSucceededAfterRetry() {
+ when(componentsCleanBusinessLogic.lockDeleteOperation())
+ .thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT)
+ .thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT)
+ .thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT)
+ .thenReturn(StorageOperationStatus.OK);
+ migration.isLockDeleteOperationSucceeded();
+ migration.unlockDeleteOperation();
+ verify(componentsCleanBusinessLogic).unlockDeleteOperation();
+ }
+
+ @Test
+ public void deleteLockFailedAfterRetry() {
+ when(componentsCleanBusinessLogic.lockDeleteOperation())
+ .thenReturn(StorageOperationStatus.FAILED_TO_LOCK_ELEMENT);
+ migration.isLockDeleteOperationSucceeded();
+ migration.unlockDeleteOperation();
+ verify(componentsCleanBusinessLogic, times(0)).unlockDeleteOperation();
+ }
+
+ @Test
+ public void deleteMarkedResourcesWhenLimitIsReached() {
+ ArrayList<NodeTypeEnum> componentsToClean = new ArrayList<>();
+ componentsToClean.add(NodeTypeEnum.Resource);
+ migration.setUser(user);
+ migration.setMarkedAsDeletedResourcesCnt(5);
+ migration.deleteResourcesIfLimitIsReached();
+ verify(componentsCleanBusinessLogic).cleanComponents(componentsToClean, true);
+ }
+
+ @Test
+ public void deleteMarkedResourcesNotCalledWhenLimitIsNotReached() {
+ ArrayList<NodeTypeEnum> componentsToClean = new ArrayList<>();
+ componentsToClean.add(NodeTypeEnum.Resource);
+ migration.setUser(user);
+ migration.setMarkedAsDeletedResourcesCnt(3);
+ migration.deleteResourcesIfLimitIsReached();
+ verify(componentsCleanBusinessLogic, times(0)).cleanComponents(componentsToClean, true);
+ }
+
+ @Test
+ public void deleteMarkedServicesWhenLimitIsReached() {
+ ArrayList<NodeTypeEnum> componentsToClean = new ArrayList<>();
+ componentsToClean.add(NodeTypeEnum.Service);
+ migration.setUser(user);
+ migration.setMarkedAsDeletedServicesCnt(5);
+ migration.deleteServicesIfLimitIsReached();
+ verify(componentsCleanBusinessLogic).cleanComponents(componentsToClean, true);
+ }
+
+ @Test
+ public void deleteMarkedServicesNotCalledWhenLimitIsNotReached() {
+ ArrayList<NodeTypeEnum> componentsToClean = new ArrayList<>();
+ componentsToClean.add(NodeTypeEnum.Service);
+ migration.setUser(user);
+ migration.setMarkedAsDeletedServicesCnt(2);
+ migration.deleteServicesIfLimitIsReached();
+ verify(componentsCleanBusinessLogic, times(0)).cleanComponents(componentsToClean, true);
+ }
+
+ @Test
+ public void getVfUpgradeStatusWhenUpgradeFailedAndItIsInstance() {
+ assertEquals(UpgradeMigration1710.UpgradeStatus.NOT_UPGRADED, migration.getVfUpgradeStatus(false, true));
+ }
+
+ @Test
+ public void getVfUpgradeStatusWhenUpgradeFailedAndItIsNotInstance() {
+ assertEquals(UpgradeMigration1710.UpgradeStatus.NOT_UPGRADED, migration.getVfUpgradeStatus(false, false));
+ }
+
+ @Test
+ public void getVfUpgradeStatusWhenUpgradeSucceededAndItIsInstance() {
+ assertEquals(UpgradeMigration1710.UpgradeStatus.UPGRADED_AS_INSTANCE, migration.getVfUpgradeStatus(true, true));
+ }
+
+ @Test
+ public void getVfUpgradeStatusWhenUpgradeSucceededAndItIsNotInstance() {
+ assertEquals(UpgradeMigration1710.UpgradeStatus.UPGRADED, migration.getVfUpgradeStatus(true, false));
+ }
+
private void resolveUserAndDefineUpgradeLevel() {
when(userAdminOperation.getUserData(anyString(), eq(false))).thenReturn(Either.left(user));
configurationManager.getConfiguration().setToscaConformanceLevel(CONF_LEVEL);
configurationManager.getConfiguration().setResourcesForUpgrade(resourcesForUpgrade);
}
- private void upgradeRules(boolean failedVfUpgrade, boolean exceptionOnVfUpgrade, boolean upgradeService, boolean upgradeVFCs) {
- GraphVertex component = new GraphVertex();
- component.setJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE, LifecycleStateEnum.CERTIFIED.name());
- component.setJsonMetadataField(JsonPresentationFields.UNIQUE_ID, "12345");
- List<GraphVertex> components = Lists.newArrayList();
- components.add(component);
+ private void upgradeAllScenario(boolean upgradeServices) {
+ final boolean failOnVfUpgrade = false;
+ final boolean exceptionOnFvUpgrade = false;
+ final boolean upgradeVFC = false;
+ final boolean isFailed = false;
+ final boolean isProxy = true;
+
+ resolveUserAndDefineUpgradeLevel();
+ mockCheckoutFlow();
+ when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(),
+ any()))
+ .thenReturn(resource);
+ upgradeRules(failOnVfUpgrade, exceptionOnFvUpgrade, upgradeServices, upgradeVFC, isFailed, isProxy);
+ }
+
+ private void upgradeRules(boolean failedVfUpgrade, boolean exceptionOnVfUpgrade, boolean upgradeService,
+ boolean upgradeVFCs, boolean isFailed) {
+ upgradeRules(failedVfUpgrade, exceptionOnVfUpgrade, upgradeService, upgradeVFCs, isFailed, false);
+ }
- Resource resource = new Resource();
+ private void upgradeRules(boolean failedVfUpgrade, boolean exceptionOnVfUpgrade, boolean upgradeService,
+ boolean upgradeVFCs, boolean isFailed, boolean isProxy) {
+
+ mockNodeTypesUpgrade();
Either<Component, StorageOperationStatus> foundResource = Either.left(resource);
- when(titanDao.getByCriteria(any(), any(), any(), any()))
- .thenReturn(Either.left(components));
- when(titanDao.getParentVertecies(any(GraphVertex.class), any(), any()))
- //1th node to upgrade
- .thenReturn(Either.left(components))
- //parent of the 1th node - stop recursion
- .thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
if (failedVfUpgrade) {
- Either<Component, StorageOperationStatus> getToscaForVF = Either.right(StorageOperationStatus.NOT_FOUND);
- when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(foundResource)
- .thenReturn(foundResource)
- .thenReturn(getToscaForVF);
- }
- else {
+ getToscaElementMockForVfUpgradeFailedScenario(foundResource);
+ } else {
if (exceptionOnVfUpgrade) {
- when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(foundResource)
- .thenReturn(foundResource)
- .thenThrow(new RuntimeException());
- }
- else {
- when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(foundResource);
- //happy flow
- if (upgradeService) {
- Either<Resource, StorageOperationStatus> service = Either.left(resource);
- if (upgradeVFCs) {
- when(componentUtils.convertFromStorageResponse(any(), any())).thenCallRealMethod();
- when(componentUtils.getResponseFormat(any(ActionStatus.class),any())).thenCallRealMethod();
- when(toscaOperationFacade.getLatestCertifiedByToscaResourceName(any(), any(), any()))
- .thenReturn(service)
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND))
- .thenReturn(service)
- .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- }
- else {
- when(toscaOperationFacade.getLatestCertifiedByToscaResourceName(any(), any(), any()))
- .thenReturn(service);
- }
- }
+ getToscaElementMockForExceptionOnUpgradeScenario(foundResource, upgradeService);
+ } else {
+ when(toscaOperationFacade.getToscaElement(anyString()))
+ .thenReturn(foundResource);
}
}
+ //happy flow
+ if (upgradeService) {
+ mockForUpgradeServiceScenario(foundResource, upgradeVFCs, isFailed);
+ }
+ }
+
+ private void mockNodeTypesUpgrade() {
+ GraphVertex component = createComponent();
+ List<GraphVertex> components = Lists.newArrayList();
+ components.add(component);
+
+ when(titanDao.getByCriteria(any(), any(), any(), any()))
+ .thenReturn(Either.left(components));
+ when(titanDao.getParentVertecies(any(GraphVertex.class), any(EdgeLabelEnum.class), any(JsonParseFlagEnum.class)))
+ //1th node to upgrade
+ .thenReturn(Either.left(components))
+ //parent of the 1th node - stop recursion
+ .thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ }
+
+ private GraphVertex createComponent() {
+ GraphVertex component = new GraphVertex();
+ component.setJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE,LifecycleStateEnum.CERTIFIED.name());
+ component.setJsonMetadataField(JsonPresentationFields.UNIQUE_ID,COMPONENT_UNIQUE_ID);
+ component.setJsonMetadataField(JsonPresentationFields.CI_COMPONENT_VERSION,UPDATED_VERSION);
+ return component;
+ }
+
+ private void mockChangeComponentState() {
List<ComponentInstance> instances = Lists.newArrayList();
instances.add(createComponentInstance());
- resource.setComponentInstances(instances);
- Either<Resource, ResponseFormat> fromLifeCycle = Either.left(resource);
+
+ Resource checkedOutResource = new Resource();
+ checkedOutResource.setUniqueId("123400");
+ checkedOutResource.setComponentInstances(instances);
+ Either<Resource, ResponseFormat> fromLifeCycle = Either.left(checkedOutResource);
doReturn(fromLifeCycle).when(lifecycleBusinessLogic)
.changeComponentState(any(), any(), any(), any(), any(),eq(true), eq(false));
+ }
+
+ private void getToscaElementMockForVfUpgradeFailedScenario(Either<Component, StorageOperationStatus> foundResource) {
+ when(toscaOperationFacade.getToscaElement(anyString()))
+ .thenReturn(foundResource)
+ .thenReturn(foundResource)
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ }
+
+ private void mockForUpgradeServiceScenario(Either<Component, StorageOperationStatus> foundResource, boolean upgradeVFC, boolean isFailed) {
+ Either<Resource, StorageOperationStatus> foundService = Either.left(resource);
+ if (upgradeVFC) {
+ when(toscaOperationFacade.getToscaElement(anyString()))
+ .thenReturn(foundResource)
+ .thenReturn(foundResource)
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ }
+ else if (!isFailed) {
+ when(toscaOperationFacade.getToscaElement(any(), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(resource));
+ when(toscaOperationFacade.getLatestCertifiedByToscaResourceName(any(), any(), any()))
+ .thenReturn(foundService);
+ }
+ }
+
+ private void getToscaElementMockForExceptionOnUpgradeScenario(Either<Component, StorageOperationStatus> foundResource, boolean upgradeService) {
+ if (upgradeService) {
+ service.setVersion(UPDATED_VERSION);
+ Either<Component, StorageOperationStatus> foundService = Either.left(service);
+ when(toscaOperationFacade.getToscaElement(anyString()))
+ .thenReturn(foundResource)
+ .thenReturn(foundResource)
+ .thenThrow(new RuntimeException())
+ .thenReturn(foundService);
+ }
+ else {
+ when(toscaOperationFacade.getToscaElement(anyString()))
+ .thenReturn(foundResource)
+ .thenReturn(foundResource)
+ .thenThrow(new RuntimeException());
+ }
+ }
- }
+ private void mockCheckoutFlow() {
+ GraphVertex component = new GraphVertex();
+ component.setJsonMetadataField(JsonPresentationFields.LIFECYCLE_STATE, LifecycleStateEnum.CERTIFIED.name());
+ component.setJsonMetadataField(JsonPresentationFields.UNIQUE_ID, COMPONENT_UNIQUE_ID);
+ List<GraphVertex> components = Lists.newArrayList();
+ components.add(component);
+
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource));
+ when(titanDao.getByCriteria(any(), any(), any(), any()))
+ .thenReturn(Either.left(components));
+ when(csarOperation.getCsarLatestVersion(anyString(), any()))
+ .thenReturn(Either.left("2.0"));
+ }
private ComponentInstance createComponentInstance() {
ComponentInstance instance = new ComponentInstance();
@@ -260,7 +603,7 @@ public class UpgradeMigration1710Test {
instance.setOriginType(OriginTypeEnum.CVFC);
instance.setCustomizationUUID("");
instance.setComponentName("");
- instance.setComponentVersion("");
+ instance.setComponentVersion(OLD_VERSION);
instance.setToscaComponentName("");
instance.setInvariantName("");
instance.setSourceModelInvariant("");
@@ -269,7 +612,7 @@ public class UpgradeMigration1710Test {
instance.setSourceModelUid("");
instance.setIsProxy(false);
return instance;
- }
+ }
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java
new file mode 100644
index 0000000000..d040d66496
--- /dev/null
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1806/SDCInstancesMigrationTest.java
@@ -0,0 +1,69 @@
+package org.openecomp.sdc.asdctool.migration.tasks.mig1806;
+
+import fj.data.Either;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
+import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult.MigrationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SDCInstancesMigrationTest{
+ @Mock
+ private TitanDao titanDao;
+ @Mock
+ private NodeTemplateOperation nodeTemplateOperation;
+
+
+ @Test
+ public void testFailedMigration(){
+ SDCInstancesMigration instancesMigration = new SDCInstancesMigration(titanDao, nodeTemplateOperation);
+ when(titanDao.getByCriteria(any(), any(), any(), any() )).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
+
+ MigrationResult migrate = instancesMigration.migrate();
+ MigrationStatus migrationStatus = migrate.getMigrationStatus();
+ assertEquals(MigrationStatus.FAILED, migrationStatus);
+ }
+ @Test
+ public void testSuccessMigration(){
+ SDCInstancesMigration instancesMigration = new SDCInstancesMigration(titanDao, nodeTemplateOperation);
+ List<GraphVertex> list = new ArrayList<>();
+ GraphVertex vertexOrig = new GraphVertex();
+ Map<String, CompositionDataDefinition> jsonComposition = new HashMap<>();
+ CompositionDataDefinition composition = new CompositionDataDefinition();
+ Map<String, ComponentInstanceDataDefinition> componentInstances = new HashMap<>();
+ ComponentInstanceDataDefinition instance = new ComponentInstanceDataDefinition();
+ componentInstances.put("instanceId", instance);
+ composition.setComponentInstances(componentInstances);
+ jsonComposition.put(JsonConstantKeysEnum.COMPOSITION.getValue(), composition);
+ vertexOrig.setJson(jsonComposition);
+ vertexOrig.setType(ComponentTypeEnum.SERVICE);
+ list.add(vertexOrig);
+
+ when(titanDao.getByCriteria(any(), any(), any(), any() )).thenReturn(Either.left(list));
+ when(nodeTemplateOperation.createInstanceEdge(vertexOrig, instance)).thenReturn(StorageOperationStatus.OK);
+
+ MigrationResult migrate = instancesMigration.migrate();
+ MigrationStatus migrationStatus = migrate.getMigrationStatus();
+ assertEquals(MigrationStatus.COMPLETED, migrationStatus);
+ }
+}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServletTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServletTest.java
index 2733beeda7..9f104632dd 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServletTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServletTest.java
@@ -1,12 +1,10 @@
package org.openecomp.sdc.asdctool.servlets;
-import java.io.File;
-
-import javax.ws.rs.core.Response;
-
+import com.thinkaurelius.titan.core.TitanGraph;
import org.junit.Test;
-import com.thinkaurelius.titan.core.TitanGraph;
+import javax.ws.rs.core.Response;
+import java.io.File;
public class ExportImportTitanServletTest {