dc5cc3809e9e1f97d892dc3e30ed86618b4f6c87
[policy/apex-pdp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.plugins.event.carrier.grpc;
22
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25
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;
32
33 public class ApexGrpcConsumerTest {
34     ApexGrpcConsumer grpcConsumer = null;
35     EventHandlerParameters consumerParameters = null;
36     ApexEventReceiver incomingEventReceiver = null;
37
38     private static final String GRPC_CONSUMER_ERROR_MSG =
39         "A gRPC Consumer may not be specified. Only sending events is possible using gRPC";
40
41     /**
42      * Set up testing.
43      *
44      * @throws ApexEventException on test set up errors.
45      */
46     @Before
47     public void setUp() throws ApexEventException {
48         grpcConsumer = new ApexGrpcConsumer();
49         consumerParameters = new EventHandlerParameters();
50         consumerParameters.setCarrierTechnologyParameters(new GrpcCarrierTechnologyParameters() {});
51     }
52
53     @Test
54     public void testInit() {
55         assertThatThrownBy(() -> {
56             grpcConsumer.init("TestApexGrpcConsumer", consumerParameters, incomingEventReceiver);
57         }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
58     }
59
60     @Test
61     public void testStart() {
62         assertThatThrownBy(() -> {
63             grpcConsumer.start();
64         }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
65     }
66
67     @Test
68     public void testGetName() {
69         assertEquals(null, new ApexGrpcConsumer().getName());
70     }
71
72     @Test
73     public void testGetPeeredReference() {
74         assertThatThrownBy(() -> {
75             grpcConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
76         }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
77     }
78
79     @Test
80     public void testSetPeeredReference() {
81         assertThatThrownBy(() -> {
82             grpcConsumer.setPeeredReference(null, null);
83         }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
84     }
85
86     @Test()
87     public void testStop() {
88         assertThatThrownBy(() -> {
89             new ApexGrpcConsumer().stop();
90         }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
91     }
92
93 }