9055715b47cb38a011d7bbe2b41559914256fc00
[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  * ================================================================================
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.sdnc;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Collections;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.sdnc.SdncHealRequest;
31 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
32 import org.onap.policy.sdnc.SdncRequest;
33
34 public class SdncOperationTest extends BasicSdncOperation {
35
36     private static final String MY_URI = "my-uri";
37
38     private SdncRequest request;
39     private SdncOperation oper;
40
41     /**
42      * Sets up.
43      */
44     @Before
45     public void setUp() throws Exception {
46         super.setUp();
47
48         request = new SdncRequest();
49         request.setUrl(MY_URI);
50
51         SdncHealRequest healRequest = new SdncHealRequest();
52         request.setHealRequest(healRequest);
53
54         SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
55         healRequest.setRequestHeaderInfo(headerInfo);
56         headerInfo.setSvcRequestId(SUB_REQ_ID);
57
58         oper = new SdncOperation(params, config, Collections.emptyList()) {
59             @Override
60             protected SdncRequest makeRequest(int attempt) {
61                 return request;
62             }
63         };
64     }
65
66     @Test
67     public void testSdncOperator() {
68         assertEquals(DEFAULT_ACTOR, oper.getActorName());
69         assertEquals(DEFAULT_OPERATION, oper.getName());
70     }
71
72     @Test
73     public void testStartOperationAsync_testStartRequestAsync() throws Exception {
74         verifyOperation(oper);
75     }
76
77     @Test
78     public void testIsSuccess() {
79         // success case
80         response.getResponseOutput().setResponseCode("200");
81         assertTrue(oper.isSuccess(null, response));
82
83         // failure code
84         response.getResponseOutput().setResponseCode("555");
85         assertFalse(oper.isSuccess(null, response));
86
87         // null code
88         response.getResponseOutput().setResponseCode(null);
89         assertFalse(oper.isSuccess(null, response));
90
91         // null output
92         response.setResponseOutput(null);
93         assertFalse(oper.isSuccess(null, response));
94     }
95 }