More changes to actor code
[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.Map;
28 import java.util.TreeMap;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.sdnc.SdncRequest;
32
33 public class SdncOperationTest extends BasicSdncOperation {
34
35     private SdncRequest request;
36     private SdncOperation oper;
37
38     /**
39      * Sets up.
40      */
41     @Before
42     public void setUp() throws Exception {
43         super.setUp();
44
45         oper = new SdncOperation(params, operator) {
46             @Override
47             protected SdncRequest makeRequest(int attempt) {
48                 return request;
49             }
50         };
51     }
52
53     @Test
54     public void testSdncOperator() {
55         assertEquals(DEFAULT_ACTOR, oper.getActorName());
56         assertEquals(DEFAULT_OPERATION, oper.getName());
57     }
58
59     @Test
60     public void testStartOperationAsync_testStartRequestAsync() throws Exception {
61         verifyOperation(oper);
62     }
63
64     @Test
65     public void testIsSuccess() {
66         // success case
67         response.getResponseOutput().setResponseCode("200");
68         assertTrue(oper.isSuccess(null, response));
69
70         // failure code
71         response.getResponseOutput().setResponseCode("555");
72         assertFalse(oper.isSuccess(null, response));
73
74         // null code
75         response.getResponseOutput().setResponseCode(null);
76         assertFalse(oper.isSuccess(null, response));
77
78         // null output
79         response.setResponseOutput(null);
80         assertFalse(oper.isSuccess(null, response));
81     }
82
83     @Override
84     protected Map<String, String> makeEnrichment() {
85         return new TreeMap<>();
86     }
87 }