2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
21 import com.fasterxml.jackson.core.JsonProcessingException;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPCMVESMsgConsumer;
26 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException;
29 import java.io.IOException;
30 import java.net.URISyntaxException;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
33 import static org.junit.Assert.fail;
35 public class TestDMaaPCMVESMsgConsumer {
37 private static final String CONFIGURATION_FILE = "cm_test.properties";
38 private DMaaPCMVESMsgConsumer dMaaPCMVESMsgConsumer;
39 private GeneralConfigForTest generalConfigForTest;
42 public void setUp() throws Exception {
43 generalConfigForTest = new GeneralConfigForTest(CONFIGURATION_FILE);
44 dMaaPCMVESMsgConsumer = new DMaaPCMVESMsgConsumer(generalConfigForTest.getCfg());
48 public void processValidMsg() throws URISyntaxException, IOException {
49 File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI());
50 String cmEvent = readFileToString(cmFileValid);
52 dMaaPCMVESMsgConsumer.processMsg(cmEvent);
53 } catch (Exception e) {
54 fail("Test fail with message: " + e.getMessage());
58 @Test(expected = InvalidMessageException.class)
59 public void processMsgThatMissesField() throws URISyntaxException, IOException, InvalidMessageException {
60 File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_invalid.json").toURI());
61 String cmEvent = readFileToString(cmFileInvalid);
62 dMaaPCMVESMsgConsumer.processMsg(cmEvent);
65 @Test(expected = JsonProcessingException.class)
66 public void processMsgThatIsNotValidJson() throws URISyntaxException, IOException, InvalidMessageException {
67 File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/not_a_json.json").toURI());
68 String cmEvent = readFileToString(cmFileInvalid);
69 dMaaPCMVESMsgConsumer.processMsg(cmEvent);
72 private String readFileToString(File file) throws IOException {
73 StringBuilder fileContent = new StringBuilder();
74 Files.lines(Paths.get(file.toURI())).forEach(fileContent::append);
75 return fileContent.toString();
80 generalConfigForTest.close();