Fix for radio buttons
[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 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;
27
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32
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;
39
40 import com.thinkaurelius.titan.core.TitanVertex;
41
42 public class AttKeyPropertiesRenameTest extends ComponentBaseTest {
43
44     @Rule
45     public static TestName name = new TestName();
46
47
48     public AttKeyPropertiesRenameTest() {
49         super(name, AttKeyPropertiesRenameTest.class.getName());
50     }
51
52     @Test
53     public void verifyAttPropertyKeys() throws Exception {
54         initGraph();
55         CommonMigrationUtils.assertKeyNotExist(titanGraph, "attContact");
56         CommonMigrationUtils.assertKeyNotExist(titanGraph, "attCreator");
57         CommonMigrationUtils.assertKeyNotExist(titanGraph, "attuid");
58         CommonMigrationUtils.assertKeyNotExist(titanGraph, "pmatt");
59
60         CommonMigrationUtils.assertKeyExists(titanGraph, "userId");
61         CommonMigrationUtils.assertKeyExists(titanGraph, "projectCode");
62         CommonMigrationUtils.assertKeyExists(titanGraph, "contactId");
63         CommonMigrationUtils.assertKeyExists(titanGraph, "creatorId");
64
65         verifyPropertyKeysVerticesSameAsPreUpgrade("attuid", "userId");
66         verifyPropertyKeysVerticesSameAsPreUpgrade("pmatt", "projectCode");
67         verifyPropertyKeysVerticesSameAsPreUpgrade("attContact", "contactId");
68         verifyPropertyKeysVerticesSameAsPreUpgrade("attCreator", "creatorId");
69
70     }
71
72     private void assertKeyNotExist(String key) {
73         assertNotNull(titanGraph.getPropertyKey(key));
74     }
75
76     private void assertKeyExists(String key) {
77         assertNull(titanGraph.getPropertyKey(key));
78     }
79
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);
86     }
87
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;
94     }
95 }