Merge "Change payload to Map<String,Object> so it's more versatile"
[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.SdncRequest;
33
34 public class SdncOperationTest extends BasicSdncOperation {
35
36     private SdncRequest request;
37     private SdncOperation oper;
38
39     /**
40      * Sets up.
41      */
42     @Before
43     public void setUp() throws Exception {
44         super.setUp();
45
46         oper = new SdncOperation(params, config) {
47             @Override
48             protected SdncRequest makeRequest(int attempt) {
49                 return request;
50             }
51         };
52     }
53
54     @Test
55     public void testSdncOperator() {
56         assertEquals(DEFAULT_ACTOR, oper.getActorName());
57         assertEquals(DEFAULT_OPERATION, oper.getName());
58     }
59
60     @Test
61     public void testStartPreprocessorAsync() {
62         assertNotNull(oper.startPreprocessorAsync());
63     }
64
65     @Test
66     public void testStartOperationAsync_testStartRequestAsync() throws Exception {
67         verifyOperation(oper);
68     }
69
70     @Test
71     public void testIsSuccess() {
72         // success case
73         response.getResponseOutput().setResponseCode("200");
74         assertTrue(oper.isSuccess(null, response));
75
76         // failure code
77         response.getResponseOutput().setResponseCode("555");
78         assertFalse(oper.isSuccess(null, response));
79
80         // null code
81         response.getResponseOutput().setResponseCode(null);
82         assertFalse(oper.isSuccess(null, response));
83
84         // null output
85         response.setResponseOutput(null);
86         assertFalse(oper.isSuccess(null, response));
87     }
88
89     @Override
90     protected Map<String, String> makeEnrichment() {
91         return new TreeMap<>();
92     }
93 }