2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 
   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 static org.hamcrest.MatcherAssert.assertThat;
 
  27 import static org.hamcrest.core.Is.is;
 
  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;
 
  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;
 
  44 public class TestXmlParser {
 
  46     private static final Logger log = LoggerFactory.getLogger(TestXmlParser.class);
 
  49     public void test() throws Exception {
 
  50         BufferedReader in = new BufferedReader(
 
  51                 new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
 
  53         StringBuilder b = new StringBuilder();
 
  55         while ((line = in.readLine()) != null)
 
  56             b.append(line).append('\n');
 
  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");
 
  66         Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
 
  72     public void testValidLength() throws Exception {
 
  73         BufferedReader in = new BufferedReader(
 
  74             new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))
 
  76         StringBuilder b = new StringBuilder();
 
  78         while ((line = in.readLine()) != null)
 
  79             b.append(line).append('\n');
 
  81         Set<String> listNameList = new HashSet<String>();
 
  82         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
 
  83         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
 
  85         Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
 
  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"));
 
  94     @Test(expected = SvcLogicException.class)
 
  95     public void testInvalidLength() throws Exception {
 
  96         BufferedReader in = new BufferedReader(
 
  97             new InputStreamReader(ClassLoader.getSystemResourceAsStream("invalidlength.xml"))
 
  99         StringBuilder b = new StringBuilder();
 
 101         while ((line = in.readLine()) != null)
 
 102             b.append(line).append('\n');
 
 104         Set<String> listNameList = new HashSet<String>();
 
 105         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
 
 106         listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
 
 108         Map<String, String> mm = XmlParser.convertToProperties(b.toString(), listNameList);
 
 113     private void logProperties(Map<String, String> mm) {
 
 114         List<String> ll = new ArrayList<>();
 
 115         for (Object o : mm.keySet())
 
 117         Collections.sort(ll);
 
 119         log.info("Properties:");
 
 120         for (String name : ll)
 
 121             log.info("--- " + name + ": " + mm.get(name));