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