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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.GroupValidationResult;
31 public class GrpcCarrierTechnologyParametersTest {
33 private static final String USERNAME = "username";
34 private static final String PASSWORD = "password";
35 private static final String HOST = "localhost";
37 private GrpcCarrierTechnologyParameters params;
41 params = new GrpcCarrierTechnologyParameters();
45 public void testGrpcCarrierTechnologyParameters_invalid() {
46 GroupValidationResult result = params.validate();
47 assertFalse(result.isValid());
48 assertTrue(result.getResult().contains("field \"timeout\" type \"int\" value \"0\" INVALID, must be >= 1"));
49 assertTrue(result.getResult().contains("field \"port\" type \"int\" value \"0\" INVALID, must be >= 1024"));
51 result.getResult().contains("field \"host\" type \"java.lang.String\" value \"null\" INVALID, is null"));
52 assertTrue(result.getResult()
53 .contains("field \"username\" type \"java.lang.String\" value \"null\" INVALID, is null"));
54 assertTrue(result.getResult()
55 .contains("field \"password\" type \"java.lang.String\" value \"null\" INVALID, is null"));
56 assertTrue(result.getResult().contains(""));
57 assertTrue(result.getResult().contains(""));
61 public void testGrpcCarrierTechnologyParameters_valid() {
62 assertEquals("GRPC", params.getName());
63 assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
64 assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
67 params.setPassword(PASSWORD);
69 params.setTimeout(1000);
70 params.setUsername(USERNAME);
71 GroupValidationResult result = params.validate();
72 assertTrue(result.isValid());
76 public void testGrpcCarrierTechnologyParameters_invalid_values() {
78 params.setPassword(PASSWORD);
79 params.setTimeout(1000);
80 params.setUsername(USERNAME);
82 params.setPort(23); // invalid value
83 GroupValidationResult result = params.validate();
84 assertFalse(result.isValid());
85 assertTrue(result.getResult().contains("field \"port\" type \"int\" value \"23\" INVALID, must be >= 1024"));