2 * ============LICENSE_START=======================================================
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 * 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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.generator.transform;
28 import java.nio.charset.Charset;
29 import java.util.HashMap;
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;
40 public class TestXSLTTransformerNode {
42 private static final EELFLogger log =
43 EELFManager.getInstance().getLogger(TestXSLTTransformerNode.class);
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));
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);
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);
80 @Test(expected=SvcLogicException.class)
81 public void testTransformDataForEmptyRequestTemplate() throws Exception {
82 SvcLogicContext ctx = new SvcLogicContext();
83 Map<String, String> inParams = new HashMap<String, String>();
84 XSLTTransformerNode transformerNode = new XSLTTransformerNode();
85 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_DATA, "testTemplateData");
86 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_TEMPLATE_FILE, "NO_SUCH_FILE.json");
87 transformerNode.transformData(inParams, ctx);