Changed to unmaintained
[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  * 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
16  * 
17  *      http://www.apache.org/licenses/LICENSE-2.0
18  * 
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.
24  * 
25  * ============LICENSE_END=========================================================
26  */
27
28 package org.onap.sdnc.config.generator.transform;
29
30 import static org.junit.Assert.assertEquals;
31 import java.nio.charset.Charset;
32 import java.util.HashMap;
33 import java.util.Map;
34 import org.apache.commons.io.IOUtils;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
40 import org.onap.sdnc.config.generator.merge.TestMergeNode;
41 import com.att.eelf.configuration.EELFLogger;
42 import com.att.eelf.configuration.EELFManager;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
44
45 public class TestXSLTTransformerNode {
46
47     private static final EELFLogger log =
48             EELFManager.getInstance().getLogger(TestXSLTTransformerNode.class);
49
50     @Rule
51     public ExpectedException expectedEx = ExpectedException.none();
52
53     @Test
54     public void transformData() throws Exception {
55         SvcLogicContext ctx = new SvcLogicContext();
56         String templateData = IOUtils.toString(
57                 TestMergeNode.class.getClassLoader().getResourceAsStream("transform/template.xsl"),
58                 Charset.defaultCharset());
59         String requestData = IOUtils.toString(
60                 TestMergeNode.class.getClassLoader().getResourceAsStream("transform/request.xml"),
61                 Charset.defaultCharset());
62         Map<String, String> inParams = new HashMap<String, String>();
63         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, templateData);
64         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA, requestData);
65         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
66         transformerNode.transformData(inParams, ctx);
67         assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
68                 ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
69         log.info("transformData Result: "
70                 + ctx.getAttribute(ConfigGeneratorConstant.OUTPUT_PARAM_TRANSFORMED_DATA));
71
72     }
73
74     @Test
75     public void testTransformDataForEmptyTemplateData() throws Exception {
76         SvcLogicContext ctx = new SvcLogicContext();
77         Map<String, String> inParams = new HashMap<String, String>();
78         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_REQUEST_DATA, "testRequestData");
79         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
80         expectedEx.expect(SvcLogicException.class);
81         expectedEx.expectMessage("In-param templateFile/templateData value is missing");
82         transformerNode.transformData(inParams, ctx);
83     }
84
85     @Test
86     public void testTransformDataForEmptyRequestData() throws Exception {
87         SvcLogicContext ctx = new SvcLogicContext();
88         Map<String, String> inParams = new HashMap<String, String>();
89         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
90         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, "testTemplateData");
91         expectedEx.expect(SvcLogicException.class);
92         expectedEx.expectMessage("In-param requestData value is missing");
93         transformerNode.transformData(inParams, ctx);
94    }
95
96     @Test
97     public void testTransformDataForEmptyRequestTemplate() throws Exception {
98         SvcLogicContext ctx = new SvcLogicContext();
99         Map<String, String> inParams = new HashMap<String, String>();
100         XSLTTransformerNode transformerNode = new XSLTTransformerNode();
101         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, "testTemplateData");
102         inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "NO_SUCH_FILE.json");
103         expectedEx.expect(SvcLogicException.class);
104         expectedEx.expectMessage("File 'NO_SUCH_FILE.json' does not exist");
105         transformerNode.transformData(inParams, ctx);
106    }
107 }