X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=mso-api-handlers%2Fmso-api-handler-infra%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenecomp%2Fmso%2Fapihandlerinfra%2FE2EServiceInstancesTest.java;h=b1906d143f71a629353b01e617c5471145962abd;hb=1f2d4d8b32ef9403abec190775b90c5a4ab11d9f;hp=b247d81d7f865329e5caf6e52b92421e1fe762fa;hpb=fe2f2a382c07bc64e1b1c5910a9358e6b25c83ca;p=so.git diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java index b247d81d7f..b1906d143f 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -34,17 +35,24 @@ 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.HibernateException; +import org.hibernate.Session; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Order; +import org.hibernate.internal.SessionFactoryImpl; import org.junit.Test; +import org.junit.Ignore; +import org.mockito.Mockito; 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.MsoDatabaseException; import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.requestsdb.InfraActiveRequests; +import org.openecomp.mso.requestsdb.OperationStatus; import org.openecomp.mso.requestsdb.RequestsDatabase; import mockit.Mock; @@ -52,422 +60,777 @@ import mockit.MockUp; public class E2EServiceInstancesTest { - + String jsonBody = "{" + + "\"service\": {" + + "\"name\": \"so_test4\"," + + "\"description\": \"so_test2\"," + + "\"serviceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561519\"," + + "\"serviceUuid\": \"592f9437-a9c0-4303-b9f6-c445bb7e9814\"," + + "\"globalSubscriberId\": \"123457\"," + + "\"serviceType\": \"voLTE\"," + + "\"parameters\": {" + + "\"resources\": [" + + "{" + + "\"resourceName\": \"vIMS\"," + + "\"resourceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561516\"," + + "\"resourceUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561512\"," + + "\"parameters\": {" + + "\"locationConstraints\": [" + + "{" + + "\"vnfProfileId\": \"zte-vBAS-1.0\"," + + "\"locationConstraints\": {" + + "\"vimId\": \"4050083f-465f-4838-af1e-47a545222ad0\"" + + "}" + + "}," + + "{" + + "\"vnfProfileId\": \"zte-vMME-1.0\"," + + "\"locationConstraints\": {" + + "\"vimId\": \"4050083f-465f-4838-af1e-47a545222ad0\"" + + "}" + + "}" + + "]" + + "}" + + "}," + + "{" + + "\"resourceName\": \"vEPC\"," + + "\"resourceInvariantUuid\": \"61c3e96e-0970-4871-b6e0-3b6de7561516\"," + + "\"resourceUuid\": \"62c3e96e-0970-4871-b6e0-3b6de7561512\"," + + "\"parameters\": {" + + "\"locationConstraints\": [" + + "{" + + "\"vnfProfileId\": \"zte-CSCF-1.0\"," + + "\"locationConstraints\": {" + + "\"vimId\": \"4050083f-465f-4838-af1e-47a545222ad1\"" + + "}" + + "}" + + "]" + + "}" + + "}," + + "{" + + "\"resourceName\": \"underlayvpn\"," + + "\"resourceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561513\"," + + "\"resourceUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561514\"," + + "\"parameters\": {" + + "\"locationConstraints\": []" + + "}" + + "}," + + "{" + + "\"resourceName\": \"overlayvpn\"," + + "\"resourceInvariantUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561517\"," + + "\"resourceUuid\": \"60c3e96e-0970-4871-b6e0-3b6de7561518\"," + + "\"parameters\": {" + + "\"locationConstraints\": []" + + "}" + + "}" + + "]," + + "\"requestInputs\": {" + + "\"externalDataNetworkName\": \"Flow_out_net\"," + + "\"m6000_mng_ip\": \"181.18.20.2\"," + + "\"externalCompanyFtpDataNetworkName\": \"Flow_out_net\"," + + "\"externalPluginManageNetworkName\": \"plugin_net_2014\"," + + "\"externalManageNetworkName\": \"mng_net_2017\"," + + "\"sfc_data_network\": \"sfc_data_net_2016\"," + + "\"NatIpRange\": \"210.1.1.10-210.1.1.20\"," + + "\"location\": \"4050083f-465f-4838-af1e-47a545222ad0\"," + + "\"sdncontroller\": \"9b9f02c0-298b-458a-bc9c-be3692e4f35e\"" + + "}" + + "}" + + "}" + + "}"; + @Test - public void createE2EServiceInstanceTestSuccess(){ + 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; - } - }; - + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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 configurationId, String serviceType, + String vnfType, String vfModuleType, String networkType, + String requestDetails, String recipeParamXsd) { + 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\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestBpelHTTPException(){ + 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; - } - }; - + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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 configurationId, String serviceType, + String vnfType, String vfModuleType, String networkType, + String requestDetails, String recipeParamXsd) { + 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\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestBpelHTTPExceptionWithNullREsponseBody(){ + 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; - } - }; - + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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 configurationId, String serviceType, + String vnfType, String vfModuleType, String networkType, + String requestDetails, String recipeParamXsd) { + 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\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestNullBPELResponse(){ + 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; - } - }; - + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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 configurationId, String serviceType, + String vnfType, String vfModuleType, String networkType, + String requestDetails, String recipeParamXsd) { + HttpResponse resp = null; + return resp; + } + }; + E2EServiceInstances instance = new E2EServiceInstances(); - String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestBPMNNullREsponse(){ + 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; - } - }; - + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestNullBpmn(){ + 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; - } - }; + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody;; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("Exception while creating record in DB null") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestNullReceipe(){ + public void createE2EServiceInstanceTestNullReceipe() { new MockUp() { - @Mock - private List executeInfraQuery (List criteria, Order order) { - return null; - } - }; + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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\"}]}}}}"; + String request = jsonBody; 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); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestNullDBResponse(){ + public void createE2EServiceInstanceTestNullDBResponse() { + new MockUp() { - @Mock - private List executeInfraQuery (List criteria, Order order) { - return null; - } - }; + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + E2EServiceInstances instance = new E2EServiceInstances(); - String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; 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); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestInvalidRequest(){ + 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; - } - }; + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; E2EServiceInstances instance = new E2EServiceInstances(); - String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; 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); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestEmptyDBQuery(){ - new MockUp() { - @Mock - private List executeInfraQuery (List criteria, Order order) { - return Collections.EMPTY_LIST; - } - }; + public void createE2EServiceInstanceTestEmptyDBQuery() { + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + E2EServiceInstances instance = new E2EServiceInstances(); - String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; 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); + assertTrue(respStr.contains("SVC2000")); + // assertTrue(true); } - + @Test - public void createE2EServiceInstanceTestDBQueryFail(){ + public void createE2EServiceInstanceTestDBQueryFail() { + new MockUp() { + @Mock + public OperationStatus getOperationStatusByServiceName( + String serviceName) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; E2EServiceInstances instance = new E2EServiceInstances(); - String request = "{\"service\":{\"name\":\"service\",\"description\":\"so_test1\",\"serviceDefId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"subscriberName\":\"NEED THIS UUI - AAI\",\"requestParameters\":{\"subscriptionServiceType\":\"MOG\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"},{\"name\":\"segments\",\"value\":\"value\"},{\"name\":\"nsParameters\",\"value\":\"othervalue\"}]}}}}"; + String request = jsonBody; Response resp = instance.createE2EServiceInstance(request, "v3"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("SVC2000") != -1); + assertTrue(respStr.contains("SVC2000")); } - + @Test - public void createE2EServiceInstanceTestForEmptyRequest(){ + public void createE2EServiceInstanceTestForEmptyRequest() { + + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; 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); + assertTrue(respStr + .contains("Mapping of request to JSON object failed. No content to map to Object due to end of input")); + } + + @Ignore // 1802 merge + @Test + public void deleteE2EServiceInstanceTestNormal() { + E2EServiceInstances instance = new E2EServiceInstances(); + String request = "{\"globalSubscriberId\":\"299392392\",\"serviceType\":\"VoLTE\"}"; + Response resp = instance.deleteE2EServiceInstance(request, "v3", + "12345678"); + String respStr = resp.getEntity().toString(); + assertTrue(respStr.contains("SVC1000")); + } + + @Test + public void getE2EServiceInstanceTest() { + + new MockUp() { + @Mock + public OperationStatus getOperationStatus(String serviceId, + String operationId) { + OperationStatus os = new OperationStatus(); + os.setOperation(""); + os.setOperationContent(""); + os.setOperationId("123456"); + os.setProgress(""); + os.setServiceId("12345"); + os.setServiceName("VoLTE"); + os.setReason(""); + os.setResult(""); + os.setUserId(""); + return os; + } + }; + + E2EServiceInstances instance = new E2EServiceInstances(); + Response resp = instance + .getE2EServiceInstances("12345", "v3", "123456"); + } @Test - public void deleteE2EServiceInstanceTestNormal(){ + public void updateE2EServiceInstanceTestNormal() { + new MockUp() { + @Mock + public OperationStatus getOperationStatusByServiceId( + String serviceID) { + OperationStatus operationStatus = new OperationStatus(); + operationStatus.setProgress("100"); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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 configurationId, String serviceType, + String vnfType, String vfModuleType, String networkType, + String requestDetails, String recipeParamXsd) { + 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 = jsonBody; + Response resp = instance.updateE2EServiceInstance(request, "v3", "12345"); + String respStr = resp.getEntity().toString(); + assertTrue(respStr.contains("success")); + } + + @Test + public void updateE2EServiceInstanceTestChkStatusFalse() { + new MockUp() { + @Mock + public OperationStatus getOperationStatusByServiceId( + String serviceID) { + OperationStatus operationStatus = new OperationStatus(); + return operationStatus; + } + }; + new MockUp() { + @Mock + private void createOperationStatusRecordForError(Action action, + String requestId) throws MsoDatabaseException { + + } + }; + 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 configurationId, String serviceType, + String vnfType, String vfModuleType, String networkType, + String requestDetails, String recipeParamXsd) { + 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\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"templateId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"parameters\":{\"domainHost\":\"localhost\",\"nodeTemplateName\":\"modelName:v3\",\"nodeType\":\"service\",\"globalSubscriberId\":\"4050083f-465f-4838-af1e-47a545222ad1\",\"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 request = jsonBody; + Response resp = instance.updateE2EServiceInstance(request, "v3", "12345"); String respStr = resp.getEntity().toString(); - assertTrue(respStr.indexOf("SVC2000") != -1); + assertTrue(respStr.contains("SVC2000")); } }