2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Bell Canada. All rights reserved.
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.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.controlloop.actor.cds;
21 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
22 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.MockitoAnnotations;
30 import org.onap.policy.cds.properties.CdsServerProperties;
31 import org.onap.policy.controlloop.VirtualControlLoopEvent;
32 import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
33 import org.onap.policy.controlloop.actorserviceprovider.Operation;
34 import org.onap.policy.controlloop.actorserviceprovider.Util;
35 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
37 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
39 public class GrpcOperatorTest {
41 GrpcOperator operation;
42 Map<String, Object> paramMap;
43 Map<String, Object> invalidParamMap;
46 * Initializes fields, including {@link #operation}.
50 MockitoAnnotations.initMocks(this);
51 operation = new GrpcOperator(CdsActorConstants.CDS_ACTOR, GrpcOperation.NAME, GrpcOperation::new);
53 CdsServerProperties props = new CdsServerProperties();
54 props.setHost("grpcHost");
56 props.setUsername("grpcUsername");
57 props.setPassword("grpcPassword");
60 paramMap = Util.translateToMap(GrpcOperation.NAME, props);
62 invalidParamMap = Util.translateToMap(GrpcOperation.NAME, props);
66 public void testGrpcOperator() {
67 assertEquals(CdsActorConstants.CDS_ACTOR, operation.getActorName());
68 assertEquals(GrpcOperation.NAME, operation.getName());
69 assertEquals(CdsActorConstants.CDS_ACTOR + "." + GrpcOperation.NAME, operation.getFullName());
74 public void testDoConfigure() {
76 operation.doConfigure(paramMap);
77 assertEquals(30000, operation.getCurrentConfig().getTimeoutMs());
79 // use invalidParamsMap
80 assertThatExceptionOfType(ParameterValidationRuntimeException.class)
81 .isThrownBy(() -> operation.makeConfiguration(invalidParamMap));
85 public void testBuildOperation() {
86 VirtualControlLoopEvent event = new VirtualControlLoopEvent();
87 ControlLoopEventContext context = new ControlLoopEventContext(event);
88 ControlLoopOperationParams params = ControlLoopOperationParams.builder().actor(CdsActorConstants.CDS_ACTOR)
89 .operation(GrpcOperation.NAME).context(context).build();
92 assertThatIllegalStateException().isThrownBy(() -> operation.buildOperation(params));
94 operation.configure(paramMap);
97 assertThatIllegalStateException().isThrownBy(() -> operation.buildOperation(params));
100 Operation operation1 = operation.buildOperation(params);
101 assertEquals(GrpcOperation.NAME, operation1.getName());
103 // with no operation-maker
104 GrpcOperator oper2 = new GrpcOperator(CdsActorConstants.CDS_ACTOR, GrpcOperation.NAME);
105 assertThatThrownBy(() -> oper2.buildOperation(params)).isInstanceOf(UnsupportedOperationException.class);