2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertSame;
27 import static org.junit.Assert.assertTrue;
30 import java.util.concurrent.CompletableFuture;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.aai.AaiCqResponse;
34 import org.onap.policy.common.utils.coder.CoderException;
35 import org.onap.policy.common.utils.resources.ResourceUtils;
36 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
37 import org.onap.policy.controlloop.actorserviceprovider.Util;
38 import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
39 import org.onap.policy.controlloop.policy.PolicyResult;
41 public class BasicOperationTest {
42 private static final String ACTOR = "my-actor";
43 private static final String OPERATION = "my-operation";
45 private BasicOperation oper;
49 public void setUp() throws Exception {
50 oper = new BasicHttpOperation<>(ACTOR, OPERATION);
55 public void testBasicHttpOperation() {
56 oper = new BasicHttpOperation<>();
57 assertEquals(BasicHttpOperation.DEFAULT_ACTOR, oper.actorName);
58 assertEquals(BasicHttpOperation.DEFAULT_OPERATION, oper.operationName);
62 public void testBasicHttpOperationStringString() {
63 assertEquals(ACTOR, oper.actorName);
64 assertEquals(OPERATION, oper.operationName);
68 public void testSetUp() throws Exception {
69 assertNotNull(oper.future);
70 assertNotNull(oper.context);
71 assertNotNull(oper.outcome);
72 assertNotNull(oper.executor);
73 assertNotNull(oper.guardOperation);
75 CompletableFuture<OperationOutcome> future = oper.service.getActor(OperationPartial.GUARD_ACTOR_NAME)
76 .getOperator(OperationPartial.GUARD_OPERATION_NAME).buildOperation(null).start();
77 assertTrue(future.isDone());
78 assertEquals(PolicyResult.SUCCESS, future.get().getResult());
82 public void testMakeContext() {
85 assertTrue(oper.enrichment.isEmpty());
87 assertSame(BasicHttpOperation.REQ_ID, oper.event.getRequestId());
88 assertSame(oper.enrichment, oper.event.getAai());
90 assertSame(oper.event, oper.context.getEvent());
92 assertSame(oper.context, oper.params.getContext());
93 assertSame(oper.service, oper.params.getActorService());
94 assertSame(oper.executor, oper.params.getExecutor());
95 assertEquals(ACTOR, oper.params.getActor());
96 assertEquals(OPERATION, oper.params.getOperation());
97 assertEquals(BasicHttpOperation.TARGET_ENTITY, oper.params.getTargetEntity());
101 public void testMakeEnrichment_testMakePayload() {
102 assertTrue(oper.makeEnrichment().isEmpty());
103 assertNull(oper.makePayload());
107 public void testVerifyRequest() throws CoderException {
108 Map<String, Object> map = Util.translateToMap("", ResourceUtils.getResourceAsString("actual.json"));
109 oper.verifyRequest("expected.json", map, "svc-request-id", "vnf-id");
113 public void testProvideCqResponse() throws Exception {
114 AaiCqResponse cq = new AaiCqResponse("{}");
115 oper.provideCqResponse(cq);
117 assertSame(cq, oper.context.getProperty(AaiCqResponse.CONTEXT_KEY));
118 assertTrue(oper.cqFuture.isDone());
119 assertEquals(PolicyResult.SUCCESS, oper.cqFuture.get().getResult());