7c79e95b64218e1ee9cc7fbe5d5dca102cd170fd
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.plugins.event.carrier.grpc;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import org.assertj.core.api.Assertions;
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.common.parameters.ValidationResult;
33
34 public class GrpcCarrierTechnologyParametersTest {
35
36     private static final String USERNAME = "username";
37     private static final String PASSWORD = "password";
38     private static final String HOST = "localhost";
39
40     private GrpcCarrierTechnologyParameters params;
41
42     @Before
43     public void setUp() {
44         params = new GrpcCarrierTechnologyParameters();
45     }
46
47     @Test
48     public void testGrpcCarrierTechnologyParameters_invalid_producer_params() throws ApexEventException {
49         ValidationResult result = params.validate();
50         assertTrue(result.isValid());
51         assertThatThrownBy(() -> params.validateGrpcParameters(true))
52             .hasMessage("Issues in specifying gRPC Producer parameters:\ntimeout should have a positive value.\n"
53                 + "port range should be between 1024 and 65535\n" + "host should be specified.\n"
54                 + "username should be specified.\n" + "password should be specified.\n");
55     }
56
57     @Test
58     public void testGrpcCarrierTechnologyParameters_valid() {
59         assertEquals("GRPC", params.getName());
60         assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
61         assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
62
63         params.setHost(HOST);
64         params.setPassword(PASSWORD);
65         params.setPort(2233);
66         params.setTimeout(1000);
67         params.setUsername(USERNAME);
68         ValidationResult result = params.validate();
69         assertTrue(result.isValid());
70         Assertions.assertThatCode(() -> params.validateGrpcParameters(true)).doesNotThrowAnyException();
71     }
72
73     @Test
74     public void testGrpcCarrierTechnologyParameters_invalid_values() {
75         params.setHost(HOST);
76         params.setPassword(PASSWORD);
77         params.setTimeout(1000);
78         params.setUsername(USERNAME);
79
80         params.setPort(23); // invalid value
81         ValidationResult result = params.validate();
82         assertTrue(result.isValid());
83         assertThatThrownBy(() -> params.validateGrpcParameters(true))
84             .hasMessageContaining("port range should be between 1024 and 65535");
85     }
86 }