6567a2cce1a98766da88f11694357a09a2f515fa
[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  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.interfaceService.serviceExecutor;
27
28 import static org.junit.Assert.*;
29
30 import org.junit.Test;
31
32 import org.onap.appc.interfaces.service.executorImpl.ServiceExecutorImpl;
33 import org.onap.appc.interfaces.service.data.ScopeOverlap;
34 import org.onap.appc.interfaces.service.executor.ServiceExecutor;
35
36 import com.fasterxml.jackson.databind.ObjectMapper;
37
38 import org.powermock.reflect.Whitebox;
39
40 public class TestServiceExecutor {
41
42     @Test
43     public void serviceExecutorTest() throws Exception {
44         ServiceExecutorImpl sei = new ServiceExecutorImpl();
45         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\"}}]}";
46         sei.isRequestOverLap(requestData);
47     }
48
49     @Test
50     public void isVserverOrVnfcIdOverLapTest() throws Exception{
51         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\"}}]}";
52         ServiceExecutorImpl sei = new ServiceExecutorImpl();
53         ScopeOverlap scopeOverlap = new ScopeOverlap();
54         ObjectMapper mapper = new ObjectMapper();
55         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
56         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap);
57         assertEquals(true, result);
58     }
59
60     @Test
61     public void serviceExecutor() throws Exception {
62         ServiceExecutor sei = new ServiceExecutor();
63         String action ="getdatabymodel";
64         String requestDataType = "";
65         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\"}}]}";
66        String result = sei.execute(action, requestData, requestDataType);
67        assertEquals(null, result);
68     }
69
70     @Test(expected = Exception.class)
71     public void serviceExecutorException() throws Exception {
72         ServiceExecutor sei = new ServiceExecutor();
73         String action ="";
74         String requestDataType = "";
75         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\"}}]}";
76         sei.execute(action, requestData, requestDataType);
77     }
78
79     @Test
80     public void serviceExecutorRequest() throws Exception {
81         ServiceExecutor sei = new ServiceExecutor();
82         String action ="isScopeOverlap";
83         String requestDataType = "";
84         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\"}}]}";
85         String actual ="\"requestOverlap\"  : true";
86         String result = sei.execute(action, requestData, requestDataType);
87         assertEquals(actual,result);
88     }
89
90     @Test
91     public void serviceExecutorRqsFal() throws Exception {
92         ServiceExecutor sei = new ServiceExecutor();
93         String action ="isScopeOverlap";
94         String requestDataType = "";
95         String actual ="\"requestOverlap\"  : false";
96         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\"}}}";        
97         String result = sei.execute(action, requestData, requestDataType);
98         assertEquals(actual,result);
99     }
100
101     @Test(expected = Exception.class)
102     public void serviceExecutorRqstEx() throws Exception {
103         ServiceExecutor sei = new ServiceExecutor();
104         String action ="isScopeOverlap";
105         String requestData = "";
106         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\"}]}";        
107         sei.execute(action, requestData, requestDataType);
108     }
109
110     @Test
111     public void isVserverOrVnfcIdOverlap() throws Exception{
112         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\"}}]}";
113         ServiceExecutorImpl sei = new ServiceExecutorImpl();
114         ScopeOverlap scopeOverlap = new ScopeOverlap();
115         ObjectMapper mapper = new ObjectMapper();
116         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
117         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap);
118         assertEquals(true, result);
119     }
120
121     @Test
122     public void isVserverOrVnfcIdO() throws Exception{
123         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\"}}]}";
124         ServiceExecutorImpl sei = new ServiceExecutorImpl();
125         ScopeOverlap scopeOverlap = new ScopeOverlap();
126         ObjectMapper mapper = new ObjectMapper();
127         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
128         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap);
129         assertEquals(true, result);
130     }
131
132     @Test(expected = Exception.class)
133     public void isVserverOrVnfcId() throws Exception{
134         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\"}}]}";
135         ServiceExecutorImpl sei = new ServiceExecutorImpl();
136         ScopeOverlap scopeOverlap = new ScopeOverlap();
137         ObjectMapper mapper = new ObjectMapper();
138         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
139         Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap);
140     }
141 }