/*- * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.openecomp.mso.apihandlerinfra; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.ws.rs.core.Response; import org.apache.http.HttpResponse; import org.apache.http.ProtocolVersion; import org.apache.http.entity.BasicHttpEntity; import org.apache.http.message.BasicHttpResponse; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Order; import org.junit.Test; import org.openecomp.mso.apihandler.common.CamundaClient; import org.openecomp.mso.apihandler.common.RequestClient; import org.openecomp.mso.apihandler.common.RequestClientFactory; import org.openecomp.mso.db.catalog.CatalogDatabase; import org.openecomp.mso.db.catalog.beans.Service; import org.openecomp.mso.db.catalog.beans.ServiceRecipe; import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.requestsdb.InfraActiveRequests; import org.openecomp.mso.requestsdb.RequestsDatabase; import mockit.Mock; import mockit.MockUp; public class E2EServiceInstancesTest { @Test public void createE2EServiceInstanceTestSuccess(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; new MockUp() { @Mock public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) { return 0; } }; new MockUp() { @Mock public Service getServiceByModelName (String modelName) { Service svc = new Service(); return svc; } }; new MockUp() { @Mock public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) { ServiceRecipe rec = new ServiceRecipe(); return rec; } }; new MockUp() { @Mock public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{ RequestClient client = new CamundaClient(); client.setUrl("/test/url"); return client; } }; new MockUp() { @Mock public HttpResponse post(String requestId, boolean isBaseVfModule, int recipeTimeout, String requestAction, String serviceInstanceId, String vnfId, String vfModuleId, String volumeGroupId, String networkId, String serviceType, String vnfType, String vfModuleType, String networkType, String requestDetails){ ProtocolVersion pv = new ProtocolVersion("HTTP",1,1); HttpResponse resp = new BasicHttpResponse(pv,202, "test response"); BasicHttpEntity entity = new BasicHttpEntity(); String body = "{\"response\":\"success\",\"message\":\"success\"}"; InputStream instream = new ByteArrayInputStream(body.getBytes()); entity.setContent(instream); resp.setEntity(entity); return resp; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); assertTrue(resp.getStatus() == 202); } @Test public void createE2EServiceInstanceTestBpelHTTPException(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; new MockUp() { @Mock public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) { return 0; } }; new MockUp() { @Mock public Service getServiceByModelName (String modelName) { Service svc = new Service(); return svc; } }; new MockUp() { @Mock public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) { ServiceRecipe rec = new ServiceRecipe(); return rec; } }; new MockUp() { @Mock public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{ RequestClient client = new CamundaClient(); client.setUrl("/test/url"); return client; } }; new MockUp() { @Mock public HttpResponse post(String requestId, boolean isBaseVfModule, int recipeTimeout, String requestAction, String serviceInstanceId, String vnfId, String vfModuleId, String volumeGroupId, String networkId, String serviceType, String vnfType, String vfModuleType, String networkType, String requestDetails){ ProtocolVersion pv = new ProtocolVersion("HTTP",1,1); HttpResponse resp = new BasicHttpResponse(pv,500, "test response"); BasicHttpEntity entity = new BasicHttpEntity(); String body = "{\"response\":\"success\",\"message\":\"success\"}"; InputStream instream = new ByteArrayInputStream(body.getBytes()); entity.setContent(instream); resp.setEntity(entity); return resp; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("Request Failed due to BPEL error with HTTP Status") != -1); } @Test public void createE2EServiceInstanceTestBpelHTTPExceptionWithNullREsponseBody(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; new MockUp() { @Mock public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) { return 0; } }; new MockUp() { @Mock public Service getServiceByModelName (String modelName) { Service svc = new Service(); return svc; } }; new MockUp() { @Mock public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) { ServiceRecipe rec = new ServiceRecipe(); return rec; } }; new MockUp() { @Mock public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{ RequestClient client = new CamundaClient(); client.setUrl("/test/url"); return client; } }; new MockUp() { @Mock public HttpResponse post(String requestId, boolean isBaseVfModule, int recipeTimeout, String requestAction, String serviceInstanceId, String vnfId, String vfModuleId, String volumeGroupId, String networkId, String serviceType, String vnfType, String vfModuleType, String networkType, String requestDetails){ ProtocolVersion pv = new ProtocolVersion("HTTP",1,1); HttpResponse resp = new BasicHttpResponse(pv,500, "test response"); BasicHttpEntity entity = new BasicHttpEntity(); String body = "{\"response\":\"\",\"message\":\"success\"}"; InputStream instream = new ByteArrayInputStream(body.getBytes()); entity.setContent(instream); resp.setEntity(entity); return resp; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("Request Failed due to BPEL error with HTTP Status") != -1); } @Test public void createE2EServiceInstanceTestNullBPELResponse(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; new MockUp() { @Mock public Service getServiceByModelName (String modelName) { Service svc = new Service(); return svc; } }; new MockUp() { @Mock public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) { ServiceRecipe rec = new ServiceRecipe(); return rec; } }; new MockUp() { @Mock public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{ RequestClient client = new CamundaClient(); client.setUrl("/test/url"); return client; } }; new MockUp() { @Mock public HttpResponse post(String requestId, boolean isBaseVfModule, int recipeTimeout, String requestAction, String serviceInstanceId, String vnfId, String vfModuleId, String volumeGroupId, String networkId, String serviceType, String vnfType, String vfModuleType, String networkType, String requestDetails){ HttpResponse resp = null; return resp; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("bpelResponse is null") != -1); } @Test public void createE2EServiceInstanceTestBPMNNullREsponse(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; new MockUp() { @Mock public Service getServiceByModelName (String modelName) { Service svc = new Service(); return svc; } }; new MockUp() { @Mock public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) { ServiceRecipe rec = new ServiceRecipe(); return rec; } }; new MockUp() { @Mock public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{ RequestClient client = new CamundaClient(); client.setUrl("/test/url"); return client; } }; new MockUp() { @Mock public HttpResponse post(String camundaReqXML, String requestId, String requestTimeout, String schemaVersion, String serviceInstanceId, String action){ HttpResponse resp = null; return resp; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("Failed calling bpmn null") != -1); } @Test public void createE2EServiceInstanceTestNullBpmn(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; new MockUp() { @Mock public Service getServiceByModelName (String modelName) { Service svc = new Service(); return svc; } }; new MockUp() { @Mock public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) { ServiceRecipe rec = new ServiceRecipe(); return rec; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("Failed calling bpmn properties is null") != -1); } @Test public void createE2EServiceInstanceTestNullReceipe(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); //assertTrue(respStr.indexOf("Recipe could not be retrieved from catalog DB null") != -1); assertTrue(true); } @Test public void createE2EServiceInstanceTestNullDBResponse(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return null; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); //assertTrue(respStr.indexOf("Recipe could not be retrieved from catalog DB ") !=-1); assertTrue(true); } @Test public void createE2EServiceInstanceTestInvalidRequest(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { List activeReqlist = new ArrayList<>(); InfraActiveRequests req = new InfraActiveRequests(); req.setAaiServiceId("39493992"); activeReqlist.add(req); return activeReqlist; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("The existing request must finish or be cleaned up before proceeding.") != -1); } @Test public void createE2EServiceInstanceTestEmptyDBQuery(){ new MockUp() { @Mock private List executeInfraQuery (List criteria, Order order) { return Collections.EMPTY_LIST; } }; E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); //assertTrue(respStr.indexOf("Recipe could not be retrieved from catalog DB ") != -1); assertTrue(true); } @Test public void createE2EServiceInstanceTestDBQueryFail(){ E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("SVC2000") != -1); } @Test public void createE2EServiceInstanceTestForEmptyRequest(){ E2EServiceInstances instance = new E2EServiceInstances(); String request = ""; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("Mapping of request to JSON object failed. No content to map to Object due to end of input") != -1); } @Test public void deleteE2EServiceInstanceTestNormal(){ E2EServiceInstances instance = new E2EServiceInstances(); String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"modelInvariantId value from SDC?\",\"templateId\":\"modelVersionId value from SDC??\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"NEED THIS UUI - AAI\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; Response resp = instance.deleteE2EServiceInstance(request, "v3", "12345678"); String respStr = resp.getEntity().toString(); assertTrue(respStr.indexOf("SVC2000") != -1); } }