2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Modifications Copyright (C) 2018 Ericsson
12 * =============================================================================
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 * ============LICENSE_END=========================================================
28 package org.onap.sdnc.config.generator.pattern;
30 import static org.junit.Assert.assertEquals;
31 import java.util.HashMap;
33 import org.apache.commons.io.IOUtils;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
39 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
41 public class TestPatternNode {
44 public ExpectedException expectedEx = ExpectedException.none();
47 public void parseErrorLog() throws Exception {
48 PatternNode patternNode = new PatternNode();
49 Map<String, String> inParams = new HashMap<String, String>();
50 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
51 String logData = IOUtils.toString(
52 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
53 ConfigGeneratorConstant.STRING_ENCODING);
54 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_LOG_DATA, logData);
55 SvcLogicContext ctx = new SvcLogicContext();
56 patternNode.parseErrorLog(inParams, ctx);
57 assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
58 ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
62 public void testParseErrorLogForEmptyLogData() throws Exception {
63 PatternNode patternNode = new PatternNode();
64 Map<String, String> inParams = new HashMap<String, String>();
65 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
66 SvcLogicContext ctx = new SvcLogicContext();
67 expectedEx.expect(SvcLogicException.class);
68 expectedEx.expectMessage("Log Data is missing");
69 patternNode.parseErrorLog(inParams, ctx);
73 // @Test(expected=Exception.class)
74 public void checkXMLData() throws Exception {
75 PatternNode patternNode = new PatternNode();
76 Map<String, String> inParams = new HashMap<String, String>();
77 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
78 String xmlData = IOUtils.toString(
79 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
80 ConfigGeneratorConstant.STRING_ENCODING);
81 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, xmlData);
82 SvcLogicContext ctx = new SvcLogicContext();
83 patternNode.checkDataType(inParams, ctx);
84 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
85 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
89 public void checkJsonData() throws Exception {
90 PatternNode patternNode = new PatternNode();
91 Map<String, String> inParams = new HashMap<String, String>();
92 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
94 IOUtils.toString(TestPatternNode.class.getClassLoader().getResourceAsStream(
95 "pattern/json_data.json"), ConfigGeneratorConstant.STRING_ENCODING);
96 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, xmlData);
97 SvcLogicContext ctx = new SvcLogicContext();
98 patternNode.checkDataType(inParams, ctx);
99 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
100 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
104 public void checStringData() throws Exception {
105 PatternNode patternNode = new PatternNode();
106 Map<String, String> inParams = new HashMap<String, String>();
107 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
108 String stringData = IOUtils.toString(
109 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/text_data.txt"),
110 ConfigGeneratorConstant.STRING_ENCODING);
111 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, stringData);
112 SvcLogicContext ctx = new SvcLogicContext();
113 expectedEx.expect(SvcLogicException.class);
114 expectedEx.expectMessage("Check Data is missing");
115 patternNode.checkDataType(inParams, ctx);
119 public void testCheckDataType() throws Exception {
120 PatternNode patternNode = new PatternNode();
121 Map<String, String> inParams = new HashMap<String, String>();
122 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
123 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, "testData");
124 SvcLogicContext ctx = new SvcLogicContext();
125 patternNode.checkDataType(inParams, ctx);
126 assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));