2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.generator.pattern;
26 import static org.junit.Assert.assertEquals;
27 import java.util.HashMap;
29 import org.apache.commons.io.IOUtils;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
34 public class TestPatternNode {
37 public void parseErrorLog() throws Exception {
38 PatternNode patternNode = new PatternNode();
39 Map<String, String> inParams = new HashMap<String, String>();
40 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
41 String logData = IOUtils.toString(
42 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/errorlog.txt"),
43 ConfigGeneratorConstant.STRING_ENCODING);
44 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_LOG_DATA, logData);
45 SvcLogicContext ctx = new SvcLogicContext();
46 patternNode.parseErrorLog(inParams, ctx);
47 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
48 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
52 // @Test(expected=Exception.class)
53 public void checkXMLData() throws Exception {
54 PatternNode patternNode = new PatternNode();
55 Map<String, String> inParams = new HashMap<String, String>();
56 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
58 String xmlData = IOUtils.toString(
59 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/xml_data.xml"),
60 ConfigGeneratorConstant.STRING_ENCODING);
61 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, xmlData);
62 SvcLogicContext ctx = new SvcLogicContext();
63 patternNode.checkDataType(inParams, ctx);
64 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
65 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
69 public void checkJsonData() throws Exception {
70 PatternNode patternNode = new PatternNode();
71 Map<String, String> inParams = new HashMap<String, String>();
72 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
74 IOUtils.toString(TestPatternNode.class.getClassLoader().getResourceAsStream(
75 "pattern/json_data.json"), ConfigGeneratorConstant.STRING_ENCODING);
76 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, xmlData);
77 SvcLogicContext ctx = new SvcLogicContext();
78 patternNode.checkDataType(inParams, ctx);
79 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
80 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);
83 @Test(expected = Exception.class)
84 public void checStringData() throws Exception {
85 PatternNode patternNode = new PatternNode();
86 Map<String, String> inParams = new HashMap<String, String>();
87 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
88 String stringData = IOUtils.toString(
89 TestPatternNode.class.getClassLoader().getResourceAsStream("pattern/text_data.txt"),
90 ConfigGeneratorConstant.STRING_ENCODING);
91 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_CHECK_DATA, stringData);
92 SvcLogicContext ctx = new SvcLogicContext();
93 patternNode.checkDataType(inParams, ctx);
94 assertEquals(ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS),
95 ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS);