2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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.plugins.event.carrier.grpc;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.apex.service.engine.event.ApexEventException;
29 import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
30 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
31 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
33 public class ApexGrpcConsumerTest {
34 ApexGrpcConsumer grpcConsumer = null;
35 EventHandlerParameters consumerParameters = null;
36 ApexEventReceiver incomingEventReceiver = null;
38 private static final String GRPC_CONSUMER_ERROR_MSG =
39 "A gRPC Consumer may not be specified. Only sending events is possible using gRPC";
44 * @throws ApexEventException on test set up errors.
47 public void setUp() throws ApexEventException {
48 grpcConsumer = new ApexGrpcConsumer();
49 consumerParameters = new EventHandlerParameters();
50 consumerParameters.setCarrierTechnologyParameters(new GrpcCarrierTechnologyParameters() {});
54 public void testInit() {
55 assertThatThrownBy(() -> {
56 grpcConsumer.init("TestApexGrpcConsumer", consumerParameters, incomingEventReceiver);
57 }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
61 public void testStart() {
62 assertThatThrownBy(() -> {
64 }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
68 public void testGetName() {
69 assertEquals(null, new ApexGrpcConsumer().getName());
73 public void testGetPeeredReference() {
74 assertThatThrownBy(() -> {
75 grpcConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
76 }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
80 public void testSetPeeredReference() {
81 assertThatThrownBy(() -> {
82 grpcConsumer.setPeeredReference(null, null);
83 }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
87 public void testStop() {
88 assertThatThrownBy(() -> {
89 new ApexGrpcConsumer().stop();
90 }).hasMessage(GRPC_CONSUMER_ERROR_MSG);