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.utils.graph;
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;
31 import org.apache.commons.io.FileUtils;
32 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
34 import com.thinkaurelius.titan.core.TitanVertex;
36 public class GraphFileUtils {
38 public static final String TEMP_FILES_PATH = "src/main/resources/ci/tempFiles/%s.txt";
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);
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);
56 private static String getUid(TitanVertex titanVertex) {
57 return (String )titanVertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());