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