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