2 * ============LICENSE_START=======================================================
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
17 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 * ============LICENSE_END=========================================================
28 package org.onap.appc.interfaceService.serviceExecutor;
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;
38 import com.fasterxml.jackson.databind.ObjectMapper;
40 import org.powermock.reflect.Whitebox;
42 public class TestServiceExecutor {
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);
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);
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);
73 @Test(expected = Exception.class)
74 public void serviceExecutorException() throws Exception {
75 ServiceExecutor sei = new ServiceExecutor();
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);
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);
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);
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);
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);
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);
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);