Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / utils / graph / GraphFileUtils.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.utils.graph;
22
23 import java.io.IOException;
24 import java.nio.charset.Charset;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.apache.commons.io.FileUtils;
32 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
33
34 import com.thinkaurelius.titan.core.TitanVertex;
35
36 public class GraphFileUtils {
37
38     public static final String TEMP_FILES_PATH = "src/main/resources/ci/tempFiles/%s.txt";
39
40     public static void writeVerticesUIDToFile(String fileName, Iterable<TitanVertex> vertices) throws IOException {
41         Path path = Paths.get(String.format(TEMP_FILES_PATH, fileName));
42         Files.deleteIfExists(path);
43         Path file = Files.createFile(path);
44         final String newLine = System.getProperty("line.separator");
45         for (TitanVertex vertex : vertices) {
46             FileUtils.writeStringToFile(file.toFile(), String.valueOf(vertex.id()) + newLine, Charset.defaultCharset(), true);
47         }
48     }
49
50     public static List<String> getVerticesIdsFromFile(String fileName) throws IOException {
51         List<String> verticesUids = new ArrayList<>();
52         Files.lines(Paths.get(String.format(TEMP_FILES_PATH, fileName))).forEach(verticesUids::add);
53         return verticesUids;
54     }
55
56     private static String getUid(TitanVertex titanVertex) {
57         return (String )titanVertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
58     }
59
60 }