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