[sdc] rebase update
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / migration / v1707 / postupgrade / AttKeyPropertiesRenameTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.migration.v1707.postupgrade;
22
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;
30
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
35
36 import static org.testng.Assert.*;
37
38 public class AttKeyPropertiesRenameTest extends ComponentBaseTest {
39
40     @Rule
41     public static TestName name = new TestName();
42
43
44     public AttKeyPropertiesRenameTest() {
45         super(name, AttKeyPropertiesRenameTest.class.getName());
46     }
47
48     @Test
49     public void verifyAttPropertyKeys() throws Exception {
50         initGraph();
51         CommonMigrationUtils.assertKeyNotExist(titanGraph, "attContact");
52         CommonMigrationUtils.assertKeyNotExist(titanGraph, "attCreator");
53         CommonMigrationUtils.assertKeyNotExist(titanGraph, "attuid");
54         CommonMigrationUtils.assertKeyNotExist(titanGraph, "pmatt");
55
56         CommonMigrationUtils.assertKeyExists(titanGraph, "userId");
57         CommonMigrationUtils.assertKeyExists(titanGraph, "projectCode");
58         CommonMigrationUtils.assertKeyExists(titanGraph, "contactId");
59         CommonMigrationUtils.assertKeyExists(titanGraph, "creatorId");
60
61         verifyPropertyKeysVerticesSameAsPreUpgrade("attuid", "userId");
62         verifyPropertyKeysVerticesSameAsPreUpgrade("pmatt", "projectCode");
63         verifyPropertyKeysVerticesSameAsPreUpgrade("attContact", "contactId");
64         verifyPropertyKeysVerticesSameAsPreUpgrade("attCreator", "creatorId");
65
66     }
67
68     private void assertKeyNotExist(String key) {
69         assertNotNull(titanGraph.getPropertyKey(key));
70     }
71
72     private void assertKeyExists(String key) {
73         assertNull(titanGraph.getPropertyKey(key));
74     }
75
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);
82     }
83
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;
90     }
91 }