Merge "replace test sleep() with awaitality package"
[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.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.common.parameters.GroupValidationResult;
30
31 public class GrpcCarrierTechnologyParametersTest {
32
33     private static final String USERNAME = "username";
34     private static final String PASSWORD = "password";
35     private static final String HOST = "localhost";
36
37     private GrpcCarrierTechnologyParameters params;
38
39     @Before
40     public void setUp() {
41         params = new GrpcCarrierTechnologyParameters();
42     }
43
44     @Test
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"));
50         assertTrue(
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(""));
58     }
59
60     @Test
61     public void testGrpcCarrierTechnologyParameters_valid() {
62         assertEquals("GRPC", params.getName());
63         assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
64         assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
65
66         params.setHost(HOST);
67         params.setPassword(PASSWORD);
68         params.setPort(2233);
69         params.setTimeout(1000);
70         params.setUsername(USERNAME);
71         GroupValidationResult result = params.validate();
72         assertTrue(result.isValid());
73     }
74
75     @Test
76     public void testGrpcCarrierTechnologyParameters_invalid_values() {
77         params.setHost(HOST);
78         params.setPassword(PASSWORD);
79         params.setTimeout(1000);
80         params.setUsername(USERNAME);
81
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"));
86     }
87 }