480d8423b1358d0e1e23b5b19086be35e096a8ad
[policy/apex-pdp.git] / plugins / plugins-event / plugins-event-carrier / plugins-event-carrier-grpc / src / test / java / org / onap / policy / apex / plugins / event / carrier / grpc / GrpcCarrierTechnologyParametersTest.java
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 import static org.junit.Assert.assertTrue;
26
27 import org.assertj.core.api.Assertions;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.apex.service.engine.event.ApexEventException;
31 import org.onap.policy.common.parameters.GroupValidationResult;
32
33 public class GrpcCarrierTechnologyParametersTest {
34
35     private static final String USERNAME = "username";
36     private static final String PASSWORD = "password";
37     private static final String HOST = "localhost";
38
39     private GrpcCarrierTechnologyParameters params;
40
41     @Before
42     public void setUp() {
43         params = new GrpcCarrierTechnologyParameters();
44     }
45
46     @Test
47     public void testGrpcCarrierTechnologyParameters_invalid_producer_params() throws ApexEventException {
48         GroupValidationResult result = params.validate();
49         assertTrue(result.isValid());
50         assertThatThrownBy(() -> params.validateGrpcParameters(true))
51             .hasMessage("Issues in specifying gRPC Producer parameters:\ntimeout should have a positive value.\n"
52                 + "port range should be between 1024 and 65535\n" + "host should be specified.\n"
53                 + "username should be specified.\n" + "password should be specified.\n");
54     }
55
56     @Test
57     public void testGrpcCarrierTechnologyParameters_valid() {
58         assertEquals("GRPC", params.getName());
59         assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
60         assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
61
62         params.setHost(HOST);
63         params.setPassword(PASSWORD);
64         params.setPort(2233);
65         params.setTimeout(1000);
66         params.setUsername(USERNAME);
67         GroupValidationResult result = params.validate();
68         assertTrue(result.isValid());
69         Assertions.assertThatCode(() -> params.validateGrpcParameters(true)).doesNotThrowAnyException();
70     }
71
72     @Test
73     public void testGrpcCarrierTechnologyParameters_invalid_values() {
74         params.setHost(HOST);
75         params.setPassword(PASSWORD);
76         params.setTimeout(1000);
77         params.setUsername(USERNAME);
78
79         params.setPort(23); // invalid value
80         GroupValidationResult result = params.validate();
81         assertTrue(result.isValid());
82         assertThatThrownBy(() -> params.validateGrpcParameters(true))
83             .hasMessageContaining("port range should be between 1024 and 65535");
84     }
85 }