Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.sdnc / src / test / java / org / onap / policy / controlloop / actor / sdnc / SdncOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 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.sdnc;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.Collections;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.junit.MockitoJUnitRunner;
33 import org.onap.policy.sdnc.SdncHealRequest;
34 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
35 import org.onap.policy.sdnc.SdncRequest;
36
37 @RunWith(MockitoJUnitRunner.class)
38 public class SdncOperationTest extends BasicSdncOperation {
39
40     private static final String MY_URI = "my-uri";
41
42     private SdncRequest request;
43     private SdncOperation oper;
44
45     /**
46      * Sets up.
47      */
48     @Override
49     @Before
50     public void setUp() throws Exception {
51         super.setUp();
52
53         request = new SdncRequest();
54         request.setUrl(MY_URI);
55
56         SdncHealRequest healRequest = new SdncHealRequest();
57         request.setHealRequest(healRequest);
58
59         SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
60         healRequest.setRequestHeaderInfo(headerInfo);
61         headerInfo.setSvcRequestId(SUB_REQ_ID);
62
63         oper = new SdncOperation(params, config, Collections.emptyList()) {
64             @Override
65             protected SdncRequest makeRequest(int attempt) {
66                 return request;
67             }
68         };
69     }
70
71     @Test
72     public void testSdncOperator() {
73         assertEquals(DEFAULT_ACTOR, oper.getActorName());
74         assertEquals(DEFAULT_OPERATION, oper.getName());
75     }
76
77     @Test
78     public void testStartOperationAsync_testStartRequestAsync() throws Exception {
79         verifyOperation(oper);
80     }
81
82     @Test
83     public void testIsSuccess() {
84         // success case
85         response.getResponseOutput().setResponseCode("200");
86         assertTrue(oper.isSuccess(null, response));
87
88         // failure code
89         response.getResponseOutput().setResponseCode("555");
90         assertFalse(oper.isSuccess(null, response));
91
92         // null code
93         response.getResponseOutput().setResponseCode(null);
94         assertFalse(oper.isSuccess(null, response));
95
96         // null output
97         response.setResponseOutput(null);
98         assertFalse(oper.isSuccess(null, response));
99     }
100 }