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;
25 import static org.junit.Assert.assertTrue;
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;
33 public class GrpcCarrierTechnologyParametersTest {
35 private static final String USERNAME = "username";
36 private static final String PASSWORD = "password";
37 private static final String HOST = "localhost";
39 private GrpcCarrierTechnologyParameters params;
43 params = new GrpcCarrierTechnologyParameters();
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");
57 public void testGrpcCarrierTechnologyParameters_valid() {
58 assertEquals("GRPC", params.getName());
59 assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
60 assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
63 params.setPassword(PASSWORD);
65 params.setTimeout(1000);
66 params.setUsername(USERNAME);
67 GroupValidationResult result = params.validate();
68 assertTrue(result.isValid());
69 Assertions.assertThatCode(() -> params.validateGrpcParameters(true)).doesNotThrowAnyException();
73 public void testGrpcCarrierTechnologyParameters_invalid_values() {
75 params.setPassword(PASSWORD);
76 params.setTimeout(1000);
77 params.setUsername(USERNAME);
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");