summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorseshukm <seshu.kumar.m@huawei.com>2017-10-06 11:10:59 +0530
committerseshukm <seshu.kumar.m@huawei.com>2017-10-06 11:10:59 +0530
commitd88601feb7f3fff14c9cb3633a1d95229f97ee92 (patch)
tree1106a07210ed8821376fccc087f2a0a13400bb4f
parentfc0e957f6c3adb18eba669b0dd808398da24a003 (diff)
Adding UT for SO
IssueId: SO-191 Change-Id: Ic9fb77341842fd48efc81341c3a42c26d101b60d Signed-off-by: seshukm <seshu.kumar.m@huawei.com>
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java213
-rw-r--r--asdc-controller/src/test/java/org/openecomp/mso/asdc/util/tests/ASDCNotificationLoggingTest.java174
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/ServiceInstanceTest.java391
3 files changed, 778 insertions, 0 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java
new file mode 100644
index 0000000000..f231c75211
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java
@@ -0,0 +1,213 @@
+/*-
+ * ============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.adapter_utils.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openecomp.mso.entity.MsoRequest;
+import org.openecomp.mso.openstack.beans.HeatStatus;
+import org.openecomp.mso.openstack.beans.MsoTenant;
+import org.openecomp.mso.openstack.beans.NetworkInfo;
+import org.openecomp.mso.openstack.beans.NetworkRollback;
+import org.openecomp.mso.openstack.beans.NetworkStatus;
+import org.openecomp.mso.openstack.beans.Pool;
+import org.openecomp.mso.openstack.beans.StackInfo;
+import org.openecomp.mso.openstack.beans.Subnet;
+import org.openecomp.mso.openstack.beans.VnfRollback;
+
+import com.woorea.openstack.heat.model.Stack;
+
+public class AdapterBeansTest {
+ @Test
+ public final void msoTenantTest() {
+ MsoTenant tenant = new MsoTenant();
+ tenant.setTenantId("1");
+ assertTrue(tenant.getTenantId().equalsIgnoreCase("1"));
+ tenant.setTenantName("TenantName");
+ assertTrue(tenant.getTenantName().equalsIgnoreCase("TenantName"));
+ Map<String, String> hm = new HashMap<>();
+ hm.put("Key1", "value1");
+ tenant.setMetadata(hm);
+ assertTrue(tenant.getMetadata() != null);
+ new MsoTenant("1", "TenantName", hm);
+ // assertTrue(tenant.toString() != null);
+ }
+
+ @Test
+ public final void networkInfoTest() {
+ NetworkInfo networkInfo = new NetworkInfo();
+ networkInfo.setName("name");
+ assertTrue(networkInfo.getName().equalsIgnoreCase("name"));
+ networkInfo.setId("1");
+ assertTrue(networkInfo.getId().equalsIgnoreCase("1"));
+ networkInfo.setStatus(NetworkStatus.ACTIVE);
+ assertTrue(networkInfo.getStatus().equals(NetworkStatus.ACTIVE));
+ networkInfo.setProvider("provider");
+ networkInfo.getProvider().equalsIgnoreCase("provider");
+ List<Integer> al = new ArrayList<>();
+ al.add(1);
+ al.add(2);
+ networkInfo.setVlans(al);
+ assertTrue(networkInfo.getVlans() != null);
+ networkInfo.setShared("shared");
+ assertTrue(networkInfo.getShared().equalsIgnoreCase("shared"));
+ List<String> als = new ArrayList<>();
+ als.add("1");
+ als.add("2");
+ networkInfo.setSubnets(als);
+ assertTrue(networkInfo.getSubnets() != null);
+ new NetworkInfo("string", NetworkStatus.ACTIVE);
+ assertTrue(networkInfo.toString() != null);
+ }
+
+ @Test
+ public final void networkRollbackTest() {
+ NetworkRollback networkRollback = new NetworkRollback();
+ networkRollback.setCloudId("cloudId");
+ assertTrue(networkRollback.getCloudId().equalsIgnoreCase("cloudId"));
+ networkRollback.setModelCustomizationUuid("modelCustomizationUuid");
+ assertTrue(networkRollback.getModelCustomizationUuid().equalsIgnoreCase("modelCustomizationUuid"));
+ MsoRequest msoRequest = new MsoRequest();
+ networkRollback.setMsoRequest(msoRequest);
+ networkRollback.getMsoRequest();
+ // assertTrue(networkRollback.getMsoRequest() == null);
+ networkRollback.setNetworkCreated(Boolean.TRUE);
+ assertTrue(networkRollback.getNetworkCreated());
+ networkRollback.setNetworkId("networkId");
+ assertTrue(networkRollback.getNetworkId().equalsIgnoreCase("networkId"));
+ networkRollback.setNetworkName("networkName");
+ assertTrue(networkRollback.getNetworkName().equalsIgnoreCase("networkName"));
+ networkRollback.setNetworkStackId("networkStackId");
+ assertTrue(networkRollback.getNetworkStackId().equalsIgnoreCase("networkStackId"));
+ networkRollback.setNetworkType("networkType");
+ assertTrue(networkRollback.getNetworkType().equalsIgnoreCase("networkType"));
+ networkRollback.setNeutronNetworkId("neutronNetworkId");
+ assertTrue(networkRollback.getNeutronNetworkId().equalsIgnoreCase("neutronNetworkId"));
+ networkRollback.setPhysicalNetwork("physicalNetwork");
+ assertTrue(networkRollback.getPhysicalNetwork().equalsIgnoreCase("physicalNetwork"));
+ networkRollback.setTenantId("tenantId");
+ assertTrue(networkRollback.getTenantId().equalsIgnoreCase("tenantId"));
+ List<Integer> al = new ArrayList<>();
+ al.add(1);
+ al.add(2);
+ networkRollback.setVlans(al);
+ assertTrue(networkRollback.getVlans() != null);
+ assertTrue(networkRollback.toString() != null);
+ }
+
+ @Test
+ public final void poolTest() {
+ Pool p = new Pool();
+ p.setStart("start");
+ p.getStart();
+ p.setEnd("end");
+ p.getEnd();
+ p.toString();
+ }
+
+ @Test
+ public final void stackInfoTest() {
+ StackInfo stackInfo = new StackInfo();
+ new StackInfo(new Stack());
+ new StackInfo("name", HeatStatus.CREATED, "statusmessage", new HashMap<>());
+ new StackInfo("name", HeatStatus.CREATED);
+ stackInfo.setCanonicalName("Canonicalname");
+ stackInfo.getCanonicalName();
+ stackInfo.setName("name");
+ stackInfo.getName();
+ stackInfo.setOutputs(new HashMap<>());
+ stackInfo.getOutputs();
+ stackInfo.setParameters(new HashMap<>());
+ stackInfo.getParameters();
+ stackInfo.setStatus(HeatStatus.CREATED);
+ stackInfo.getStatus();
+ stackInfo.setStatusMessage("statusMessage");
+ stackInfo.getStatusMessage();
+ }
+
+ @Test
+ public final void subnetTest() {
+ Subnet subnet = new Subnet();
+ subnet.setAllocationPools(new ArrayList<>());
+ subnet.getAllocationPools();
+ subnet.setCidr("cidr");
+ subnet.getCidr();
+ subnet.setDnsNameServers(new ArrayList<>());
+ subnet.getDnsNameServers();
+ subnet.setEnableDHCP(true);
+ subnet.getEnableDHCP();
+ subnet.setGatewayIp("gatewayIp");
+ subnet.getGatewayIp();
+ subnet.setHostRoutes(new ArrayList<>());
+ subnet.getHostRoutes();
+ subnet.setIpVersion("ipVersion");
+ subnet.getIpVersion();
+ subnet.setNeutronId("neutronId");
+ subnet.getNeutronId();
+ subnet.setSubnetId("subnetId");
+ subnet.getSubnetId();
+ subnet.setSubnetName("subnetName");
+ subnet.getSubnetName();
+ subnet.toString();
+ }
+
+ @Test
+ public final void vnfRollbackTest() {
+ VnfRollback vnfRollback = new VnfRollback();
+ new VnfRollback("vnfId", "tenantId", "cloudSiteId", true, true, new MsoRequest(), "volumeGroupName",
+ "volumeGroupId", "requestType", "modelCustomizationUuid");
+ vnfRollback.setBaseGroupHeatStackId("baseGroupHeatStackId");
+ vnfRollback.getBaseGroupHeatStackId();
+ vnfRollback.setCloudSiteId("cloudId");
+ vnfRollback.getCloudSiteId();
+ vnfRollback.setIsBase(false);
+ vnfRollback.isBase();
+ vnfRollback.setModelCustomizationUuid("modelCustomizationUuid");
+ vnfRollback.getModelCustomizationUuid();
+ vnfRollback.setMsoRequest(new MsoRequest());
+ vnfRollback.getMsoRequest();
+ vnfRollback.setRequestType("requestType");
+ vnfRollback.getRequestType();
+ vnfRollback.setTenantCreated(true);
+ vnfRollback.getTenantCreated();
+ vnfRollback.setTenantId("tenantId");
+ vnfRollback.getTenantId();
+ vnfRollback.setVfModuleStackId("vfModuleStackId");
+ vnfRollback.getVfModuleStackId();
+ vnfRollback.setVnfCreated(true);
+ vnfRollback.getVnfCreated();
+ vnfRollback.setVnfId("vnfId");
+ vnfRollback.getVnfId();
+ vnfRollback.setVolumeGroupHeatStackId("volumeGroupHeatStackId");
+ vnfRollback.getVolumeGroupHeatStackId();
+ vnfRollback.setVolumeGroupId("volumeGroupId");
+ vnfRollback.getVolumeGroupId();
+ vnfRollback.setVolumeGroupName("volumeGroupName");
+ vnfRollback.getVolumeGroupName();
+ vnfRollback.toString();
+ }
+}
diff --git a/asdc-controller/src/test/java/org/openecomp/mso/asdc/util/tests/ASDCNotificationLoggingTest.java b/asdc-controller/src/test/java/org/openecomp/mso/asdc/util/tests/ASDCNotificationLoggingTest.java
new file mode 100644
index 0000000000..1d65501ce2
--- /dev/null
+++ b/asdc-controller/src/test/java/org/openecomp/mso/asdc/util/tests/ASDCNotificationLoggingTest.java
@@ -0,0 +1,174 @@
+/*-
+ * ============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.asdc.util.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.openecomp.mso.asdc.installer.IVfModuleData;
+import org.openecomp.mso.asdc.installer.VfModuleMetaData;
+import org.openecomp.mso.asdc.util.ASDCNotificationLogging;
+import org.openecomp.sdc.api.notification.IArtifactInfo;
+import org.openecomp.sdc.api.notification.INotificationData;
+import org.openecomp.sdc.api.notification.IResourceInstance;
+
+public class ASDCNotificationLoggingTest {
+ @Test
+ public void dumpASDCNotificationTestForNull() throws Exception {
+ INotificationData asdcNotification = iNotificationDataObject();
+
+ String result = ASDCNotificationLogging.dumpASDCNotification(asdcNotification);
+
+ assertTrue(!result.equalsIgnoreCase("NULL"));
+ }
+
+ private INotificationData iNotificationDataObject() {
+ INotificationData iNotification = new INotificationData() {
+
+ @Override
+ public String getServiceVersion() {
+ return "DistributionID";
+ }
+
+ @Override
+ public String getServiceUUID() {
+ return "12343254";
+ }
+
+ @Override
+ public String getServiceName() {
+ return "servername";
+ }
+
+ @Override
+ public String getServiceInvariantUUID() {
+ return "ServiceInvariantUUID";
+ }
+
+ @Override
+ public String getServiceDescription() {
+ return "Description";
+ }
+
+ @Override
+ public List<IArtifactInfo> getServiceArtifacts() {
+ return new ArrayList();
+ }
+
+ @Override
+ public List<IResourceInstance> getResources() {
+ return new ArrayList();
+ }
+
+ @Override
+ public String getDistributionID() {
+ return "23434";
+ }
+
+ @Override
+ public IArtifactInfo getArtifactMetadataByUUID(String arg0) {
+ return null;
+ }
+ };
+ return iNotification;
+ }
+
+ @Test
+ public void dumpASDCNotificationTest() throws Exception {
+ INotificationData asdcNotification = iNotificationDataObject();
+ String result = ASDCNotificationLogging.dumpASDCNotification(asdcNotification);
+
+ assertTrue(!result.equalsIgnoreCase("NULL"));
+ }
+
+ @Test
+ public void dumpVfModuleMetaDataListTest() {
+ INotificationData asdcNotification = iNotificationDataObject();
+ List<IVfModuleData> list = new ArrayList<>();
+ list.add(new VfModuleMetaData());
+ String result = null;
+ try {
+ result = ASDCNotificationLogging.dumpVfModuleMetaDataList(list);
+ } catch (Exception e) {
+ }
+
+ assertTrue(result == null);
+
+ }
+
+ public IArtifactInfo getIArtifactInfo() {
+ return new IArtifactInfo() {
+
+ @Override
+ public List<IArtifactInfo> getRelatedArtifacts() {
+ return null;
+ }
+
+ @Override
+ public IArtifactInfo getGeneratedArtifact() {
+ return null;
+ }
+
+ @Override
+ public String getArtifactVersion() {
+ return "version";
+ }
+
+ @Override
+ public String getArtifactUUID() {
+ return "123";
+ }
+
+ @Override
+ public String getArtifactURL() {
+ return "url";
+ }
+
+ @Override
+ public String getArtifactType() {
+ return "type";
+ }
+
+ @Override
+ public Integer getArtifactTimeout() {
+ return 12;
+ }
+
+ @Override
+ public String getArtifactName() {
+ return "name";
+ }
+
+ @Override
+ public String getArtifactDescription() {
+ return "desc";
+ }
+
+ @Override
+ public String getArtifactChecksum() {
+ return "true";
+ }
+ };
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/ServiceInstanceTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/ServiceInstanceTest.java
index d1d8544763..08abf5702f 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/ServiceInstanceTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/openecomp/mso/apihandlerinfra/ServiceInstanceTest.java
@@ -21,6 +21,10 @@
package org.openecomp.mso.apihandlerinfra;
+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;
@@ -31,9 +35,19 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+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;
@@ -54,6 +68,383 @@ public class ServiceInstanceTest {
}
@Test
+ public void createServiceInstanceNormalDuplicate(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return new InfraActiveRequests();
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"service\",\"modelName\":\"serviceModel\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v2");
+ String respBody = resp.getEntity().toString();
+ assertTrue(respBody.indexOf("Locked instance - This service (testService) already has a request being worked with a status of null (RequestId - null). The existing request must finish or be cleaned up before proceeding.") != -1);
+ }
+
+ @Test
+ public void createServiceInstanceTestDBException(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String defaultServiceModelName) {
+ Service serviceRecord = new Service();
+ serviceRecord.setModelUUID("2883992993");
+ return serviceRecord;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID (String uuid,String action) {
+ ServiceRecipe recipe =new ServiceRecipe();
+ recipe.setOrchestrationUri("/test/mso");
+ recipe.setRecipeTimeout(1000);
+ return recipe;
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"service\",\"modelName\":\"serviceModel\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v2");
+ String respBody = resp.getEntity().toString();
+ assertTrue(respBody.indexOf("Exception while creating record in DB null") != -1);
+ }
+
+ @Test
+ public void createServiceInstanceTestBpmnFail(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String defaultServiceModelName) {
+ Service serviceRecord = new Service();
+ serviceRecord.setModelUUID("2883992993");
+ return serviceRecord;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID (String uuid,String action) {
+ ServiceRecipe recipe =new ServiceRecipe();
+ recipe.setOrchestrationUri("/test/mso");
+ recipe.setRecipeTimeout(1000);
+ return recipe;
+ }
+ };
+
+ new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord (Status status, Action action) {
+ return;
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"service\",\"modelName\":\"serviceModel\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v2");
+ String respBody = resp.getEntity().toString();
+ assertTrue(respBody.indexOf("Failed calling bpmn properties") != -1);
+ }
+
+ @Test(expected = Exception.class)
+ public void createServiceInstanceTest200Http(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String defaultServiceModelName) {
+ Service serviceRecord = new Service();
+ serviceRecord.setModelUUID("2883992993");
+ return serviceRecord;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID (String uuid,String action) {
+ ServiceRecipe recipe =new ServiceRecipe();
+ recipe.setOrchestrationUri("/test/mso");
+ recipe.setRecipeTimeout(1000);
+ return recipe;
+ }
+ };
+
+ new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord (Status status, Action action) {
+ return;
+ }
+ };
+
+ 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,200, "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;
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"service\",\"modelName\":\"serviceModel\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v2");
+ String respBody = resp.getEntity().toString();
+ }
+
+ @Test
+ public void createServiceInstanceTest500Http(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String defaultServiceModelName) {
+ Service serviceRecord = new Service();
+ serviceRecord.setModelUUID("2883992993");
+ return serviceRecord;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID (String uuid,String action) {
+ ServiceRecipe recipe =new ServiceRecipe();
+ recipe.setOrchestrationUri("/test/mso");
+ recipe.setRecipeTimeout(1000);
+ return recipe;
+ }
+ };
+
+ new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord (Status status, Action action) {
+ return;
+ }
+ };
+
+ 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;
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"service\",\"modelName\":\"serviceModel\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v2");
+ String respBody = resp.getEntity().toString();
+ assertTrue(respBody.indexOf("Request Failed due to BPEL error with HTTP Status") != -1);
+ }
+
+ @Test
+ public void createServiceInstanceTestVnfModelType(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String defaultServiceModelName) {
+ Service serviceRecord = new Service();
+ serviceRecord.setModelUUID("2883992993");
+ return serviceRecord;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID (String uuid,String action) {
+ ServiceRecipe recipe =new ServiceRecipe();
+ recipe.setOrchestrationUri("/test/mso");
+ recipe.setRecipeTimeout(1000);
+ return recipe;
+ }
+ };
+
+ new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord (Status status, Action action) {
+ return;
+ }
+ };
+
+ 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;
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"vnf\",\"modelName\":\"serviceModel\",\"modelCustomizationName\":\"test\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v5");
+ String respBody = resp.getEntity().toString();
+ assertTrue(respBody.indexOf("No valid modelVersionId is specified") != -1);
+ }
+
+ @Test
+ public void createServiceInstanceTestNullHttpResp(){
+ new MockUp<RequestsDatabase>() {
+ @Mock
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+ return null;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public Service getServiceByModelName (String defaultServiceModelName) {
+ Service serviceRecord = new Service();
+ serviceRecord.setModelUUID("2883992993");
+ return serviceRecord;
+ }
+ };
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ public ServiceRecipe getServiceRecipeByModelUUID (String uuid,String action) {
+ ServiceRecipe recipe =new ServiceRecipe();
+ recipe.setOrchestrationUri("/test/mso");
+ recipe.setRecipeTimeout(1000);
+ return recipe;
+ }
+ };
+
+ new MockUp<MsoRequest>() {
+ @Mock
+ public void createRequestRecord (Status status, Action action) {
+ return;
+ }
+ };
+
+ 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){
+ return null;
+ }
+ };
+ ServiceInstances instance = new ServiceInstances();
+ String requestJson = "{\"serviceInstanceId\":\"1882939\","
+ +"\"vnfInstanceId\":\"1882938\","
+ +"\"networkInstanceId\":\"1882937\","
+ +"\"volumeGroupInstanceId\":\"1882935\","
+ +"\"vfModuleInstanceId\":\"1882934\","
+ + "\"requestDetails\": {\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"zz9999\",\"instanceName\": \"testService\"},\"requestParameters\": { \"autoBuildVfModules\": false,\"subscriptionServiceType\": \"test\"},\"modelInfo\":{\"modelInvariantId\": \"557ea944-c83e-43cf-9ed7-3a354abd6d34\",\"modelVersion\":\"v2\",\"modelType\":\"service\",\"modelName\":\"serviceModel\"}}}";
+ Response resp = instance.createServiceInstance(requestJson, "v2");
+ String respBody = resp.getEntity().toString();
+ assertTrue(respBody.indexOf("bpelResponse is null") != -1);
+ }
+
+ @Test
public void createServiceInstanceNormalNullDBFatch(){
new MockUp<RequestsDatabase>() {
@Mock