fix use of user credentials logic
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / config / MainToTest.java
1 package org.openecomp.sdc.ci.tests.config;
2
3
4 import fj.data.Either;
5 import org.apache.commons.io.IOUtils;
6 import org.json.JSONObject;
7 import org.openecomp.sdc.be.model.Service;
8 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
9 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
10 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
11 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
12 import org.yaml.snakeyaml.Yaml;
13
14 import java.io.*;
15 import java.nio.charset.Charset;
16 import java.nio.charset.StandardCharsets;
17 import java.util.Map;
18
19 public class MainToTest {
20
21     private static final String CREDENTIALS_FILE = "credentials.yaml";
22
23     public static void main(String[] args) throws Exception {
24         System.out.println("Hello World!"); // Display the string.
25         System.out.println("user.dir: " + System.getProperty("user.dir"));
26         System.out.println(UserRoleEnum.DESIGNER.getFirstName());
27         String file = readFile();
28         convertToJson(file);
29         Either<Service, RestResponse> createDefaultService1e = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true);
30
31
32
33     }
34
35     private static String convertToJson(String yamlString) {
36         Yaml yaml = new Yaml();
37         Map<String, Object> map = (Map<String, Object>) yaml.load(yamlString);
38
39         JSONObject jsonObject = new JSONObject(map);
40         return jsonObject.toString();
41     }
42
43     private static String readFile() {
44
45     File credentialsFileLocal = new File(FileHandling.getSdcVnfsPath() + File.separator + "conf"
46             + File.separator + CREDENTIALS_FILE);
47
48         InputStream inputStream = null;
49         try {
50             inputStream = new FileInputStream(credentialsFileLocal);
51         } catch (FileNotFoundException e) {
52             e.printStackTrace();
53         }
54         finally {
55             try {
56                 String mystr = IOUtils.toString(inputStream, Charset.forName("UTF-8"));
57                 inputStream.close();
58                 return mystr;
59             } catch(IOException e) {
60             }
61         }
62
63         return null;
64     }
65
66
67 }