summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorseshukm <seshu.kumar.m@huawei.com>2017-09-18 14:39:13 +0530
committerseshukm <seshu.kumar.m@huawei.com>2017-09-18 14:39:13 +0530
commitc3bf7754faf220200849f0e8f0cb666e51cdbce5 (patch)
treee0b888a06b053175251dcb67d8638b405d524873
parent311c1cf6d87a6c9b72581d218fb07526847e461d (diff)
Added UT for E2EService.
Issue-Id: SO-134 Change-Id: I046d6a922f07f0a10d124f67285c9277290e8879 Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java469
1 files changed, 469 insertions, 0 deletions
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
new file mode 100644
index 0000000000..f656d896fe
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstancesTest.java
@@ -0,0 +1,469 @@
+/*-
+ * ============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<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) {
+ return 0;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @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\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ assertTrue(resp.getStatus() == 202);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestBpelHTTPException(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) {
+ return 0;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @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\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Request Failed due to BPEL error with HTTP Status") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestBpelHTTPExceptionWithNullREsponseBody(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) {
+ return 0;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @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\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Request Failed due to BPEL error with HTTP Status") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestNullBPELResponse(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @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\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("bpelResponse is null") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestBPMNNullREsponse(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+
+ new MockUp<RequestClientFactory>() {
+ @Mock
+ public RequestClient getRequestClient(String orchestrationURI, MsoJavaProperties props) throws IllegalStateException{
+ RequestClient client = new CamundaClient();
+ client.setUrl("/test/url");
+ return client;
+ }
+ };
+
+ new MockUp<CamundaClient>() {
+ @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\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Failed calling bpmn null") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestNullBpmn(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String modelName) {
+ Service svc = new Service();
+ return svc;
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID(String modelUUID, String action) {
+ ServiceRecipe rec = new ServiceRecipe();
+ return rec;
+ }
+ };
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"service\":{\"name\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Failed calling bpmn properties is null") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestNullReceipe(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"service\":{\"name\":\"E2EService\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Recipe could not be retrieved from catalog DB null") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestNullDBResponse(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return null;
+ }
+ };
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"service\":{\"name\":\"e2eservice\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Recipe does not exist in catalog DB") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestInvalidRequest(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ List<InfraActiveRequests> activeReqlist = new ArrayList<>();
+ InfraActiveRequests req = new InfraActiveRequests();
+ req.setAaiServiceId("39493992");
+
+ activeReqlist.add(req);
+ return activeReqlist;
+ }
+ };
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"service\":{\"name\":\"e2eservice\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ 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<RequestsDatabase>() {
+ @Mock
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ return Collections.EMPTY_LIST;
+ }
+ };
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"service\":{\"name\":\"e2eservice\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("Recipe does not exist in catalog DB") != -1);
+ }
+
+ @Test
+ public void createE2EServiceInstanceTestDBQueryFail(){
+ E2EServiceInstances instance = new E2EServiceInstances();
+ String request = "{\"service\":{\"name\":\"e2eservice\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.createE2EServiceInstance(request, "v2");
+ 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, "v2");
+ 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\":\"e2eservice\",\"serviceDefId\":\"37889593\",\"templateId\":\"2000039\",\"parameters\":{\"domainHost\":\"test\"}}}";
+ Response resp = instance.deleteE2EServiceInstance(request, "v2");
+ String respStr = resp.getEntity().toString();
+ assertTrue(respStr.indexOf("SVC2000") != -1);
+ }
+}