9df790ae3b79af41fd573001474245695aef4a61
[ccsdk/sli/plugins.git] / sshapi-call-node / provider / src / test / java / jtest / org / onap / ccsdk / sli / plugins / sshapicall / TestJsonParser.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * * Copyright (C) 2017 AT&T Intellectual Property.
6  * ================================================================================
7  * Copyright (C) 2018 Samsung Electronics. All rights
8  *                      reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package jtest.org.onap.ccsdk.sli.plugins.sshapicall;
25
26 import java.io.BufferedReader;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Map;
33
34 import org.junit.Test;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.plugins.sshapicall.model.JsonParser;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 public class TestJsonParser {
41
42     private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class);
43
44     @Test
45     public void test() throws SvcLogicException, IOException {
46         BufferedReader in = new BufferedReader(
47                 new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json"))
48         );
49         StringBuilder b = new StringBuilder();
50         String line;
51         while ((line = in.readLine()) != null)
52             b.append(line).append('\n');
53
54         Map<String, String> mm = JsonParser.convertToProperties(b.toString());
55
56         logProperties(mm);
57
58         in.close();
59     }
60
61     @Test(expected = NullPointerException.class)
62     public void testNullString() throws SvcLogicException {
63         JsonParser.convertToProperties(null);
64     }
65
66     private void logProperties(Map<String, String> mm) {
67         List<String> ll = new ArrayList<>();
68         for (Object o : mm.keySet())
69             ll.add((String) o);
70         Collections.sort(ll);
71         log.info("Properties:");
72         for (String name : ll)
73             log.info("--- {}: {}", name, mm.get(name));
74     }
75 }