2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * * Copyright (C) 2017 AT&T Intellectual Property.
6 * ================================================================================
7 * Copyright (C) 2018 Samsung Electronics. All rights
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package jtest.org.onap.ccsdk.sli.plugins.sshapicall;
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;
34 import org.codehaus.jettison.json.JSONException;
35 import org.junit.Test;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37 import org.onap.ccsdk.sli.plugins.sshapicall.model.JsonParser;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 public class TestJsonParser {
43 private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class);
46 public void test() throws SvcLogicException, IOException {
47 BufferedReader in = new BufferedReader(
48 new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json"))
50 StringBuilder b = new StringBuilder();
52 while ((line = in.readLine()) != null)
53 b.append(line).append('\n');
54 Map<String, String> mm = null;
56 mm = JsonParser.convertToProperties(b.toString());
57 } catch (JSONException e){
58 throw new SvcLogicException(e.getMessage());
66 @Test(expected = NullPointerException.class)
67 public void testNullString() throws SvcLogicException {
68 Map<String, String> mm = null;
70 mm = JsonParser.convertToProperties(null);
71 } catch (JSONException e){
72 throw new SvcLogicException(e.getMessage());
76 private void logProperties(Map<String, String> mm) {
77 List<String> ll = new ArrayList<>();
78 for (Object o : mm.keySet())
81 log.info("Properties:");
82 for (String name : ll)
83 log.info("--- {}: {}", name, mm.get(name));