9ce1b214ec09d1c21aa083d936d2722b816ef7db
[policy/models.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023, 2024 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.test;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNotNull;
26 import static org.junit.jupiter.api.Assertions.assertNull;
27 import static org.junit.jupiter.api.Assertions.assertSame;
28
29 import java.util.Map;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.junit.jupiter.api.extension.ExtendWith;
33 import org.junit.runner.RunWith;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.mockito.junit.jupiter.MockitoExtension;
36 import org.onap.policy.common.utils.coder.CoderException;
37 import org.onap.policy.common.utils.resources.ResourceUtils;
38 import org.onap.policy.controlloop.actorserviceprovider.Util;
39
40 @ExtendWith(MockitoExtension.class)
41  class BasicOperationTest {
42     private static final String ACTOR = "my-actor";
43     private static final String OPERATION = "my-operation";
44
45     private BasicOperation oper;
46
47
48     @BeforeEach
49      void setUp() throws Exception {
50         oper = new BasicHttpOperation(ACTOR, OPERATION);
51         oper.setUpBasic();
52     }
53
54     @Test
55      void testBasicHttpOperation() {
56         oper = new BasicHttpOperation();
57         assertEquals(BasicHttpOperation.DEFAULT_ACTOR, oper.actorName);
58         assertEquals(BasicHttpOperation.DEFAULT_OPERATION, oper.operationName);
59     }
60
61     @Test
62      void testBasicHttpOperationStringString() {
63         assertEquals(ACTOR, oper.actorName);
64         assertEquals(OPERATION, oper.operationName);
65     }
66
67     @Test
68      void testSetUp() throws Exception {
69         assertNotNull(oper.future);
70         assertNotNull(oper.outcome);
71         assertNotNull(oper.executor);
72     }
73
74     @Test
75      void testMakeContext() {
76         oper.makeContext();
77
78         assertSame(oper.service, oper.params.getActorService());
79         assertSame(oper.executor, oper.params.getExecutor());
80         assertEquals(ACTOR, oper.params.getActor());
81         assertEquals(OPERATION, oper.params.getOperation());
82         assertSame(BasicHttpOperation.REQ_ID, oper.params.getRequestId());
83     }
84
85     @Test
86      void testMakePayload() {
87         assertNull(oper.makePayload());
88     }
89
90     @Test
91      void testVerifyRequest() throws CoderException {
92         Map<String, Object> map = Util.translateToMap("", ResourceUtils.getResourceAsString("actual.json"));
93         oper.verifyRequest("expected.json", map, "svc-request-id", "vnf-id");
94     }
95 }