added test case to TestPatternNode.java
[appc.git] / appc-config / appc-config-generator / provider / src / test / java / org / onap / sdnc / config / generator / pattern / TestPatternNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
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.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.sdnc.config.generator.pattern;
27
28 import static org.junit.Assert.assertEquals;
29 import java.util.HashMap;
30 import java.util.Map;
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;
35
36 public class TestPatternNode {
37
38     @Test
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);
51
52     }
53
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");
59
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);
68     }
69
70     // @Test
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");
75         String xmlData =
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);
83     }
84
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);
98     }
99     
100     @Test
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));
109     }
110 }