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 Ericsson
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.reader;
28 import static org.junit.Assert.assertEquals;
29 import java.io.IOException;
30 import java.util.HashMap;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37 import org.onap.sdnc.config.generator.ConfigGeneratorConstant;
39 public class TestReaderNode {
42 public ExpectedException expectedEx = ExpectedException.none();
45 public void testGetFileDataSuccess() throws SvcLogicException, IOException {
46 ReaderNode r = new ReaderNode();
47 Map<String, String> inParams = new HashMap<String, String>();
48 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "test");
49 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME,
50 "src/test/resources/convert/payload_cli_config.json");
51 SvcLogicContext ctx = new SvcLogicContext();
52 r.getFileData(inParams, ctx);
53 assertEquals(ConfigGeneratorConstant.OUTPUT_STATUS_SUCCESS,
54 ctx.getAttribute("test." + ConfigGeneratorConstant.OUTPUT_PARAM_STATUS));
58 public void testGetFileDataFailure() throws SvcLogicException, IOException {
59 ReaderNode r = new ReaderNode();
60 Map<String, String> inParams = new HashMap<String, String>();
61 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_RESPONSE_PRIFIX, "");
62 inParams.put(ConfigGeneratorConstant.INPUT_PARAM_FILE_NAME,
63 "non_existent_filename");
64 SvcLogicContext ctx = new SvcLogicContext();
65 expectedEx.expect(SvcLogicException.class);
66 expectedEx.expectMessage("File 'non_existent_filename' does not exist");
67 r.getFileData(inParams, ctx);