Convert models to JUnit 5
[policy/models.git] / models-interactions / model-actors / actor.a1p / src / test / java / org / onap / policy / controlloop / actor / a1p / A1pOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2022 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.a1p;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertNotNull;
27 import static org.junit.jupiter.api.Assertions.assertSame;
28
29 import java.util.List;
30 import org.junit.jupiter.api.AfterAll;
31 import org.junit.jupiter.api.AfterEach;
32 import org.junit.jupiter.api.BeforeAll;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.junit.jupiter.api.extension.ExtendWith;
36 import org.mockito.junit.jupiter.MockitoExtension;
37 import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
38 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
39 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
40 import org.onap.policy.sdnr.util.StatusCodeEnum;
41
42 @ExtendWith(MockitoExtension.class)
43  class A1pOperationTest extends BasicA1pOperation {
44
45     private A1pOperation operation;
46
47     @BeforeAll
48      static void setUpBeforeClass() throws Exception {
49         BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
50     }
51
52     @AfterAll
53      static void tearDownAfterClass() {
54         destroyAfterClass();
55     }
56
57     /**
58      * Setup.
59      */
60     @BeforeEach
61     @Override
62      void setUp() throws Exception {
63         super.setUp();
64
65         operation = new A1pOperation(params, config);
66         operation.setProperty(OperationProperties.EVENT_PAYLOAD, "my payload");
67     }
68
69     @AfterEach
70     @Override
71      void tearDown() {
72         super.tearDown();
73     }
74
75     @Test
76      void testA1pOperation() {
77         assertEquals(DEFAULT_ACTOR, operation.getActorName());
78         assertEquals(DEFAULT_OPERATION, operation.getName());
79     }
80
81     @Test
82      void testGetPropertyNames() {
83         assertThat(operation.getPropertyNames()).isEqualTo(List.of(OperationProperties.EVENT_PAYLOAD));
84     }
85
86     @Test
87      void testSetOutcome() {
88         // with a status value
89         checkOutcome();
90         assertEquals(StatusCodeEnum.SUCCESS.toString(), outcome.getMessage());
91
92         // null status value
93         response.getBody().getOutput().getStatus().setValue(null);
94         checkOutcome();
95
96         // null status
97         response.getBody().getOutput().setStatus(null);
98         checkOutcome();
99
100         // null output
101         response.getBody().setOutput(null);
102         checkOutcome();
103
104         // null body
105         response.setBody(null);
106         checkOutcome();
107     }
108
109     protected void checkOutcome() {
110         assertSame(outcome, operation.setOutcome(outcome, OperationResult.SUCCESS, response));
111         assertEquals(OperationResult.SUCCESS, outcome.getResult());
112         assertNotNull(outcome.getMessage());
113         assertSame(response, outcome.getResponse());
114     }
115 }