2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021. Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
28 import org.apache.commons.lang3.RandomStringUtils;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.apex.service.engine.event.ApexEventException;
32 import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.FileCarrierTechnologyParameters;
33 import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
34 import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters;
35 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
36 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
37 import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolTextTokenDelimitedParameters;
39 public class ApexFileEventConsumerTest {
40 private ApexFileEventConsumer consumer;
41 private EventHandlerParameters handlerParameters;
42 private File tempFile;
47 * @throws Exception while file cannot be created
50 public void setUp() throws Exception {
51 consumer = new ApexFileEventConsumer();
52 handlerParameters = new EventHandlerParameters();
53 tempFile = File.createTempFile("afec", ".tmp");
54 tempFile.deleteOnExit();
58 public void initNoConsumerParameters() {
59 final String name = RandomStringUtils.randomAlphanumeric(4);
60 assertThatThrownBy(() -> consumer.init(name, null, null))
61 .isInstanceOf(ApexEventException.class);
65 public void initWrongCarrier() {
66 final String name = RandomStringUtils.randomAlphanumeric(4);
67 final CarrierTechnologyParameters technologyParameters = new SuperDooperCarrierTechnologyParameters();
68 handlerParameters.setCarrierTechnologyParameters(technologyParameters);
70 assertThatThrownBy(() -> consumer.init(name, handlerParameters, null))
71 .isInstanceOf(ApexEventException.class);
75 public void initWithoutReceiver() {
76 final String name = RandomStringUtils.randomAlphanumeric(4);
77 final EventHandlerParameters handlerParameters = new EventHandlerParameters();
78 final FileCarrierTechnologyParameters technologyParameters = new FileCarrierTechnologyParameters();
79 technologyParameters.setFileName(tempFile.getAbsolutePath());
80 final EventProtocolTextTokenDelimitedParameters params = new SuperTokenDelimitedEventProtocolParameters();
82 handlerParameters.setCarrierTechnologyParameters(technologyParameters);
83 handlerParameters.setEventProtocolParameters(params);
85 assertThatCode(() -> consumer.init(name, handlerParameters, null))
86 .doesNotThrowAnyException();
90 public void getName() throws ApexEventException {
91 final String name = RandomStringUtils.randomAlphabetic(5);
92 final EventHandlerParameters handlerParameters = new EventHandlerParameters();
93 final FileCarrierTechnologyParameters technologyParameters = new FileCarrierTechnologyParameters();
94 technologyParameters.setFileName(tempFile.getAbsolutePath());
95 final EventProtocolTextTokenDelimitedParameters params = new SuperTokenDelimitedEventProtocolParameters();
97 handlerParameters.setCarrierTechnologyParameters(technologyParameters);
98 handlerParameters.setEventProtocolParameters(params);
100 consumer.init(name, handlerParameters, null);
101 assertThat(consumer.getName()).isEqualTo(name);