summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-08-27 13:28:30 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-27 13:28:30 +0000
commitd96fcfe8117a72e26fb000c856692d35611aa629 (patch)
treefc278278b30c2c7d0ef30c71b107422d948c54d1 /mso-api-handlers/mso-api-handler-infra/src
parentbd557056cdc7a9754f15e4021194b0e7349668f0 (diff)
parent22c813992a18915f8874976d371ffb55d63930bf (diff)
Merge "request db access converted to rest"
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java1
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java1
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java176
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRunnable.java12
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java28
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java51
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java1
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java146
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java421
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java53
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java37
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java58
17 files changed, 385 insertions, 611 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java
index 923909e39b..8f8cf0898d 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java
@@ -61,6 +61,7 @@ import org.onap.so.db.request.beans.OperationStatus;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoAlarmLogger;
import org.onap.so.logger.MsoLogger;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.ModelType;
import org.onap.so.serviceinstancebeans.RequestDetails;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
index 66afcf3738..1a1b45ac8e 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
@@ -62,10 +62,10 @@ import org.onap.so.apihandlerinfra.vnfbeans.RequestStatusType;
import org.onap.so.apihandlerinfra.vnfbeans.VnfInputs;
import org.onap.so.apihandlerinfra.vnfbeans.VnfRequest;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
import org.onap.so.serviceinstancebeans.InstanceDirection;
import org.onap.so.serviceinstancebeans.ModelInfo;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
index 014739d581..753b4c48d4 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
@@ -52,6 +52,7 @@ import org.onap.so.exceptions.ValidationException;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoAlarmLogger;
import org.onap.so.logger.MsoLogger;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse;
import org.onap.so.serviceinstancebeans.GetOrchestrationResponse;
import org.onap.so.serviceinstancebeans.InstanceReferences;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
deleted file mode 100644
index 380ee2c6ad..0000000000
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. 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.onap.so.apihandlerinfra;
-
-import org.apache.http.HttpStatus;
-import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.beans.OperationStatus;
-import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.core.ParameterizedTypeReference;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.stereotype.Component;
-import org.springframework.web.client.HttpClientErrorException;
-import org.springframework.web.client.RestTemplate;
-import uk.co.blackpepper.bowman.Client;
-import uk.co.blackpepper.bowman.ClientFactory;
-import uk.co.blackpepper.bowman.Configuration;
-
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Component("RequestDbClient")
-public class RequestsDbClient {
-
- private static final String SERVICE_ID = "SERVICE_ID";
- private static final String OPERATION_ID = "OPERATION_ID";
-
- private Client<InfraActiveRequests> infraActiveRequestClient;
- private Client<OperationStatus> operationStatusClient;
-
- @Value("${mso.adapters.requestDb.endpoint}")
- private String endpoint;
-
- @Value("${mso.adapters.requestDb.auth}")
- private String msoAdaptersAuth;
-
- private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/";
- private static final String OPERATION_STATUS_REPOSITORY_SEARCH = "/operationStatusRepository/search";
-
- private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/";
-
- private String infraActiveRequestURI = "/infraActiveRequests/";
-
- private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate";
-
- private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId";
-
- private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive";
-
- private HttpHeaders headers;
-
- @Autowired
- private RestTemplate restTemplate;
-
- @PostConstruct
- public void init() {
- getOrchestrationFilterURI = endpoint + getOrchestrationFilterURI;
- infraActiveRequestURI = endpoint + infraActiveRequestURI;
- checkVnfIdStatus = endpoint + checkVnfIdStatus;
- checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate;
- cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive;
- findOneByServiceIdAndOperationIdURI = endpoint + OPERATION_STATUS_REPOSITORY_SEARCH + findOneByServiceIdAndOperationIdURI;
- headers = new HttpHeaders();
- headers.set("Authorization", msoAdaptersAuth);
- }
-
- public RequestsDbClient() {
- ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors().add((request, body, execution) -> {
- request.getHeaders().add("Authorization", msoAdaptersAuth);
- return execution.execute(request, body);
- })).build().buildClientFactory();
- infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class);
- operationStatusClient = clientFactory.create(OperationStatus.class);
-
- }
- public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){
- URI uri = getUri(cloudOrchestrationFiltersFromInfraActive);
- HttpEntity<Map> entity = new HttpEntity<>(orchestrationMap, headers);
- try{
- return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody();
- }catch(HttpClientErrorException e){
- if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){
- return null;
- }
- throw e;
- }
- }
- public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
- return this.getSingleInfraActiveRequests(this.getUri(endpoint + "/infraActiveRequests/" + requestId));
- }
-
- public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap) {
- URI uri = getUri(getOrchestrationFilterURI);
- HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(orchestrationMap, headers);
- return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody();
- }
-
- public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) {
- URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId);
- return restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody();
- }
- public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, String requestScope) {
- URI uri = getUri(checkInstanceNameDuplicate);
- HttpEntity<InstanceNameDuplicateCheckRequest> entity = new HttpEntity<>(new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers);
- try{
- return restTemplate.exchange(uri, HttpMethod.POST, entity, InfraActiveRequests.class).getBody();
- }catch(HttpClientErrorException e){
- if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){
- return null;
- }
- throw e;
- }
-
- }
-
- public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){
- return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI)
- .queryParam(SERVICE_ID,serviceId)
- .queryParam(OPERATION_ID,operationId)
- .build());
- }
-
- public void save(InfraActiveRequests infraActiveRequests) {
- URI uri = getUri(infraActiveRequestURI);
- HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(infraActiveRequests, headers);
- restTemplate.postForLocation(uri, entity);
- }
-
- protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) {
- return infraActiveRequestClient.get(uri);
- }
-
- public void updateInfraActiveRequests(InfraActiveRequests request) {
- infraActiveRequestClient.put(request);
- }
-
- public OperationStatus getSingleOperationStatus(URI uri){
- return operationStatusClient.get(uri);
- }
-
- protected URI getUri(String uri) {
- return URI.create(uri);
- }
-
- @Bean
- public RestTemplate restTemplate() {
- return new RestTemplate( new HttpComponentsClientHttpRequestFactory());
- }
-}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java
index 910b9f70cb..cfe32a3833 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java
@@ -40,7 +40,7 @@ import javax.ws.rs.core.Response;
import org.apache.http.HttpStatus;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandlerinfra.Constants;
-import org.onap.so.apihandlerinfra.RequestsDbClient;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.apihandlerinfra.Status;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException;
@@ -51,7 +51,6 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.OperationalEnvironment;
import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestReferences;
import org.onap.so.apihandlerinfra.tenantisolationbeans.TenantSyncResponse;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java
index a14554c8a1..3b7a326f3e 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java
@@ -44,7 +44,7 @@ import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandler.common.ResponseBuilder;
import org.onap.so.apihandlerinfra.Constants;
import org.onap.so.apihandlerinfra.Messages;
-import org.onap.so.apihandlerinfra.RequestsDbClient;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java
index b35b669208..b13008b3d3 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java
@@ -30,7 +30,7 @@ import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.lang3.StringUtils;
import org.onap.so.apihandlerinfra.Constants;
-import org.onap.so.apihandlerinfra.RequestsDbClient;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.apihandlerinfra.Status;
import org.onap.so.apihandlerinfra.tenantisolationbeans.Action;
import org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRunnable.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRunnable.java
index 461acab96d..2427dd2734 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRunnable.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRunnable.java
@@ -32,8 +32,6 @@ import org.onap.so.apihandlerinfra.tenantisolation.process.CreateVnfOperationalE
import org.onap.so.apihandlerinfra.tenantisolation.process.DeactivateVnfOperationalEnvironment;
import org.onap.so.apihandlerinfra.tenantisolationbeans.Action;
import org.onap.so.apihandlerinfra.tenantisolationbeans.OperationalEnvironment;
-import org.onap.so.db.request.data.repository.OperationalEnvDistributionStatusRepository;
-import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.onap.so.requestsdb.RequestsDBHelper;
@@ -46,7 +44,7 @@ import org.springframework.stereotype.Component;
@Scope("prototype")
public class TenantIsolationRunnable {
- private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, TenantIsolationRunnable.class);
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, TenantIsolationRunnable.class);
@Autowired
private RequestsDBHelper requestDb;
@@ -60,10 +58,6 @@ public class TenantIsolationRunnable {
private DeactivateVnfOperationalEnvironment deactivateVnfOpEnv;
@Autowired
private ActivateVnfStatusOperationalEnvironment activateVnfStatusOpEnv;
- @Autowired
- private OperationalEnvDistributionStatusRepository distributionStatusRepository;
- @Autowired
- private OperationalEnvServiceModelStatusRepository modelStatusRepository;
@Async
public void run(Action action, String operationalEnvType, CloudOrchestrationRequest cor, String requestId) throws ApiException {
@@ -83,11 +77,11 @@ public class TenantIsolationRunnable {
throw validateException;
}
} else if(Action.activate.equals(action)) {
- activateVnfOpEnv.execute(requestId, cor, distributionStatusRepository, modelStatusRepository);
+ activateVnfOpEnv.execute(requestId, cor);
} else if(Action.deactivate.equals(action)) {
deactivateVnfOpEnv.execute(requestId, cor);
} else if(Action.distributionStatus.equals(action)) {
- activateVnfStatusOpEnv.execute(requestId, cor, distributionStatusRepository, modelStatusRepository);
+ activateVnfStatusOpEnv.execute(requestId, cor);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder("Invalid Action specified: " + action,
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java
index 903639c8f5..e89b5c8d42 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java
@@ -21,13 +21,13 @@
package org.onap.so.apihandlerinfra.tenantisolation.process;
import java.util.List;
-import java.util.Optional;
import javax.ws.rs.core.Response;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.onap.so.apihandler.common.ErrorNumbers;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
@@ -40,8 +40,6 @@ import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.objects.AAIOperationalEnvironment;
import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
-import org.onap.so.db.request.data.repository.OperationalEnvDistributionStatusRepository;
-import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.onap.so.requestsdb.RequestsDBHelper;
@@ -53,7 +51,7 @@ import org.springframework.stereotype.Component;
@Component
public class ActivateVnfOperationalEnvironment {
- private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, ActivateVnfOperationalEnvironment.class);
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, ActivateVnfOperationalEnvironment.class);
private static final int DEFAULT_ACTIVATE_RETRY_COUNT = 3;
private static final String DISTRIBUTION_STATUS_SENT = "SENT";
@@ -69,16 +67,16 @@ public class ActivateVnfOperationalEnvironment {
@Value("${mso.tenant.isolation.retry.count}")
private String sdcRetryCount;
+ @Autowired
+ RequestsDbClient client;
+
/**
* The Point-Of-Entry from APIH with VID request to send activate request
* @param requestId - String
* @param request - CloudOrchestrationRequest object
- * @param distributionStatusRepository - OperationalEnvDistributionStatusRepository object
- * @param modelStatusRepository - OperationalEnvServiceModelStatusRepository object
* @return void - nothing
*/
- public void execute(String requestId, CloudOrchestrationRequest request, OperationalEnvDistributionStatusRepository distributionStatusRepository,
- OperationalEnvServiceModelStatusRepository modelStatusRepository) throws ApiException{
+ public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException{
String operationalEnvironmentId = request.getOperationalEnvironmentId();
String vidWorkloadContext = request.getRequestDetails().getRequestParameters().getWorkloadContext();
@@ -96,7 +94,7 @@ public class ActivateVnfOperationalEnvironment {
HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
- processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext, distributionStatusRepository, modelStatusRepository);
+ processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext);
}
@@ -107,13 +105,11 @@ public class ActivateVnfOperationalEnvironment {
* @param operationalEnvironmentId - String
* @param serviceModelVersionIdList - List<ServiceModelList> list
* @param workloadContext - String
- * @param distributionStatusRepository - OperationalEnvDistributionStatusRepository object
- * @param modelStatusRepository - OperationalEnvServiceModelStatusRepository object
* @return jsonResponse - JSONObject object
*/
- public void processActivateSDCRequest(String requestId, String operationalEnvironmentId, List<ServiceModelList> serviceModelVersionIdList,
- String workloadContext, OperationalEnvDistributionStatusRepository distributionStatusRepository,
- OperationalEnvServiceModelStatusRepository modelStatusRepository) throws ApiException {
+ public void processActivateSDCRequest(String requestId, String operationalEnvironmentId,
+ List<ServiceModelList> serviceModelVersionIdList,
+ String workloadContext) throws ApiException {
JSONObject jsonResponse = null;
int retryCount = 0;
@@ -137,7 +133,7 @@ public class ActivateVnfOperationalEnvironment {
recoveryAction,
retryCount,
workloadContext);
- modelStatusRepository.save(serviceModelStatus);
+ client.save(serviceModelStatus);
String distributionId = "";
@@ -154,7 +150,7 @@ public class ActivateVnfOperationalEnvironment {
requestId,
DISTRIBUTION_STATUS_SENT,
"");
- distributionStatusRepository.save(distStatus);
+ client.save(distStatus);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build();
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java
index 6a9bec5abb..6eb5157568 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java
@@ -28,6 +28,7 @@ import javax.ws.rs.core.Response;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.onap.so.apihandler.common.ErrorNumbers;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
@@ -38,8 +39,6 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution;
import org.onap.so.apihandlerinfra.tenantisolationbeans.DistributionStatus;
import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
-import org.onap.so.db.request.data.repository.OperationalEnvDistributionStatusRepository;
-import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.onap.so.requestsdb.RequestsDBHelper;
@@ -72,17 +71,16 @@ public class ActivateVnfStatusOperationalEnvironment {
private RequestsDBHelper requestDb;
@Autowired
private SDCClientHelper sdcClientHelper;
+ @Autowired
+ private RequestsDbClient client;
/**
* The Point-Of-Entry from APIH with activate status from SDC
* @param requestId - String
* @param request - CloudOrchestrationRequest - object
- * @param distributionStatusRepository - OperationalEnvDistributionStatusRepository - object
- * @param modelStatusRepository - OperationalEnvServiceModelStatusRepository - object
* @return void - nothing
*/
- public void execute(String requestId, CloudOrchestrationRequest request, OperationalEnvDistributionStatusRepository distributionStatusRepository,
- OperationalEnvServiceModelStatusRepository modelStatusRepository) throws ApiException {
+ public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
String operationalEnvironmentId = "";
@@ -91,18 +89,18 @@ public class ActivateVnfStatusOperationalEnvironment {
Distribution sdcStatus = request.getDistribution();
// Distribution, Query for operationalEnvironmentId, serviceModelVersionId
- this.queryDistributionDbResponse = distributionStatusRepository.findOne(sdcDistributionId);
+ this.queryDistributionDbResponse = client.getDistributionStatusById(sdcDistributionId);
operationalEnvironmentId = this.queryDistributionDbResponse.getOperationalEnvId();
// ServiceModel, Query for dbRequestId, recoveryAction, retryCountString
- this.queryServiceModelResponse = modelStatusRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, queryDistributionDbResponse.getServiceModelVersionId());
+ this.queryServiceModelResponse = client.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, queryDistributionDbResponse.getServiceModelVersionId());
this.origRequestId = this.queryServiceModelResponse.getRequestId();
- processActivateSDCStatus(sdcDistributionId, sdcStatus, this.queryDistributionDbResponse, this.queryServiceModelResponse, distributionStatusRepository, modelStatusRepository);
+ processActivateSDCStatus(sdcDistributionId, sdcStatus, this.queryDistributionDbResponse, this.queryServiceModelResponse);
// After EVERY status processed, need to query the status of all service modelId
// to determine the OVERALL status if "COMPLETE" or "FAILURE":
- checkOrUpdateOverallStatus(operationalEnvironmentId, this.origRequestId, modelStatusRepository);
+ checkOrUpdateOverallStatus(operationalEnvironmentId, this.origRequestId);
}
@@ -112,13 +110,10 @@ public class ActivateVnfStatusOperationalEnvironment {
* @param sdcStatus - Distribution object
* @param queryDistributionDbResponse - OperationalEnvDistributionStatus object
* @param queryServiceModelResponse - OperationalEnvServiceModelStatus object
- * @param distributionStatusRepository - OperationalEnvDistributionStatusRepository object
- * @param modelStatusRepository - OperationalEnvServiceModelStatusRepository object
* @return void - nothing
*/
public void processActivateSDCStatus(String sdcDistributionId, Distribution sdcStatus, OperationalEnvDistributionStatus queryDistributionDbResponse,
- OperationalEnvServiceModelStatus queryServiceModelResponse, OperationalEnvDistributionStatusRepository distributionStatusRepository,
- OperationalEnvServiceModelStatusRepository modelStatusRepository) throws ApiException {
+ OperationalEnvServiceModelStatus queryServiceModelResponse) throws ApiException {
String sdcStatusValue = sdcStatus.getStatus().toString();
String recoveryAction = queryServiceModelResponse.getRecoveryAction();
@@ -131,13 +126,13 @@ public class ActivateVnfStatusOperationalEnvironment {
dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse,
sdcStatusValue,
"");
- distributionStatusRepository.save(updateDistStatusOk);
+ client.save(updateDistStatusOk);
// should update 1 row, update status and retryCount = 0 (ie, serviceModelVersionId is DONE!)
OperationalEnvServiceModelStatus updateRetryCountZeroAndStatusOk =
dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse,
sdcStatusValue,
RETRY_COUNT_ZERO);
- modelStatusRepository.save(updateRetryCountZeroAndStatusOk);
+ client.save(updateRetryCountZeroAndStatusOk);
} else {
// "DISTRIBUTION_COMPLETE_ERROR", Check if recoveryAction is "RETRY"
@@ -145,8 +140,7 @@ public class ActivateVnfStatusOperationalEnvironment {
// RESEND / RETRY serviceModelVersionId to SDC
- JSONObject jsonResponse = callSDClientForRetry(queryDistributionDbResponse, queryServiceModelResponse, sdcStatus,
- distributionStatusRepository, modelStatusRepository);
+ JSONObject jsonResponse = callSDClientForRetry(queryDistributionDbResponse, queryServiceModelResponse, sdcStatus);
} else { // either RETRY & Count = 0, or 'ABORT', or 'SKIP'
@@ -168,13 +162,13 @@ public class ActivateVnfStatusOperationalEnvironment {
dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse,
modifiedStatus,
RETRY_COUNT_ZERO);
- modelStatusRepository.save(updateRetryCountZeroAndStatus);
+ client.save(updateRetryCountZeroAndStatus);
// should update 1 row, modified status
OperationalEnvDistributionStatus updateDistStatus =
dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse,
modifiedStatus,
errorReason);
- distributionStatusRepository.save(updateDistStatus);
+ client.save(updateDistStatus);
} else {
// RETRY & Count = 0 (do nothing!)
}
@@ -187,15 +181,11 @@ public class ActivateVnfStatusOperationalEnvironment {
* @param queryDistributionDbResponse - OperationalEnvDistributionStatus object
* @param queryServiceModelResponse - OperationalEnvServiceModelStatus object
* @param sdcStatus - Distribution object
- * @param distributionStatusRepository - OperationalEnvDistributionStatusRepository object
- * @param modelStatusRepository - OperationalEnvServiceModelStatusRepository object
* @return JSONObject object
*/
public JSONObject callSDClientForRetry(OperationalEnvDistributionStatus queryDistributionDbResponse,
OperationalEnvServiceModelStatus queryServiceModelResponse,
- Distribution sdcStatus,
- OperationalEnvDistributionStatusRepository distributionStatusRepository,
- OperationalEnvServiceModelStatusRepository modelStatusRepository) throws ApiException {
+ Distribution sdcStatus) throws ApiException {
JSONObject jsonResponse = null;
@@ -218,7 +208,7 @@ public class ActivateVnfStatusOperationalEnvironment {
originalRequestId,
DISTRIBUTION_STATUS_SENT,
"");
- distributionStatusRepository.save(insertNewDistributionId);
+ client.save(insertNewDistributionId);
// update retryCount (less 1) for the serviceModelServiceId
retryCount = retryCount - 1;
@@ -227,14 +217,14 @@ public class ActivateVnfStatusOperationalEnvironment {
dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse,
DISTRIBUTION_STATUS_SENT,
retryCount);
- modelStatusRepository.save(updateRetryCountAndStatus);
+ client.save(updateRetryCountAndStatus);
// should update 1 row, OLD distributionId set to status error (ie, old distributionId is DONE!).
OperationalEnvDistributionStatus updateStatus =
dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse,
DISTRIBUTION_STATUS_ERROR,
sdcStatus.getErrorReason());
- distributionStatusRepository.save(updateStatus);
+ client.save(updateStatus);
} else {
String dbErrorMessage = "Failure calling SDC: statusCode: " + statusCode +
"; messageId: " + jsonResponse.get("messageId") +
@@ -255,12 +245,11 @@ public class ActivateVnfStatusOperationalEnvironment {
* The Method to check the overall status of the Activation for an operationalEnvironmentId
* @param operationalEnvironmentId - string
* @param origRequestId - string
- * @param modelStatusRepository - OperationalEnvServiceModelStatusRepository object
* @return void - nothing
*/
- public void checkOrUpdateOverallStatus(String operationalEnvironmentId, String origRequestId, OperationalEnvServiceModelStatusRepository modelStatusRepository) throws ApiException{
+ public void checkOrUpdateOverallStatus(String operationalEnvironmentId, String origRequestId) throws ApiException{
- List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = modelStatusRepository.findAllByOperationalEnvIdAndRequestId(operationalEnvironmentId, origRequestId);
+ List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = client.getAllByOperationalEnvIdAndRequestId(operationalEnvironmentId, origRequestId);
String status = "Waiting";
int count = 0;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
index a63b778a1f..5932f6d206 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
@@ -187,7 +187,7 @@ private final ObjectMapper mapper = new ObjectMapper();
OperationStatus status = new OperationStatus();
status.setOperationId("operationId");
status.setServiceId("9b9f02c0-298b-458a-bc9c-be3692e4f35e");
- stubFor(get(urlPathEqualTo("/operationStatusRepository/search/findOneByServiceIdAndOperationId"))
+ stubFor(get(urlPathEqualTo("/operationStatus/search/findOneByServiceIdAndOperationId"))
.willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.withBody(mapper.writeValueAsString(status))
.withStatus(HttpStatus.SC_OK)));
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
index de7f560020..582bc12077 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
@@ -31,6 +31,7 @@ import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
+import org.onap.so.requestsdb.client.RequestsDbClient;
import org.onap.so.serviceinstancebeans.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java
index 3c991ef0c5..c36eb2b063 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironmentTest.java
@@ -25,70 +25,81 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onap.so.apihandlerinfra.BaseTest;
+import org.onap.so.apihandlerinfra.exceptions.ApiException;
+import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
import org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.RecoveryAction;
import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails;
import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestParameters;
import org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList;
+import org.onap.so.apihandlerinfra.tenantisolationbeans.RecoveryAction;
+import org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest;
import org.onap.so.client.aai.AAIVersion;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.objects.AAIOperationalEnvironment;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
-import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
-import org.onap.so.db.request.data.repository.OperationalEnvDistributionStatusRepository;
-import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
import org.springframework.beans.factory.annotation.Autowired;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
- @Autowired
- private OperationalEnvDistributionStatusRepository distributionDbRepository;
- @Autowired
- private OperationalEnvServiceModelStatusRepository serviceModelDbRepository;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Autowired
private ActivateVnfOperationalEnvironment activateVnf;
@Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
- @Autowired
private AAIClientHelper clientHelper;
- String requestId = "TEST_requestId";
- String operationalEnvironmentId = "EMOE-001";
- CloudOrchestrationRequest request = new CloudOrchestrationRequest();
- String workloadContext = "PVT";
+ private final String requestId = "TEST_requestId";
+ private final String operationalEnvironmentId = "1dfe7154-eae0-44f2-8e7a-8e5e7882e55d";
+ private final CloudOrchestrationRequest request = new CloudOrchestrationRequest();
+ private final String workloadContext = "PVT";
String recoveryActionRetry = "RETRY";
- String serviceModelVersionId = "TEST_serviceModelVersionId";
+ private final String serviceModelVersionId = "TEST_serviceModelVersionId";
int retryCount = 3;
- String sdcDistributionId = "TEST_distributionId";
- String statusSent = "SENT";
-
- @After
- public void after() throws Exception {
- distributionDbRepository.deleteAll();
- serviceModelDbRepository.deleteAll();
+ private final String sdcDistributionId = "TEST_distributionId";
+ private final String statusSent = "SENT";
+ private final ObjectMapper mapper = new ObjectMapper();
+
+ @Before
+ public void init(){
+ stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/"))
+ .withRequestBody(equalTo("{\"requestId\":\"TEST_requestId\",\"operationalEnvId\":\"1dfe7154-eae0-44f2-8e7a-8e5e7882e55d\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":3,\"workloadContext\":\"PVT\",\"createTime\":null,\"modifyTime\":null}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/"))
+ .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"1dfe7154-eae0-44f2-8e7a-8e5e7882e55d\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestId\",\"distributionIdStatus\":\"SENT\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
}
+
@Test
- public void getAAIOperationalEnvironmentTest() throws Exception {
+ public void getAAIOperationalEnvironmentTest() {
- AAIOperationalEnvironment aaiOpEnv = null;
+ AAIOperationalEnvironment aaiOpEnv;
stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/ecompOperationalEnvironment.json").withStatus(HttpStatus.SC_ACCEPTED)));
@@ -104,7 +115,7 @@ public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
@Test
public void executionTest() throws Exception {
- List<ServiceModelList> serviceModelVersionIdList = new ArrayList<ServiceModelList>();
+ List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
ServiceModelList serviceModelList1 = new ServiceModelList();
serviceModelList1.setRecoveryAction(RecoveryAction.retry);
serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
@@ -130,22 +141,7 @@ public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/ecompOperationalEnvironment.json").withStatus(HttpStatus.SC_ACCEPTED)));
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
-
-
- activateVnf.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
-
- // insert record, status sent
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusSent, distStatus.getDistributionIdStatus());
-
- // insert record, status sent
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(statusSent, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
-
+ activateVnf.execute(requestId, request);
}
@Test
@@ -159,7 +155,7 @@ public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
jsonObject.put("distributionId", distributionId);
// prepare request detail
- List<ServiceModelList> serviceModelVersionIdList = new ArrayList<ServiceModelList>();
+ List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
ServiceModelList serviceModelList1 = new ServiceModelList();
serviceModelList1.setRecoveryAction(RecoveryAction.retry);
serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
@@ -168,25 +164,11 @@ public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
- activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext,
- distributionDbRepository, serviceModelDbRepository);
-
- // insert record, status sent
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusSent, distStatus.getDistributionIdStatus());
-
- // insert record, status sent
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(statusSent, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
-
+ activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext);
}
- @Test
- public void processActivateSDCRequestTest_409() throws Exception {
+ @Test
+ public void processActivateSDCRequestTest_409() throws ApiException, JsonProcessingException {
// ERROR in asdc
JSONObject jsonMessages = new JSONObject();
@@ -200,7 +182,7 @@ public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
jsonErrorResponse.put("requestError", jsonServException);
// prepare request detail
- List<ServiceModelList> serviceModelVersionIdList = new ArrayList<ServiceModelList>();
+ List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
ServiceModelList serviceModelList1 = new ServiceModelList();
serviceModelList1.setRecoveryAction(RecoveryAction.retry);
serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
@@ -209,30 +191,20 @@ public class ActivateVnfOperationalEnvironmentTest extends BaseTest{
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestId);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
-
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonErrorResponse.toString()).withStatus(HttpStatus.SC_CONFLICT)));
-
- try {
- activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext,
- distributionDbRepository, serviceModelDbRepository);
-
- } catch (Exception ex) {
-
- // insert record, status sent
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(statusSent, servStatus.getServiceModelVersionDistrStatus());
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestId);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("FAILURE"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("FAILED"));
-
- }
-
- infraActiveRequestsRepository.delete(requestId);
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("operationalEnvId\":\"1dfe7154-eae0-44f2-8e7a-8e5e7882e55d\""))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ thrown.expect(ValidateException.class);
+
+ activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext);
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java
index 3dcac0da18..eba90496ba 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java
@@ -21,22 +21,27 @@
package org.onap.so.apihandlerinfra.tenantisolation.process;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Ignore;
import org.junit.Rule;
+import org.junit.After;
import org.junit.Test;
+import org.junit.Ignore;
import org.junit.rules.ExpectedException;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandlerinfra.BaseTest;
@@ -54,13 +59,12 @@ import org.onap.so.db.request.data.repository.OperationalEnvDistributionStatusRe
import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository;
import org.springframework.beans.factory.annotation.Autowired;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
@Autowired
- private OperationalEnvDistributionStatusRepository distributionDbRepository;
- @Autowired
- private OperationalEnvServiceModelStatusRepository serviceModelDbRepository;
- @Autowired
private ActivateVnfStatusOperationalEnvironment activateVnfStatus;
@Autowired
private InfraActiveRequestsRepository infraActiveRequestsRepository;
@@ -69,30 +73,26 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
@Rule
public ExpectedException thrown = ExpectedException.none();
- private String requestId = "TEST_requestId";
- private String requestIdOrig = "TEST_requestIdOrig";
- private String operationalEnvironmentId = "TEST_operationalEnvironmentId";
- private CloudOrchestrationRequest request = new CloudOrchestrationRequest();
- private String workloadContext = "TEST_workloadContext";
- private String recoveryActionRetry = "RETRY";
- private String recoveryActionAbort = "ABORT";
- private String recoveryActionSkip = "SKIP";
- private String serviceModelVersionId = "TEST_serviceModelVersionId";
- private String serviceModelVersionId1 = "TEST_serviceModelVersionId1";
- private int retryCountThree = 3;
- private int retryCountTwo = 2;
- private int retryCountZero = 0;
- private String sdcDistributionId = "TEST_distributionId";
- private String sdcDistributionId1 = "TEST_distributionId1";
- private String statusOk = Status.DISTRIBUTION_COMPLETE_OK.toString();
- private String statusError = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
- private String statusSent = "SENT";
-
- @After
- public void after() throws Exception {
- distributionDbRepository.deleteAll();
- serviceModelDbRepository.deleteAll();
- }
+ private final String requestId = "TEST_requestId";
+ private final String requestIdOrig = "TEST_requestIdOrig";
+ private final String operationalEnvironmentId = "TEST_operationalEnvironmentId";
+ private final CloudOrchestrationRequest request = new CloudOrchestrationRequest();
+ private final String workloadContext = "TEST_workloadContext";
+ private final String recoveryActionRetry = "RETRY";
+ private final String recoveryActionAbort = "ABORT";
+ private final String recoveryActionSkip = "SKIP";
+ private final String serviceModelVersionId = "TEST_serviceModelVersionId";
+ private final String serviceModelVersionId1 = "TEST_serviceModelVersionId1";
+ private final int retryCountThree = 3;
+ private final int retryCountTwo = 2;
+ private final int retryCountZero = 0;
+ private final String sdcDistributionId = "TEST_distributionId";
+ private final String sdcDistributionId1 = "TEST_distributionId1";
+ private final String statusOk = Status.DISTRIBUTION_COMPLETE_OK.toString();
+ private final String statusError = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString();
+ private final String statusSent = "SENT";
+
+ private final ObjectMapper mapper = new ObjectMapper();
@Test
public void checkOrUpdateOverallStatusTest_Ok() throws Exception {
@@ -106,7 +106,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountZero);
serviceModelDb.setServiceModelVersionDistrStatus(statusOk);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
serviceModelDb.setRequestId(requestIdOrig);
serviceModelDb.setServiceModelVersionId(serviceModelVersionId1);
@@ -115,27 +114,27 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountZero);
serviceModelDb.setServiceModelVersionDistrStatus(statusOk);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
-
+
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
+
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
- activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig, serviceModelDbRepository);
+ activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig);
// overall is success
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESSFUL"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("COMPLETE"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
}
@Test
- public void checkOrUpdateOverallStatusTest_Error() throws Exception {
+ public void checkOrUpdateOverallStatusTest_Error() throws JsonProcessingException {
OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
serviceModelDb.setRequestId(requestIdOrig);
@@ -145,29 +144,28 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountZero);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
+
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
try {
- activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig, serviceModelDbRepository);
+ activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig);
}catch(ApiException e){
assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
}
- // overall is failure
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("FAILURE"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("FAILED"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
}
@Test
@@ -181,9 +179,12 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountTwo);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
- activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig, serviceModelDbRepository);
+ activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig);
// do nothing, waiting for more
assertNull(infraActiveRequestsRepository.findOne(requestIdOrig));
@@ -200,7 +201,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountThree);
serviceModelDb.setServiceModelVersionDistrStatus(statusSent);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
distributionDb.setDistributionId(sdcDistributionId);
@@ -209,9 +209,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
distributionDb.setDistributionIdStatus(statusSent);
distributionDb.setServiceModelVersionId(serviceModelVersionId);
distributionDb.setDistributionIdErrorReason(null);
- distributionDbRepository.saveAndFlush(distributionDb);
-
-
// prepare distribution obj
Distribution distribution = new Distribution();
@@ -223,32 +220,30 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
-
- activateVnfStatus.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
-
- // status ok
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusOk, distStatus.getDistributionIdStatus());
- assertEquals("", distStatus.getDistributionIdErrorReason());
-
- // status ok
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
- assertEquals(statusOk, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(new Integer(retryCountZero), servStatus.getRetryCount());
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESSFUL"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("COMPLETE"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/"+sdcDistributionId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(distributionDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/"))
+ .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"RETRY\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/"))
+ .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ activateVnfStatus.execute(requestId, request);
}
@Test
@@ -262,7 +257,10 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountThree);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
distributionDb.setDistributionId(sdcDistributionId);
@@ -271,7 +269,7 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
distributionDb.setDistributionIdStatus(statusError);
distributionDb.setServiceModelVersionId(serviceModelVersionId);
distributionDb.setDistributionIdErrorReason(null);
- distributionDbRepository.saveAndFlush(distributionDb);
+
@@ -291,37 +289,34 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/"+sdcDistributionId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(distributionDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/"))
+ .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_ERROR\",\"distributionIdErrorReason\":\"Unable to process.\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/"))
+ .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId1\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"SENT\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/"))
+ .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
- activateVnfStatus.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
-
- // old distributionId, status error
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusError, distStatus.getDistributionIdStatus());
- assertEquals("Unable to process.", distStatus.getDistributionIdErrorReason());
-
- // new distributionId, status sent
- OperationalEnvDistributionStatus newDistStatus = distributionDbRepository.findOne(sdcDistributionId1);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, newDistStatus.getOperationalEnvId());
- assertEquals(statusSent, newDistStatus.getDistributionIdStatus());
- assertEquals("", newDistStatus.getDistributionIdErrorReason());
-
- // count is less 1, status sent
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
- assertEquals(statusSent, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(new Integer(retryCountTwo), servStatus.getRetryCount());
-
- // no update
- assertNull(infraActiveRequestsRepository.findOne(requestIdOrig));
-
+ activateVnfStatus.execute(requestId, request);
}
@Test
- public void executionTest_ERROR_Status_And_RETRY_And_RetryZero() throws Exception {
+ public void executionTest_ERROR_Status_And_RETRY_And_RetryZero() throws JsonProcessingException {
OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
serviceModelDb.setRequestId(requestIdOrig);
@@ -331,7 +326,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountZero);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
distributionDb.setDistributionId(sdcDistributionId);
@@ -340,7 +334,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
distributionDb.setDistributionIdStatus(statusError);
distributionDb.setServiceModelVersionId(serviceModelVersionId);
distributionDb.setDistributionIdErrorReason(null);
- distributionDbRepository.saveAndFlush(distributionDb);
@@ -359,44 +352,41 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
+
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/"+sdcDistributionId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(distributionDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
+ stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/"))
+ .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
try {
- activateVnfStatus.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
+ activateVnfStatus.execute(requestId, request);
}catch(ApiException e){
assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
}
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusError, distStatus.getDistributionIdStatus());
- assertEquals(null, distStatus.getDistributionIdErrorReason());
-
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
- assertEquals(statusError, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(new Integer(retryCountZero), servStatus.getRetryCount());
-
- // Retry count is zero, no more retry. all retry failed.
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("FAILURE"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("FAILED"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
}
@Test
- public void executionTest_ERROR_Status_And_RETRY_And_ErrorSdc() throws Exception {
+ public void executionTest_ERROR_Status_And_RETRY_And_ErrorSdc() throws JsonProcessingException {
OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
serviceModelDb.setRequestId(requestIdOrig);
@@ -406,7 +396,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountThree);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
distributionDb.setDistributionId(sdcDistributionId);
@@ -415,7 +404,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
distributionDb.setDistributionIdStatus(statusError);
distributionDb.setServiceModelVersionId(serviceModelVersionId);
distributionDb.setDistributionIdErrorReason(null);
- distributionDbRepository.saveAndFlush(distributionDb);
@@ -441,41 +429,33 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/"+sdcDistributionId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(distributionDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("operationalEnvId\":\"TEST_operationalEnvironmentId\""))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonMessages.toString()).withStatus(HttpStatus.SC_CONFLICT)));
try {
- activateVnfStatus.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
+ activateVnfStatus.execute(requestId, request);
}catch(ApiException e){
assertThat(e.getMessage(), startsWith("Failure calling SDC: statusCode: "));
assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
}
- // status as-is / no changes
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusError, distStatus.getDistributionIdStatus());
- assertEquals(null, distStatus.getDistributionIdErrorReason());
-
- // status as-is / no changes
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
- assertEquals(statusError, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(new Integer(retryCountThree), servStatus.getRetryCount());
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("FAILURE"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("FAILED"));
- assertTrue(infraActiveRequest.getStatusMessage().contains("Undefined Error Message!"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
-
}
@Test
@@ -489,8 +469,7 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountThree);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
-
+
OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
distributionDb.setDistributionId(sdcDistributionId);
distributionDb.setRequestId(requestIdOrig);
@@ -498,36 +477,48 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
distributionDb.setDistributionIdStatus(statusError);
distributionDb.setServiceModelVersionId(serviceModelVersionId);
distributionDb.setDistributionIdErrorReason(null);
- distributionDbRepository.saveAndFlush(distributionDb);
-
-
// prepare distribution obj
+ OperationalEnvDistributionStatus distributionStatus = new OperationalEnvDistributionStatus(sdcDistributionId,operationalEnvironmentId,serviceModelVersionId);
+ distributionStatus.setDistributionIdStatus(Status.DISTRIBUTION_COMPLETE_ERROR.name());
+
Distribution distribution = new Distribution();
distribution.setStatus(Status.DISTRIBUTION_COMPLETE_ERROR);
request.setDistribution(distribution);
request.setDistributionId(sdcDistributionId);
request.setOperationalEnvironmentId(operationalEnvironmentId);
-
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
- activateVnfStatus.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/"+sdcDistributionId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(distributionDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/"))
+ .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"SKIP\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/"))
+ .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ activateVnfStatus.execute(requestId, request);
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESSFUL"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("COMPLETE"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
-
}
@Test
- public void executionTest_ERROR_Status_And_ABORT() throws Exception {
+ public void executionTest_ERROR_Status_And_ABORT() throws JsonProcessingException {
OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
serviceModelDb.setRequestId(requestIdOrig);
@@ -537,7 +528,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountThree);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
- serviceModelDbRepository.saveAndFlush(serviceModelDb);
OperationalEnvDistributionStatus distributionDb = new OperationalEnvDistributionStatus();
distributionDb.setDistributionId(sdcDistributionId);
@@ -546,7 +536,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
distributionDb.setDistributionIdStatus(statusError);
distributionDb.setServiceModelVersionId(serviceModelVersionId);
distributionDb.setDistributionIdErrorReason(null);
- distributionDbRepository.saveAndFlush(distributionDb);
@@ -560,23 +549,36 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
- infraActiveRequestsRepository.saveAndFlush(iar);
+ stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceModelDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/operationalEnvDistributionStatus/"+sdcDistributionId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(distributionDb))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestIdOrig))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/"))
+ .withRequestBody(containing("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_ERROR\""))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/"))
+ .withRequestBody(containing("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_ERROR\""))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
try {
- activateVnfStatus.execute(requestId, request, distributionDbRepository, serviceModelDbRepository);
- }catch(ApiException e){
- assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
- assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
- assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
- }
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestIdOrig);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("FAILURE"));
- assertTrue(infraActiveRequest.getRequestStatus().contains("FAILED"));
-
- // cleanup
- infraActiveRequestsRepository.delete(requestIdOrig);
+ activateVnfStatus.execute(requestId, request);
+ }catch(ApiException e) {
+ assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
+ assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
+ assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
+ }
}
@@ -617,24 +619,11 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{
stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
- JSONObject jsonResponse = activateVnfStatus.callSDClientForRetry(distributionDb, serviceModelDb, distribution,
- distributionDbRepository, serviceModelDbRepository);
+ JSONObject jsonResponse = activateVnfStatus.callSDClientForRetry(distributionDb, serviceModelDb, distribution);
assertEquals("TEST_distributionId1", jsonResponse.get("distributionId"));
assertEquals("Success", jsonResponse.get("message"));
assertEquals("202", jsonResponse.get("statusCode"));
- // insert new record, status sent
- OperationalEnvDistributionStatus distStatus = distributionDbRepository.findOne(sdcDistributionId1);
- assertNotNull(distStatus);
- assertEquals(operationalEnvironmentId, distStatus.getOperationalEnvId());
- assertEquals(statusSent, distStatus.getDistributionIdStatus());
-
- // insert new record, status sent
- OperationalEnvServiceModelStatus servStatus = serviceModelDbRepository.findOneByOperationalEnvIdAndServiceModelVersionId(operationalEnvironmentId, serviceModelVersionId);
- assertNotNull(servStatus);
- assertEquals(statusSent, servStatus.getServiceModelVersionDistrStatus());
- assertEquals(operationalEnvironmentId, servStatus.getOperationalEnvId());
-
- }
+ }
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java
index d64cf6106a..0ace9d5445 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java
@@ -20,16 +20,12 @@
package org.onap.so.apihandlerinfra.tenantisolation.process;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.post;
-import static com.github.tomakehurst.wiremock.client.WireMock.put;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpStatus;
import org.junit.Test;
import org.onap.so.apihandler.common.ErrorNumbers;
@@ -44,19 +40,20 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestInfo;
import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestParameters;
import org.onap.so.client.aai.AAIVersion;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
public class CreateEcompOperationalEnvironmentTest extends BaseTest{
@Autowired
private CreateEcompOperationalEnvironment createEcompOpEn;
- @Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
-
+ private final ObjectMapper mapper = new ObjectMapper();
+
public CloudOrchestrationRequest getCloudOrchestrationRequest() {
CloudOrchestrationRequest request = new CloudOrchestrationRequest();
RequestDetails reqDetails = new RequestDetails();
@@ -75,7 +72,7 @@ public class CreateEcompOperationalEnvironmentTest extends BaseTest{
}
@Test
- public void testProcess() throws ApiException {
+ public void testProcess() throws ApiException, JsonProcessingException {
stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
stubFor(post(urlPathMatching("/events/.*"))
@@ -87,18 +84,20 @@ public class CreateEcompOperationalEnvironmentTest extends BaseTest{
iar.setRequestScope("create");
iar.setRequestStatus("PENDING");
iar.setRequestAction("UNKNOWN");
- infraActiveRequestsRepository.saveAndFlush(iar);
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/123"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("{\"requestId\":\"123\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"COMPLETE\",\"statusMessage\":\"SUCCESSFUL, operationalEnvironmentId - operationalEnvId; Success Message: SUCCESSFULLY Created ECOMP OperationalEnvironment.\",\"progress\":100"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
createEcompOpEn.execute("123", getCloudOrchestrationRequest());
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOneByRequestId("123");
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESS"));
- assertTrue(infraActiveRequest.getRequestStatus().equals("COMPLETE"));
}
@Test
- public void testProcessException() {
+ public void testProcessException() throws JsonProcessingException {
stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
stubFor(post(urlPathMatching("/events/.*"))
@@ -113,18 +112,20 @@ public class CreateEcompOperationalEnvironmentTest extends BaseTest{
iar.setRequestScope("create");
iar.setRequestStatus("PENDING");
iar.setRequestAction("UNKNOWN");
- infraActiveRequestsRepository.saveAndFlush(iar);
-
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/123"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("{\"requestId\":\"123\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"FAILED\",\"statusMessage\":\"FAILURE, operationalEnvironmentId - operationalEnvId; Error message: empty"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
try {
createEcompOpEn.execute("123", getCloudOrchestrationRequest());
}catch(ApiException e){
assertThat(e, sameBeanAs((ApiException) expectedException).ignoring("cause"));
}
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOneByRequestId("123");
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("FAILURE"));
- assertTrue(infraActiveRequest.getRequestStatus().equals("FAILED"));
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java
index 8fe40f31a4..1dfafce40c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java
@@ -20,21 +20,15 @@
package org.onap.so.apihandlerinfra.tenantisolation.process;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.post;
-import static com.github.tomakehurst.wiremock.client.WireMock.put;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.UUID;
+import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.http.HttpStatus;
import org.junit.Before;
import org.junit.Test;
@@ -51,6 +45,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
public class CreateVnfOperationalEnvironmentTest extends BaseTest{
@@ -59,9 +56,7 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{
@Autowired
private CreateVnfOperationalEnvironment createVnfOpEnv;
- @Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
-
+
@Before
public void testSetUp() throws Exception {
ObjectMapper mapper = new ObjectMapper();
@@ -70,7 +65,6 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{
String jsonServiceEndpoints = getFileContentsAsString("__files/vnfoperenv/endpoints.json");
serviceEndpoints = mapper.readValue(jsonServiceEndpoints, ServiceEndPointList.class);
}
-
@Test
public void testGetEcompManagingEnvironmentId() throws Exception {
createVnfOpEnv.setRequest(request);
@@ -84,7 +78,7 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{
}
@Test
- public void testGetEnvironmentName() throws Exception {
+ public void testGetEnvironmentName() {
createVnfOpEnv.setRequest(request);
List<Property> props = serviceEndpoints.getServiceEndPointList().get(0).getProperties();
assertEquals("DEV", createVnfOpEnv.getEnvironmentName(props));
@@ -120,7 +114,7 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{
}
@Test
- public void testExecute() throws ApiException{
+ public void testExecute() throws ApiException, JsonProcessingException {
stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/ecompOperationalEnvironment.json").withStatus(HttpStatus.SC_ACCEPTED)));
stubFor(post(urlPathMatching("/GRMLWPService/v1/serviceEndPoint/findRunning"))
@@ -136,11 +130,16 @@ public class CreateVnfOperationalEnvironmentTest extends BaseTest{
iar.setRequestScope("create");
iar.setRequestStatus("PENDING");
iar.setRequestAction("UNKNOWN");
- infraActiveRequestsRepository.saveAndFlush(iar);
+ ObjectMapper mapper = new ObjectMapper();
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("{\"requestId\":\""+ requestId+"\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"COMPLETE\",\"statusMessage\":\"SUCCESSFUL"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
createVnfOpEnv.execute(requestId, request);
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestId);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESS"));
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java
index a9be10c3f4..5b0e1f6bfd 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java
@@ -20,19 +20,14 @@
package org.onap.so.apihandlerinfra.tenantisolation.process;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.post;
-import static com.github.tomakehurst.wiremock.client.WireMock.put;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpStatus;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -45,6 +40,9 @@ import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.springframework.beans.factory.annotation.Autowired;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+
public class DeactivateVnfOperationalEnvironmentTest extends BaseTest{
@Rule
@@ -52,13 +50,20 @@ public class DeactivateVnfOperationalEnvironmentTest extends BaseTest{
@Autowired
private DeactivateVnfOperationalEnvironment deactivate;
- @Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
-
+
private CloudOrchestrationRequest request = new CloudOrchestrationRequest();
private String operationalEnvironmentId = "ff3514e3-5a33-55df-13ab-12abad84e7ff";
private String requestId = "ff3514e3-5a33-55df-13ab-12abad84e7fe";
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Before
+ public void init(){
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("{\"requestId\":\""+ requestId+"\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"COMPLETE\",\"statusMessage\":\"SUCCESSFUL"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+ }
@Test
public void testDeactivateOperationalEnvironment() throws Exception {
request.setOperationalEnvironmentId(operationalEnvironmentId);
@@ -79,14 +84,11 @@ public class DeactivateVnfOperationalEnvironmentTest extends BaseTest{
iar.setRequestScope("create");
iar.setRequestStatus("PENDING");
iar.setRequestAction("UNKNOWN");
- infraActiveRequestsRepository.saveAndFlush(iar);
-
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
deactivate.execute(requestId, request);
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestId);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESSFUL"));
-
}
@Test
@@ -110,8 +112,15 @@ public class DeactivateVnfOperationalEnvironmentTest extends BaseTest{
iar.setRequestScope("create");
iar.setRequestStatus("PENDING");
iar.setRequestAction("UNKNOWN");
- infraActiveRequestsRepository.saveAndFlush(iar);
-
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/"))
+ .withRequestBody(containing("{\"requestId\":\""+ requestId+"\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"FAILED\",\"statusMessage\":\"FAILURE"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+
deactivate.execute(requestId, request);
}
@@ -131,13 +140,12 @@ public class DeactivateVnfOperationalEnvironmentTest extends BaseTest{
iar.setRequestScope("create");
iar.setRequestStatus("PENDING");
iar.setRequestAction("UNKNOWN");
- infraActiveRequestsRepository.saveAndFlush(iar);
+ stubFor(get(urlPathEqualTo("/infraActiveRequests/"+requestId))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(iar))
+ .withStatus(HttpStatus.SC_OK)));
deactivate.execute(requestId, request);
-
- InfraActiveRequests infraActiveRequest = infraActiveRequestsRepository.findOne(requestId);
- assertNotNull(infraActiveRequest);
- assertTrue(infraActiveRequest.getStatusMessage().contains("SUCCESS"));
}
@Test