fixed jUnit in 3 files
[appc.git] / appc-inbound / appc-interfaces-service / bundle / src / test / java / org / onap / appc / interfaceService / serviceExecutor / TestServiceExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modification Copyright (C) 2018 IBM
10  * ================================================================================
11  * Modifications Copyright (C) 2019 Ericsson
12  * =============================================================================
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  * 
17  *      http://www.apache.org/licenses/LICENSE-2.0
18  * 
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  * 
25  * ============LICENSE_END=========================================================
26  */
27
28 package org.onap.appc.interfaceService.serviceExecutor;
29
30
31 import static org.junit.Assert.assertEquals;
32 import static org.junit.Assert.assertNotNull;
33 import org.junit.Test;
34 import org.onap.appc.interfaces.service.executorImpl.ServiceExecutorImpl;
35 import org.onap.appc.interfaces.service.data.ScopeOverlap;
36 import org.onap.appc.interfaces.service.executor.ServiceExecutor;
37
38 import com.fasterxml.jackson.databind.ObjectMapper;
39
40 import org.powermock.reflect.Whitebox;
41
42 public class TestServiceExecutor {
43
44     @Test
45     public void serviceExecutorTest() throws Exception {
46         ServiceExecutorImpl sei = new ServiceExecutorImpl();
47         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}";
48         sei.isRequestOverLap(requestData);
49         assertNotNull(sei);
50     }
51
52     @Test
53     public void isVserverOrVnfcIdOverLapTest() throws Exception{
54         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"vnf-id\" : \"vnf-id\",\"vf-module-id\" : \"vf-module-1234\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"vnf-id\" : \"vnf-id1\",\"vf-module-id\":\"vf-module-1234\"}}]}";
55         ServiceExecutorImpl sei = new ServiceExecutorImpl();
56         ScopeOverlap scopeOverlap = new ScopeOverlap();
57         ObjectMapper mapper = new ObjectMapper();
58         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
59         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap);
60         assertEquals(true, result);
61     }
62
63     @Test
64     public void serviceExecutor() throws Exception {
65         ServiceExecutor sei = new ServiceExecutor();
66         String action ="getdatabymodel";
67         String requestDataType = "";
68         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}";
69        String result = sei.execute(action, requestData, requestDataType);
70        assertEquals(null, result);
71     }
72
73     @Test(expected = Exception.class)
74     public void serviceExecutorException() throws Exception {
75         ServiceExecutor sei = new ServiceExecutor();
76         String action = "";
77         String requestDataType = "";
78         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}";
79         sei.execute(action, requestData, requestDataType);
80     }
81
82     @Test
83     public void serviceExecutorRequest() throws Exception {
84         ServiceExecutor sei = new ServiceExecutor();
85         String action = "isScopeOverlap";
86         String requestDataType = "";
87         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}";
88         String actual ="\"requestOverlap\"  : true";
89         String result = sei.execute(action, requestData, requestDataType);
90         assertEquals(actual, result);
91     }
92
93     @Test
94     public void serviceExecutorRqsFal() throws Exception {
95         ServiceExecutor sei = new ServiceExecutor();
96         String action = "isScopeOverlap";
97         String requestDataType = "";
98         String actual ="\"requestOverlap\"  : false";
99         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id\"}}}";        
100         String result = sei.execute(action, requestData, requestDataType);
101         assertEquals(actual, result);
102     }
103
104     @Test(expected = Exception.class)
105     public void serviceExecutorRqstEx() throws Exception {
106         ServiceExecutor sei = new ServiceExecutor();
107         String action = "isScopeOverlap";
108         String requestData = "";
109         String requestDataType = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"},\"target-id\":\"ibcx0001v\"}]}";        
110         sei.execute(action, requestData, requestDataType);
111     }
112
113     @Test
114     public void isVserverOrVnfcIdOverlap() throws Exception{
115         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vf-module-id\" : \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\": \"vserver-id2\"}}]}";
116         ServiceExecutorImpl sei = new ServiceExecutorImpl();
117         ScopeOverlap scopeOverlap = new ScopeOverlap();
118         ObjectMapper mapper = new ObjectMapper();
119         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
120         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap);
121         assertEquals(true, result);
122     }
123
124     @Test
125     public void isVserverOrVnfcIdO() throws Exception{
126         String requestData = "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vserver-id\": \"vserver-id1\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vserver-id\": \"vserver-id2\"}}]}";
127         ServiceExecutorImpl sei = new ServiceExecutorImpl();
128         ScopeOverlap scopeOverlap = new ScopeOverlap();
129         ObjectMapper mapper = new ObjectMapper();
130         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
131         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap);
132         assertEquals(true, result);
133     }
134
135     @Test(expected = Exception.class)
136     public void isVserverOrVnfcId() throws Exception{
137         String requestData =  "{\"vnf-id\":\"ibcx8888v\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id\",\"vnfc-name\" : \"vnfc-name2\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" : \"service-instance-id2\",\"vnfc-name\" : \"vnfc-name2\"}}]}";
138         ServiceExecutorImpl sei = new ServiceExecutorImpl();
139         ScopeOverlap scopeOverlap = new ScopeOverlap();
140         ObjectMapper mapper = new ObjectMapper();
141         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
142         Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap);
143     }
144 }