added test cases to TestXSLTTransformerNode.java
[appc.git] / appc-config / appc-config-generator / provider / src / test / java / org / onap / sdnc / config / generator / transform / TestXSLTTransformerNode.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.transform;
27
28 import java.nio.charset.Charset;
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 import org.onap.sdnc.config.generator.merge.TestMergeNode;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
39
40 public class TestXSLTTransformerNode {
41
42     private static final EELFLogger log =
43             EELFManager.getInstance().getLogger(TestXSLTTransformerNode.class);
44
45     @Test
46     public void transformData() throws Exception {
47         SvcLogicContext ctx = new SvcLogicContext();
48         String templateData = IOUtils.toString(
49                 TestMergeNode.class.getClassLoader().getResourceAsStream("transform/template.xsl"),
50                 Charset.defaultCharset());
51         String requestData = IOUtils.toString(
52                 TestMergeNode.class.getClassLoader().getResourceAsStream("transform/request.xml"),
53                 Charset.defaultCharset());
54         Map<String, String> inParams = new HashMap<String, String>();
55         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
56         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA, requestData);
57         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
58         transformerNode.transformData(inParams, ctx);
59         log.info("transformData Result: "
60                 + ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_TRANSFORMED_DATA));
61
62     }
63     @Test(expected=SvcLogicException.class)
64     public void testTransformDataForEmptyTemplateData() throws Exception {
65         SvcLogicContext ctx = new SvcLogicContext();
66         Map<String, String> inParams = new HashMap<String, String>();
67         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA, "testRequestData");
68         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
69         transformerNode.transformData(inParams, ctx);
70     }
71     @Test(expected=SvcLogicException.class)
72     public void testTransformDataForEmptyRequestData() throws Exception {
73         SvcLogicContext ctx = new SvcLogicContext();
74         Map<String, String> inParams = new HashMap<String, String>();
75         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
76         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, "testTemplateData");
77         transformerNode.transformData(inParams, ctx);
78    }
79 }