2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.config.generator.pattern;
27 import static org.junit.Assert.assertEquals;
28 import java.util.HashMap;
30 import org.apache.commons.io.IOUtils;
31 import org.junit.Test;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
35 public class TestPatternNode {
38 public void parseErrorLog() throws Exception {
39 PatternNode patternNode = new PatternNode();
40 Map<String, String> inParams = new HashMap<String, String>();
41 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
42 String logData = IOUtils.toString(
43 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
44 ConfigGeneratorConstant.STRING_ENCODING);
45 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_LOG_DATA, logData);
46 SvcLogicContext ctx = new SvcLogicContext();
47 patternNode.parseErrorLog(inParams, ctx);
48 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
49 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
53 // @Test(expected=Exception.class)
54 public void checkXMLData() throws Exception {
55 PatternNode patternNode = new PatternNode();
56 Map<String, String> inParams = new HashMap<String, String>();
57 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
59 String xmlData = IOUtils.toString(
60 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
61 ConfigGeneratorConstant.STRING_ENCODING);
62 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, xmlData);
63 SvcLogicContext ctx = new SvcLogicContext();
64 patternNode.checkDataType(inParams, ctx);
65 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
66 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
70 public void checkJsonData() throws Exception {
71 PatternNode patternNode = new PatternNode();
72 Map<String, String> inParams = new HashMap<String, String>();
73 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
75 IOUtils.toString(TestPatternNode.class.getClassLoader().getResourceAsStream(
76 "pattern/json_data.json"), ConfigGeneratorConstant.STRING_ENCODING);
77 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, xmlData);
78 SvcLogicContext ctx = new SvcLogicContext();
79 patternNode.checkDataType(inParams, ctx);
80 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
81 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
84 @Test(expected = Exception.class)
85 public void checStringData() throws Exception {
86 PatternNode patternNode = new PatternNode();
87 Map<String, String> inParams = new HashMap<String, String>();
88 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
89 String stringData = IOUtils.toString(
90 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/text_data.txt"),
91 ConfigGeneratorConstant.STRING_ENCODING);
92 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, stringData);
93 SvcLogicContext ctx = new SvcLogicContext();
94 patternNode.checkDataType(inParams, ctx);
95 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
96 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);