Commit 7f55f6eb authored by Kristel Meikas's avatar Kristel Meikas
Browse files

TEIS-2525: added functionality to compose accident case paths

parent d1039ff4
......@@ -38,10 +38,13 @@ class PathListenerTest extends AdminAppTestBase {
}
@Test
void proceedingsPath() {
void getPath_proceedings_success() {
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
......@@ -50,10 +53,13 @@ class PathListenerTest extends AdminAppTestBase {
}
@Test
void claimsPath() {
void getPath_claims_success() {
UUID claimId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(CLAIM_PAYMENT).id(claimId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(CLAIM_PAYMENT)
.id(claimId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
......@@ -62,52 +68,70 @@ class PathListenerTest extends AdminAppTestBase {
}
@Test
void proceduralActsPath() {
void getPath_proceduralActs_success() {
UUID actId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEDURAL_ACT).id(actId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEDURAL_ACT)
.id(actId)
.build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/acts/" +
actId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/acts/" + actId + "/" + PATH_END);
}
@Test
void violationsPath() {
void getPath_violations_success() {
UUID violationId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(VIOLATION).id(violationId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(VIOLATION)
.id(violationId)
.build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violations/" +
violationId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violations/" + violationId + "/" + PATH_END);
}
@Test
void violationActsPath() {
void getPath_violationActs_success() {
UUID violationActId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(VIOLATION_ACT).id(violationActId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder().objectType(PROCEEDING).id(proceedingId).build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(VIOLATION_ACT)
.id(violationActId)
.build());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violationAct/" +
violationActId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violationAct/" + violationActId + "/" + PATH_END);
}
@Test
void riskAssessmentPath_success() {
void getPath_riskAssessments_success() {
UUID riskAssessmentId = UUID.randomUUID();
UUID riskFactorAssessmentId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
......@@ -123,8 +147,23 @@ class PathListenerTest extends AdminAppTestBase {
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo(AUTH_RISK_ASSESSMENT_URL + riskAssessmentId +
"/assessment/" + riskFactorAssessmentId + "/" + PATH_END);
assertThat(response.getPayload()).isEqualTo(AUTH_RISK_ASSESSMENT_URL + riskAssessmentId
+ "/assessment/" + riskFactorAssessmentId + "/" + PATH_END);
}
@Test
void getPath_accidentCases_success() {
UUID accidentCaseId = UUID.randomUUID();
payload.setDataObjectReferences(new ArrayList<>());
payload.getDataObjectReferences().add(DataObjectReferenceDto.builder()
.objectType(ACCIDENT_CASE)
.id(accidentCaseId)
.build());
payload.setPathEnd(PATH_END);
response = pathListener.getPath(request);
assertThat(response.getPayload()).isEqualTo("/auth/accident-cases/" + accidentCaseId + "/" + PATH_END);
}
}
......@@ -6,7 +6,6 @@ import ee.sm.ti.teis.adminservice.config.AdminQueueConfig.GetPathMsResponse;
import ee.sm.ti.teis.domain.admin.GetUrlPath;
import ee.sm.ti.teis.domain.admin.PathDataObjectReference;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.classifier.ObjectType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,15 +13,17 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.*;
import static org.assertj.core.api.Assertions.assertThat;
class PathMsListenerTest extends AdminAppTestBase {
private static final String PATH_END = "general";
private static final String AUTH_PROCEEDINGS_URL = "/auth/proceedings/";
private static final String AUTH_RISK_ASSESSMENT_URL = "/auth/risk-assessments/";
@Autowired
PathMsListener pathMsListener;
PathMsListener listener;
GetPathMsRequest request;
GetUrlPath payload;
......@@ -37,71 +38,137 @@ class PathMsListenerTest extends AdminAppTestBase {
}
@Test
void proceedingsPath() {
void getPath_proceedings_success() {
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/" + PATH_END);
}
@Test
void claimsPath() {
void getPath_claims_success() {
UUID claimId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.CLAIM_PAYMENT).id(claimId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(CLAIM_PAYMENT)
.id(claimId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo("/auth/claims/" + claimId + "/" + PATH_END);
}
@Test
void proceduralActsPath() {
void getPath_proceduralActs_success() {
UUID actId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEDURAL_ACT).id(actId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEDURAL_ACT)
.id(actId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/acts/" + actId + "/" + PATH_END);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/acts/" + actId + "/" + PATH_END);
}
@Test
void violationsPath() {
void getPath_violations_success() {
UUID violationId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.VIOLATION).id(violationId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(VIOLATION)
.id(violationId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violations/" + violationId + "/" + PATH_END);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violations/" + violationId + "/" + PATH_END);
}
@Test
void violationActsPath() {
void getPath_violationActs_success() {
UUID violationActId = UUID.randomUUID();
UUID violationId = UUID.randomUUID();
UUID proceedingId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.VIOLATION).id(violationId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.VIOLATION_ACT).id(violationActId).build());
payload.getReferences().add(PathDataObjectReference.builder().objectType(ObjectType.PROCEEDING).id(proceedingId).build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(VIOLATION)
.id(violationId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(VIOLATION_ACT)
.id(violationActId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(PROCEEDING)
.id(proceedingId)
.build());
payload.setPathEnd(PATH_END);
response = pathMsListener.getPath(request);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId + "/violationAct/" + violationActId + "/" + PATH_END);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_PROCEEDINGS_URL + proceedingId
+ "/violationAct/" + violationActId + "/" + PATH_END);
}
@Test
void getPath_riskAssessments_success() {
UUID riskAssessmentId = UUID.randomUUID();
UUID riskFactorAssessmentId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(RISK_ASSESSMENT)
.id(riskAssessmentId)
.build());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(RISK_FACTOR_ASSESSMENT)
.id(riskFactorAssessmentId)
.build());
payload.setPathEnd(PATH_END);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo(AUTH_RISK_ASSESSMENT_URL + riskAssessmentId
+ "/assessment/" + riskFactorAssessmentId + "/" + PATH_END);
}
@Test
void getPath_accidentCases_success() {
UUID accidentCaseId = UUID.randomUUID();
payload.setReferences(new ArrayList<>());
payload.getReferences().add(PathDataObjectReference.builder()
.objectType(ACCIDENT_CASE)
.id(accidentCaseId)
.build());
payload.setPathEnd(PATH_END);
response = listener.getPath(request);
assertThat(response.getPayload().getPath()).isEqualTo("/auth/accident-cases/" + accidentCaseId + "/" + PATH_END);
}
}
......@@ -24,4 +24,5 @@ public class ParameterValidationService {
throw new TeisBusinessException(BAD_REQUEST, "Value must be numeric");
}
}
}
......@@ -26,6 +26,7 @@ public class PathComposeService {
private static final String CLAIM_PAYMENT_PATH = "claims";
private static final String RISK_ASSESSMENT_PATH = "risk-assessments";
private static final String ASSESSMENT_PATH = "assessment";
private static final String ACCIDENT_CASE_PATH = "accident-cases";
private static final String PATH_DELIMITER = "/";
......@@ -48,6 +49,7 @@ public class PathComposeService {
if (!isValidData(pathDto)) {
throw new TeisIllegalArgumentException("Path validation error");
}
// IMPORTANT: do not change if ordering, they are ordered based on business logic
if (hasType(pathDto, VIOLATION_ACT)) {
path = PATH_DELIMITER + PROCEEDING_PATH + PATH_DELIMITER + getRefWithType(pathDto, PROCEEDING).getId();
......@@ -65,10 +67,14 @@ public class PathComposeService {
} else if (hasType(pathDto, RISK_ASSESSMENT) || hasType(pathDto, RISK_FACTOR_ASSESSMENT)) {
path = PATH_DELIMITER + RISK_ASSESSMENT_PATH + PATH_DELIMITER + getRefWithType(pathDto, RISK_ASSESSMENT).getId();
path += PATH_DELIMITER + ASSESSMENT_PATH + PATH_DELIMITER + getRefWithType(pathDto, RISK_FACTOR_ASSESSMENT).getId();
} else if (hasType(pathDto, ACCIDENT_CASE)) {
path = PATH_DELIMITER + ACCIDENT_CASE_PATH + PATH_DELIMITER + getRefWithType(pathDto, ACCIDENT_CASE).getId();
}
if (path.length() > 0) {
path = appendUrl(pathDto, path);
}
return path;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment