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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.plugins.event.carrier.grpc;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
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;
34 public class GrpcCarrierTechnologyParametersTest {
36 private static final String USERNAME = "username";
37 private static final String PASSWORD = "password";
38 private static final String HOST = "localhost";
40 private GrpcCarrierTechnologyParameters params;
44 params = new GrpcCarrierTechnologyParameters();
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");
58 public void testGrpcCarrierTechnologyParameters_valid() {
59 assertEquals("GRPC", params.getName());
60 assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
61 assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
64 params.setPassword(PASSWORD);
66 params.setTimeout(1000);
67 params.setUsername(USERNAME);
68 ValidationResult result = params.validate();
69 assertTrue(result.isValid());
70 Assertions.assertThatCode(() -> params.validateGrpcParameters(true)).doesNotThrowAnyException();
74 public void testGrpcCarrierTechnologyParameters_invalid_values() {
76 params.setPassword(PASSWORD);
77 params.setTimeout(1000);
78 params.setUsername(USERNAME);
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");