758acf75e3f3fc4f15debeee0d596da26b87a914
[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
28 import java.util.Map;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.common.utils.coder.CoderException;
32 import org.onap.policy.common.utils.resources.ResourceUtils;
33 import org.onap.policy.controlloop.actorserviceprovider.Util;
34
35 public class BasicOperationTest {
36     private static final String ACTOR = "my-actor";
37     private static final String OPERATION = "my-operation";
38
39     private BasicOperation oper;
40
41
42     @Before
43     public void setUp() throws Exception {
44         oper = new BasicHttpOperation(ACTOR, OPERATION);
45         oper.setUpBasic();
46     }
47
48     @Test
49     public void testBasicHttpOperation() {
50         oper = new BasicHttpOperation();
51         assertEquals(BasicHttpOperation.DEFAULT_ACTOR, oper.actorName);
52         assertEquals(BasicHttpOperation.DEFAULT_OPERATION, oper.operationName);
53     }
54
55     @Test
56     public void testBasicHttpOperationStringString() {
57         assertEquals(ACTOR, oper.actorName);
58         assertEquals(OPERATION, oper.operationName);
59     }
60
61     @Test
62     public void testSetUp() throws Exception {
63         assertNotNull(oper.future);
64         assertNotNull(oper.outcome);
65         assertNotNull(oper.executor);
66     }
67
68     @Test
69     public void testMakeContext() {
70         oper.makeContext();
71
72         assertSame(oper.service, oper.params.getActorService());
73         assertSame(oper.executor, oper.params.getExecutor());
74         assertEquals(ACTOR, oper.params.getActor());
75         assertEquals(OPERATION, oper.params.getOperation());
76         assertSame(BasicHttpOperation.REQ_ID, oper.params.getRequestId());
77     }
78
79     @Test
80     public void testMakePayload() {
81         assertNull(oper.makePayload());
82     }
83
84     @Test
85     public void testVerifyRequest() throws CoderException {
86         Map<String, Object> map = Util.translateToMap("", ResourceUtils.getResourceAsString("actual.json"));
87         oper.verifyRequest("expected.json", map, "svc-request-id", "vnf-id");
88     }
89 }