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 com.thinkaurelius.titan.core.TitanVertex;
24 import org.junit.Rule;
25 import org.junit.rules.TestName;
26 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
27 import org.openecomp.sdc.ci.tests.migration.v1707.CommonMigrationUtils;
28 import org.openecomp.sdc.ci.tests.utils.graph.GraphFileUtils;
29 import org.testng.annotations.Test;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
36 import static org.testng.Assert.*;
38 public class AttKeyPropertiesRenameTest extends ComponentBaseTest {
41 public static TestName name = new TestName();
44 public AttKeyPropertiesRenameTest() {
45 super(name, AttKeyPropertiesRenameTest.class.getName());
49 public void verifyAttPropertyKeys() throws Exception {
51 CommonMigrationUtils.assertKeyNotExist(titanGraph, "attContact");
52 CommonMigrationUtils.assertKeyNotExist(titanGraph, "attCreator");
53 CommonMigrationUtils.assertKeyNotExist(titanGraph, "attuid");
54 CommonMigrationUtils.assertKeyNotExist(titanGraph, "pmatt");
56 CommonMigrationUtils.assertKeyExists(titanGraph, "userId");
57 CommonMigrationUtils.assertKeyExists(titanGraph, "projectCode");
58 CommonMigrationUtils.assertKeyExists(titanGraph, "contactId");
59 CommonMigrationUtils.assertKeyExists(titanGraph, "creatorId");
61 verifyPropertyKeysVerticesSameAsPreUpgrade("attuid", "userId");
62 verifyPropertyKeysVerticesSameAsPreUpgrade("pmatt", "projectCode");
63 verifyPropertyKeysVerticesSameAsPreUpgrade("attContact", "contactId");
64 verifyPropertyKeysVerticesSameAsPreUpgrade("attCreator", "creatorId");
68 private void assertKeyNotExist(String key) {
69 assertNotNull(titanGraph.getPropertyKey(key));
72 private void assertKeyExists(String key) {
73 assertNull(titanGraph.getPropertyKey(key));
76 private void verifyPropertyKeysVerticesSameAsPreUpgrade(String oldPropertyKEyName, String newPropertyKeyName) throws IOException {
77 List<String> verticesIdsFromGraph = getVerticesIdsFromGRaph(newPropertyKeyName);
78 List<String> verticesIdsFromFile = GraphFileUtils.getVerticesIdsFromFile(oldPropertyKEyName);
79 Collections.sort(verticesIdsFromFile);
80 Collections.sort(verticesIdsFromGraph);
81 assertEquals(verticesIdsFromFile, verticesIdsFromGraph);
84 private List<String> getVerticesIdsFromGRaph(String newPropertyKeyName) {
85 Iterable<TitanVertex> vertices = titanGraph.query().has(newPropertyKeyName).vertices();
86 assertTrue(vertices.iterator().hasNext());
87 List<String> verticesIdsFromGraph = new ArrayList<>();
88 vertices.forEach(vertex -> verticesIdsFromGraph.add(vertex.id().toString()));
89 return verticesIdsFromGraph;