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