a81d56db0bb37bc16e4846d2755a4c7cee9f5306
[appc.git] /
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 org.junit.Test;
33 import org.onap.appc.interfaces.service.executorImpl.ServiceExecutorImpl;
34 import org.onap.appc.interfaces.service.data.ScopeOverlap;
35 import org.onap.appc.interfaces.service.executor.ServiceExecutor;
36
37 import com.fasterxml.jackson.databind.ObjectMapper;
38
39 import org.powermock.reflect.Whitebox;
40
41 public class TestServiceExecutor {
42
43     @Test
44     public void serviceExecutorTest() throws Exception {
45         ServiceExecutorImpl sei = new ServiceExecutorImpl();
46         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\"}}]}";
47         sei.isRequestOverLap(requestData);
48     }
49
50     @Test
51     public void isVserverOrVnfcIdOverLapTest() throws Exception{
52         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\"}}]}";
53         ServiceExecutorImpl sei = new ServiceExecutorImpl();
54         ScopeOverlap scopeOverlap = new ScopeOverlap();
55         ObjectMapper mapper = new ObjectMapper();
56         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
57         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap",scopeOverlap);
58         assertEquals(true, result);
59     }
60
61     @Test
62     public void serviceExecutor() throws Exception {
63         ServiceExecutor sei = new ServiceExecutor();
64         String action ="getdatabymodel";
65         String requestDataType = "";
66         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\"}}]}";
67        String result = sei.execute(action, requestData, requestDataType);
68        assertEquals(null, result);
69     }
70
71     @Test(expected = Exception.class)
72     public void serviceExecutorException() throws Exception {
73         ServiceExecutor sei = new ServiceExecutor();
74         String action = "";
75         String requestDataType = "";
76         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\"}}]}";
77         sei.execute(action, requestData, requestDataType);
78     }
79
80     @Test
81     public void serviceExecutorRequest() throws Exception {
82         ServiceExecutor sei = new ServiceExecutor();
83         String action = "isScopeOverlap";
84         String requestDataType = "";
85         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\"}}]}";
86         String actual ="\"requestOverlap\"  : true";
87         String result = sei.execute(action, requestData, requestDataType);
88         assertEquals(actual, result);
89     }
90
91     @Test
92     public void serviceExecutorRqsFal() throws Exception {
93         ServiceExecutor sei = new ServiceExecutor();
94         String action = "isScopeOverlap";
95         String requestDataType = "";
96         String actual ="\"requestOverlap\"  : false";
97         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\"}}}";        
98         String result = sei.execute(action, requestData, requestDataType);
99         assertEquals(actual, result);
100     }
101
102     @Test(expected = Exception.class)
103     public void serviceExecutorRqstEx() throws Exception {
104         ServiceExecutor sei = new ServiceExecutor();
105         String action = "isScopeOverlap";
106         String requestData = "";
107         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\"}]}";        
108         sei.execute(action, requestData, requestDataType);
109     }
110
111     @Test
112     public void isVserverOrVnfcIdOverlap() throws Exception{
113         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\"}}]}";
114         ServiceExecutorImpl sei = new ServiceExecutorImpl();
115         ScopeOverlap scopeOverlap = new ScopeOverlap();
116         ObjectMapper mapper = new ObjectMapper();
117         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
118         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap);
119         assertEquals(true, result);
120     }
121
122     @Test
123     public void isVserverOrVnfcIdO() throws Exception{
124         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\"}}]}";
125         ServiceExecutorImpl sei = new ServiceExecutorImpl();
126         ScopeOverlap scopeOverlap = new ScopeOverlap();
127         ObjectMapper mapper = new ObjectMapper();
128         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
129         boolean result = Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap);
130         assertEquals(true, result);
131     }
132
133     @Test(expected = Exception.class)
134     public void isVserverOrVnfcId() throws Exception{
135         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\"}}]}";
136         ServiceExecutorImpl sei = new ServiceExecutorImpl();
137         ScopeOverlap scopeOverlap = new ScopeOverlap();
138         ObjectMapper mapper = new ObjectMapper();
139         scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
140         Whitebox.invokeMethod(sei, "isVserverOrVnfcIdOverLap", scopeOverlap);
141     }
142 }