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.junit.Assert.assertEquals;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.HashSet;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 public class TestXmlParser {
36 public void test() throws Exception {
37 String path = "src/test/resources/test3.xml";
38 String content = new String(Files.readAllBytes(Paths.get(path)));
39 Set<String> listNameList = new HashSet<String>();
40 listNameList.add("project.dependencies.dependency");
41 listNameList.add("project.build.plugins.plugin");
42 listNameList.add("project.build.plugins.plugin.executions.execution");
43 listNameList.add("project.build.pluginManagement.plugins.plugin");
44 listNameList.add("project.build.pluginManagement." +
45 "plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution");
47 Map<String, String> mm = XmlParser.convertToProperties(content, listNameList);
48 assertEquals("811182", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VpnId"));
49 assertEquals("v6", mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.Family"));
50 assertEquals("SET6_BVOIP_IN", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport"));
51 assertEquals("AG_MAX_MCASTROUTES",
52 mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.ApplyGroup.ApplyGroup"));
53 assertEquals("ICOREPVC-81114561", mm.get("ApplyGroupResponse.ApplyGroupResponseData.ServiceInstanceId"));
54 assertEquals("SET_RESET_LP", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport"));
55 assertEquals("21302:811182", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfName"));
56 assertEquals("BGP4_PROTOCOL",
57 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.RoutingProtocol"));
58 assertEquals("AG6_MAX_PREFIX",
59 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.ApplyGroupPeer.ApplyGroup"));
60 assertEquals("VPNL811182", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.End2EndVpnKey"));
61 assertEquals("AG6_BFD_BGP_3000",
62 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.ApplyGroupNeighbour.ApplyGroup"));
63 assertEquals("200", mm.get("ApplyGroupResponse.response-code"));
64 assertEquals("gp6_21302:811182",
65 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.PeerGroupName"));
66 assertEquals("Y", mm.get("ApplyGroupResponse.ack-final-indicator"));
67 assertEquals("Success", mm.get("ApplyGroupResponse.response-message"));
71 public void testValidLength() throws Exception {
72 String path = "src/test/resources/test3.xml";
73 String content = new String(Files.readAllBytes(Paths.get(path)));
74 Set<String> listNameList = new HashSet<String>();
75 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
76 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
78 Map<String, String> mm = XmlParser.convertToProperties(content, listNameList);
79 assertEquals("AG6_BFD_BGP_3000",
80 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.ApplyGroupNeighbour.ApplyGroup"));
81 assertEquals("AG6_MAX_PREFIX",
82 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.ApplyGroupPeer.ApplyGroup"));
83 assertEquals("v6", mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.Family"));
84 assertEquals("gp6_21302:811182",
85 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.PeerGroupName"));
86 assertEquals("BGP4_PROTOCOL",
87 mm.get("ApplyGroupResponse.ApplyGroupResponseData.RoutingApplyGroups.RoutingProtocol"));
88 assertEquals("ICOREPVC-81114561", mm.get("ApplyGroupResponse.ApplyGroupResponseData.ServiceInstanceId"));
89 assertEquals("AG_MAX_MCASTROUTES",
90 mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.ApplyGroup.ApplyGroup"));
91 assertEquals("VPNL811182", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.End2EndVpnKey"));
92 assertEquals("811182", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VpnId"));
93 assertEquals("SET6_DSU", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[0]"));
94 assertEquals("SET_DSU", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[1]"));
95 assertEquals("SET6_MANAGED", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[2]"));
96 assertEquals("SET_MANAGED", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[3]"));
97 assertEquals("SET_LOVRF_COMMUNITY",
98 mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[4]"));
99 assertEquals("SET_RESET_LP", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[5]"));
100 assertEquals("6", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport_length"));
101 assertEquals("SET_BVOIP_IN", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport[0]"));
102 assertEquals("SET6_BVOIP_IN", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport[1]"));
103 assertEquals("2", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport_length"));
104 assertEquals("21302:811182", mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfName"));
105 assertEquals("Y", mm.get("ApplyGroupResponse.ack-final-indicator"));
106 assertEquals("200", mm.get("ApplyGroupResponse.response-code"));
107 assertEquals("Success", mm.get("ApplyGroupResponse.response-message"));
110 @Test(expected = SvcLogicException.class)
111 public void testInvalidLength() throws Exception {
112 String path = "src/test/resources/invalidlength.xml";
113 String content = new String(Files.readAllBytes(Paths.get(path)));
114 Set<String> listNameList = new HashSet<String>();
115 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport");
116 listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport");
117 XmlParser.convertToProperties(content, listNameList); // throws an exception because the length in the xml is
118 // not a valid number