aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid
diff options
context:
space:
mode:
authorWojciech Sliwka <wojciech.sliwka@nokia.com>2018-09-20 12:03:10 +0200
committerWojciech Sliwka <wojciech.sliwka@nokia.com>2018-10-22 08:42:07 +0200
commit2ddfc4e81cc399c8ffe5451e19308503a5b08a94 (patch)
tree1b0031eb29cc538cfa0fb8734c7a1c835ee7cdef /vid-app-common/src/main/java/org/onap/vid
parent2786c4e256e149ad5967f618017de54d5dc5566e (diff)
new tests for job dir
Add new tests for job directory to increase code coverage in vid Issue-ID: VID-310 Change-Id: Idbdeb1e9037c2b8c7359cf34b3893e1fc2e858d2 Signed-off-by: Wojciech Sliwka <wojciech.sliwka@nokia.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java25
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java12
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java23
3 files changed, 36 insertions, 24 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java
index cee5af69..6685a63d 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java
@@ -23,6 +23,7 @@ package org.onap.vid.job.command;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import io.joshworks.restclient.http.HttpResponse;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.job.Job.JobStatus;
import org.onap.vid.job.JobCommand;
import org.onap.vid.job.NextCommand;
@@ -30,13 +31,13 @@ import org.onap.vid.mso.MsoInterface;
import org.onap.vid.mso.rest.AsyncRequestStatus;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
import org.onap.vid.services.AuditService;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.Map;
+import java.util.Objects;
import java.util.UUID;
@@ -68,33 +69,38 @@ public class InProgressStatusCommand implements JobCommand {
init(jobUuid, requestId);
}
+ InProgressStatusCommand(AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic, MsoInterface msoInterface, AuditService auditService, UUID jobUuid, String requestId) {
+ this(jobUuid, requestId);
+ this.asyncInstantiationBL = asyncInstantiationBusinessLogic;
+ this.restMso = msoInterface;
+ this.auditService = auditService;
+ }
+
@Override
public NextCommand call() {
try {
- String path = asyncInstantiationBL.getOrchestrationRequestsPath()+"/"+requestId;
+ String path = asyncInstantiationBL.getOrchestrationRequestsPath() + "/" + requestId;
HttpResponse<AsyncRequestStatus> msoResponse = restMso.get(path, AsyncRequestStatus.class);
JobStatus jobStatus;
if (msoResponse.getStatus() >= 400 || msoResponse.getBody() == null) {
- auditService.setFailedAuditStatusFromMso(jobUuid, requestId, msoResponse.getStatus(), msoResponse.getBody().toString());
+ auditService.setFailedAuditStatusFromMso(jobUuid, requestId, msoResponse.getStatus(), Objects.toString(msoResponse.getBody()));
LOGGER.error(EELFLoggerDelegate.errorLogger,
"Failed to get orchestration status for {}. Status code: {}, Body: {}",
- requestId, msoResponse.getStatus(), msoResponse.getRawBody().toString());
+ requestId, msoResponse.getStatus(), Objects.toString(msoResponse.getRawBody()));
return new NextCommand(JobStatus.IN_PROGRESS, this);
- }
- else {
+ } else {
jobStatus = asyncInstantiationBL.calcStatus(msoResponse.getBody());
}
- asyncInstantiationBL.auditMsoStatus(jobUuid,msoResponse.getBody().request);
+ asyncInstantiationBL.auditMsoStatus(jobUuid, msoResponse.getBody().request);
if (jobStatus == JobStatus.FAILED) {
asyncInstantiationBL.handleFailedInstantiation(jobUuid);
- }
- else {
+ } else {
asyncInstantiationBL.updateServiceInfoAndAuditStatus(jobUuid, jobStatus);
}
//in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress
@@ -128,5 +134,4 @@ public class InProgressStatusCommand implements JobCommand {
return ImmutableMap.of("requestId", requestId);
}
-
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java
index 9d22b8bf..958fc115 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java
@@ -42,6 +42,7 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.Map;
+import java.util.Objects;
import java.util.UUID;
@@ -73,6 +74,14 @@ public class ServiceInstantiationCommand implements JobCommand {
init(uuid, serviceInstantiationRequest, userId);
}
+ ServiceInstantiationCommand(AsyncInstantiationBusinessLogic asyncInstantiationBL, AuditService auditService, MsoInterface msoInterface,
+ UUID uuid, ServiceInstantiation serviceInstantiation, String userId) {
+ this(uuid, serviceInstantiation, userId);
+ this.asyncInstantiationBL = asyncInstantiationBL;
+ this.auditService = auditService;
+ this.restMso = msoInterface;
+ }
+
@Override
public NextCommand call() {
RequestDetailsWrapper<ServiceInstantiationRequestDetails> requestDetailsWrapper ;
@@ -81,7 +90,6 @@ public class ServiceInstantiationCommand implements JobCommand {
uuid, serviceInstantiationRequest, userId
);
}
-
//Aai return bad response while checking names uniqueness
catch (InvalidAAIResponseException exception) {
LOGGER.error("Failed to check name uniqueness in AAI. VID will try again later", exception);
@@ -116,7 +124,7 @@ public class ServiceInstantiationCommand implements JobCommand {
return new NextCommand(jobStatus, new InProgressStatusCommand(uuid, requestId));
} else {
auditService.setFailedAuditStatusFromMso(uuid,null, msoResponse.getStatus(),
- msoResponse.getBody().toString());
+ Objects.toString(msoResponse.getBody()));
return handleCommandFailed();
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java
index 77e1dd2c..59f12f4c 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java
@@ -33,14 +33,10 @@ public class JobAdapterImpl implements JobAdapter {
}
@Override
- public Job createJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, Integer indexInBulk){
- JobDaoImpl job = new JobDaoImpl();
- job.setStatus(Job.JobStatus.PENDING);
- job.setTypeAndData(jobType, ImmutableMap.of(
+ public Job createJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, Integer indexInBulk) {
+ JobDaoImpl job = createJob(jobType, templateId, indexInBulk, ImmutableMap.of(
"request", request,
"userId", userId));
- job.setTemplateId(templateId);
- job.setIndexInBulk(indexInBulk);
job.setUserId(userId);
return job;
}
@@ -59,14 +55,17 @@ public class JobAdapterImpl implements JobAdapter {
List<Job> jobList = new ArrayList<>(count + 1);
UUID templateId = UUID.randomUUID();
for (int i = 0; i < count; i++) {
- Job child = new JobDaoImpl();
- child.setTypeAndData(jobType, bulkRequest);
- child.setStatus(Job.JobStatus.PENDING);
- child.setTemplateId(templateId);
- child.setIndexInBulk(i);
- jobList.add(child);
+ jobList.add(createJob(jobType, templateId, i, bulkRequest));
}
return jobList;
}
+ private JobDaoImpl createJob(JobType jobType, UUID templateId, Integer indexInBulk, Map<String, Object> data) {
+ JobDaoImpl job = new JobDaoImpl();
+ job.setStatus(Job.JobStatus.PENDING);
+ job.setTypeAndData(jobType, data);
+ job.setTemplateId(templateId);
+ job.setIndexInBulk(indexInBulk);
+ return job;
+ }
}