2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.migration.v1707.postupgrade;
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNotNull;
25 import static org.testng.Assert.assertNull;
26 import static org.testng.Assert.assertTrue;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
33 import org.junit.Rule;
34 import org.junit.rules.TestName;
35 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
36 import org.openecomp.sdc.ci.tests.migration.v1707.CommonMigrationUtils;
37 import org.openecomp.sdc.ci.tests.utils.graph.GraphFileUtils;
38 import org.testng.annotations.Test;
40 import com.thinkaurelius.titan.core.TitanVertex;
42 public class AttKeyPropertiesRenameTest extends ComponentBaseTest {
45 public static TestName name = new TestName();
48 public AttKeyPropertiesRenameTest() {
49 super(name, AttKeyPropertiesRenameTest.class.getName());
53 public void verifyAttPropertyKeys() throws Exception {
55 CommonMigrationUtils.assertKeyNotExist(titanGraph, "attContact");
56 CommonMigrationUtils.assertKeyNotExist(titanGraph, "attCreator");
57 CommonMigrationUtils.assertKeyNotExist(titanGraph, "attuid");
58 CommonMigrationUtils.assertKeyNotExist(titanGraph, "pmatt");
60 CommonMigrationUtils.assertKeyExists(titanGraph, "userId");
61 CommonMigrationUtils.assertKeyExists(titanGraph, "projectCode");
62 CommonMigrationUtils.assertKeyExists(titanGraph, "contactId");
63 CommonMigrationUtils.assertKeyExists(titanGraph, "creatorId");
65 verifyPropertyKeysVerticesSameAsPreUpgrade("attuid", "userId");
66 verifyPropertyKeysVerticesSameAsPreUpgrade("pmatt", "projectCode");
67 verifyPropertyKeysVerticesSameAsPreUpgrade("attContact", "contactId");
68 verifyPropertyKeysVerticesSameAsPreUpgrade("attCreator", "creatorId");
72 private void assertKeyNotExist(String key) {
73 assertNotNull(titanGraph.getPropertyKey(key));
76 private void assertKeyExists(String key) {
77 assertNull(titanGraph.getPropertyKey(key));
80 private void verifyPropertyKeysVerticesSameAsPreUpgrade(String oldPropertyKEyName, String newPropertyKeyName) throws IOException {
81 List<String> verticesIdsFromGraph = getVerticesIdsFromGRaph(newPropertyKeyName);
82 List<String> verticesIdsFromFile = GraphFileUtils.getVerticesIdsFromFile(oldPropertyKEyName);
83 Collections.sort(verticesIdsFromFile);
84 Collections.sort(verticesIdsFromGraph);
85 assertEquals(verticesIdsFromFile, verticesIdsFromGraph);
88 private List<String> getVerticesIdsFromGRaph(String newPropertyKeyName) {
89 Iterable<TitanVertex> vertices = titanGraph.query().has(newPropertyKeyName).vertices();
90 assertTrue(vertices.iterator().hasNext());
91 List<String> verticesIdsFromGraph = new ArrayList<>();
92 vertices.forEach(vertex -> verticesIdsFromGraph.add(vertex.id().toString()));
93 return verticesIdsFromGraph;