Replacing ":" by "_" for parameters
[ccsdk/sli/plugins.git] / sshapi-call-node / provider / src / test / java / jtest / org / onap / ccsdk / sli / plugins / sshapicall / TestXmlParser.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
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 static org.hamcrest.MatcherAssert.assertThat;
27 import static org.hamcrest.core.Is.is;
28
29 import java.io.BufferedReader;
30 import java.io.InputStreamReader;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37
38 import org.junit.Test;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.plugins.sshapicall.model.XmlParser;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 public class TestXmlParser {
45
46     private static final Logger log = LoggerFactory.getLogger(TestXmlParser.class);
47
48     @Test
49     public void test() throws Exception {
50         BufferedReader in = new BufferedReader(
51                 new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
52         );
53         StringBuilder b = new StringBuilder();
54         String line;
55         while ((line = in.readLine()) != null)
56             b.append(line).append('\n');
57
58         Set<String> listNameList = new HashSet<String>();
59         listNameList.add("project.dependencies.dependency");
60         listNameList.add("project.build.plugins.plugin");
61         listNameList.add("project.build.plugins.plugin.executions.execution");
62         listNameList.add("project.build.pluginManagement.plugins.plugin");
63         listNameList.add("project.build.pluginManagement." +
64                         "plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution");
65
66         Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
67         logProperties(mm);
68         in.close();
69     }
70
71     @Test
72     public void testValidLength() throws Exception {
73         BufferedReader in = new BufferedReader(
74             new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
75         );
76         StringBuilder b = new StringBuilder();
77         String line;
78         while ((line = in.readLine()) != null)
79             b.append(line).append('\n');
80
81         Set<String> listNameList = new HashSet<String>();
82         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
83         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
84
85         Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
86
87         assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[5]"), is("SET_RESET_LP"));
88         assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport[0]"), is("SET_BVOIP_IN"));
89
90         logProperties(mm);
91         in.close();
92     }
93
94     @Test(expected = SvcLogicException.class)
95     public void testInvalidLength() throws Exception {
96         BufferedReader in = new BufferedReader(
97             new InputStreamReader(ClassLoader.getSystemResourceAsStream("invalidlength.xml"))
98         );
99         StringBuilder b = new StringBuilder();
100         String line;
101         while ((line = in.readLine()) != null)
102             b.append(line).append('\n');
103
104         Set<String> listNameList = new HashSet<String>();
105         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
106         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
107
108         Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
109         logProperties(mm);
110         in.close();
111     }
112
113     private void logProperties(Map<String, String> mm) {
114         List<String> ll = new ArrayList<>();
115         for (Object o : mm.keySet())
116             ll.add((String) o);
117         Collections.sort(ll);
118
119         log.info("Properties:");
120         for (String name : ll)
121             log.info("--- " + name + ": " + mm.get(name));
122     }
123 }