More actor clean-up
[policy/models.git] / models-interactions / model-actors / actor.test / src / test / java / org / onap / policy / controlloop / actor / test / BasicOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.test;
22
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;
28
29 import java.util.Map;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.common.utils.coder.CoderException;
33 import org.onap.policy.common.utils.resources.ResourceUtils;
34 import org.onap.policy.controlloop.actorserviceprovider.Util;
35
36 public class BasicOperationTest {
37     private static final String ACTOR = "my-actor";
38     private static final String OPERATION = "my-operation";
39
40     private BasicOperation oper;
41
42
43     @Before
44     public void setUp() throws Exception {
45         oper = new BasicHttpOperation<>(ACTOR, OPERATION);
46         oper.setUpBasic();
47     }
48
49     @Test
50     public void testBasicHttpOperation() {
51         oper = new BasicHttpOperation<>();
52         assertEquals(BasicHttpOperation.DEFAULT_ACTOR, oper.actorName);
53         assertEquals(BasicHttpOperation.DEFAULT_OPERATION, oper.operationName);
54     }
55
56     @Test
57     public void testBasicHttpOperationStringString() {
58         assertEquals(ACTOR, oper.actorName);
59         assertEquals(OPERATION, oper.operationName);
60     }
61
62     @Test
63     public void testSetUp() throws Exception {
64         assertNotNull(oper.future);
65         assertNotNull(oper.context);
66         assertNotNull(oper.outcome);
67         assertNotNull(oper.executor);
68     }
69
70     @Test
71     public void testMakeContext() {
72         oper.makeContext();
73
74         assertTrue(oper.enrichment.isEmpty());
75
76         assertSame(BasicHttpOperation.REQ_ID, oper.event.getRequestId());
77         assertSame(oper.enrichment, oper.event.getAai());
78
79         assertSame(oper.event, oper.context.getEvent());
80
81         assertSame(oper.context, oper.params.getContext());
82         assertSame(oper.service, oper.params.getActorService());
83         assertSame(oper.executor, oper.params.getExecutor());
84         assertEquals(ACTOR, oper.params.getActor());
85         assertEquals(OPERATION, oper.params.getOperation());
86         assertEquals(BasicHttpOperation.TARGET_ENTITY, oper.params.getTargetEntity());
87     }
88
89     @Test
90     public void testMakeEnrichment_testMakePayload() {
91         assertTrue(oper.makeEnrichment().isEmpty());
92         assertNull(oper.makePayload());
93     }
94
95     @Test
96     public void testVerifyRequest() throws CoderException {
97         Map<String, Object> map = Util.translateToMap("", ResourceUtils.getResourceAsString("actual.json"));
98         oper.verifyRequest("expected.json", map, "svc-request-id", "vnf-id");
99     }
100 }