2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.plugins.restapicall;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.core.Is.is;
27 import java.io.BufferedReader;
28 import java.io.InputStreamReader;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.HashSet;
32 import java.util.List;
36 import org.junit.Test;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
38 import org.onap.ccsdk.sli.plugins.restapicall.XmlParser;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class TestXmlParser {
44 private static final Logger log = LoggerFactory.getLogger(TestXmlParser.class);
47 public void test() throws Exception {
48 BufferedReader in = new BufferedReader(
49 new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
51 StringBuilder b = new StringBuilder();
53 while ((line = in.readLine()) != null)
54 b.append(line).append('\n');
56 Set<String> listNameList = new HashSet<String>();
57 listNameList.add("project.dependencies.dependency");
58 listNameList.add("project.build.plugins.plugin");
59 listNameList.add("project.build.plugins.plugin.executions.execution");
60 listNameList.add("project.build.pluginManagement.plugins.plugin");
61 listNameList.add("project.build.pluginManagement." +
62 "plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution");
64 Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
70 public void testValidLength() throws Exception {
71 BufferedReader in = new BufferedReader(
72 new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
74 StringBuilder b = new StringBuilder();
76 while ((line = in.readLine()) != null)
77 b.append(line).append('\n');
79 Set<String> listNameList = new HashSet<String>();
80 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
81 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
83 Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
85 assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[5]"), is("SET_RESET_LP"));
86 assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport[0]"), is("SET_BVOIP_IN"));
92 @Test(expected = SvcLogicException.class)
93 public void testInvalidLength() throws Exception {
94 BufferedReader in = new BufferedReader(
95 new InputStreamReader(ClassLoader.getSystemResourceAsStream("invalidlength.xml"))
97 StringBuilder b = new StringBuilder();
99 while ((line = in.readLine()) != null)
100 b.append(line).append('\n');
102 Set<String> listNameList = new HashSet<String>();
103 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
104 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
106 Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
111 private void logProperties(Map<String, String> mm) {
112 List<String> ll = new ArrayList<>();
113 for (Object o : mm.keySet())
115 Collections.sort(ll);
117 log.info("Properties:");
118 for (String name : ll)
119 log.info("--- " + name + ": " + mm.get(name));