Skip to content

Commit

Permalink
hlm-3376: added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishq-egov committed Oct 20, 2023
1 parent 0a20eb6 commit 2eda751
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public List<Referral> create(ReferralBulkRequest referralRequest, boolean isBulk
} catch (Exception exception) {
log.error("error occurred while creating referrals: {}", exception.getMessage());
populateErrorDetails(referralRequest, errorDetailsMap, validReferrals,
exception, Constants.SET_SIDE_EFFECTS);
exception, Constants.SET_REFERRALS);
}
handleErrors(errorDetailsMap, isBulk, Constants.VALIDATION_ERROR);

Expand Down Expand Up @@ -143,7 +143,7 @@ public List<Referral> update(ReferralBulkRequest referralRequest, boolean isBulk
} catch (Exception exception) {
log.error("error occurred while updating referrals", exception);
populateErrorDetails(referralRequest, errorDetailsMap, validReferrals,
exception, Constants.SET_SIDE_EFFECTS);
exception, Constants.SET_REFERRALS);
}
handleErrors(errorDetailsMap, isBulk, Constants.VALIDATION_ERROR);

Expand Down Expand Up @@ -203,7 +203,7 @@ public List<Referral> delete(ReferralBulkRequest referralRequest, boolean isBulk
} catch (Exception exception) {
log.error("error occurred while deleting entities: {}", exception);
populateErrorDetails(referralRequest, errorDetailsMap, validReferrals,
exception, Constants.SET_SIDE_EFFECTS);
exception, Constants.SET_REFERRALS);
}
handleErrors(errorDetailsMap, isBulk, Constants.VALIDATION_ERROR);

Expand All @@ -225,7 +225,7 @@ private Tuple<List<Referral>, Map<Referral, ErrorDetails>> validate(
log.info("validating request");
Map<Referral, ErrorDetails> errorDetailsMap = CommonUtils.validate(validators,
isApplicable, request,
Constants.SET_SIDE_EFFECTS);
Constants.SET_REFERRALS);
if (!errorDetailsMap.isEmpty() && !isBulk) {
log.error("validation error occurred. error details: {}", errorDetailsMap.values().toString());
throw new CustomException(Constants.VALIDATION_ERROR, errorDetailsMap.values().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* Referral Management Api Controller
*/
@Controller
@RequestMapping("")
@Validated
Expand All @@ -52,6 +55,11 @@ public ReferralManagementApiController(
this.referralManagementConfiguration = referralManagementConfiguration;
}

/**
* @
* @param request
* @return
*/
@RequestMapping(value = "/v1/_create", method = RequestMethod.POST)
public ResponseEntity<ReferralResponse> referralV1CreatePost(@ApiParam(value = "Capture details of Referral", required = true) @Valid @RequestBody ReferralRequest request) {

Expand All @@ -66,7 +74,11 @@ public ResponseEntity<ReferralResponse> referralV1CreatePost(@ApiParam(value = "
}



/**
*
* @param request
* @return
*/
@RequestMapping(value = "/v1/bulk/_create", method = RequestMethod.POST)
public ResponseEntity<ResponseInfo> referralBulkV1CreatePost(@ApiParam(value = "Capture details of Referral", required = true) @Valid @RequestBody ReferralBulkRequest request) {
request.getRequestInfo().setApiId(httpServletRequest.getRequestURI());
Expand All @@ -77,6 +89,17 @@ public ResponseEntity<ResponseInfo> referralBulkV1CreatePost(@ApiParam(value = "
.createResponseInfo(request.getRequestInfo(), true));
}

/**
*
* @param request
* @param limit
* @param offset
* @param tenantId
* @param lastChangedSince
* @param includeDeleted
* @return
* @throws Exception
*/
@RequestMapping(value = "/v1/_search", method = RequestMethod.POST)
public ResponseEntity<ReferralBulkResponse> referralV1SearchPost(@ApiParam(value = "Referral Search.", required = true) @Valid @RequestBody ReferralSearchRequest request,
@NotNull @Min(0) @Max(1000) @ApiParam(value = "Pagination - limit records in response", required = true) @Valid @RequestParam(value = "limit", required = true) Integer limit,
Expand All @@ -92,6 +115,11 @@ public ResponseEntity<ReferralBulkResponse> referralV1SearchPost(@ApiParam(value
return ResponseEntity.status(HttpStatus.OK).body(response);
}

/**
*
* @param request
* @return
*/
@RequestMapping(value = "/v1/_update", method = RequestMethod.POST)
public ResponseEntity<ReferralResponse> referralV1UpdatePost(@ApiParam(value = "Capture details of Existing Referral", required = true) @Valid @RequestBody ReferralRequest request) {
Referral referral = referralManagementService.update(request);
Expand All @@ -106,6 +134,11 @@ public ResponseEntity<ReferralResponse> referralV1UpdatePost(@ApiParam(value = "

}

/**
*
* @param request
* @return
*/
@RequestMapping(value = "/v1/bulk/_update", method = RequestMethod.POST)
public ResponseEntity<ResponseInfo> referralV1BulkUpdatePost(@ApiParam(value = "Capture details of Existing Referral", required = true) @Valid @RequestBody ReferralBulkRequest request) {
request.getRequestInfo().setApiId(httpServletRequest.getRequestURI());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.egov.referralmanagement.helper;

import org.egov.common.helper.RequestInfoTestBuilder;
import org.egov.common.models.referralmanagement.ReferralRequest;

import java.util.ArrayList;

public class ReferralRequestTestBuilder {
private ReferralRequest.ReferralRequestBuilder builder;

private ArrayList referral = new ArrayList();

public ReferralRequestTestBuilder() {
this.builder = ReferralRequest.builder();
}

public static ReferralRequestTestBuilder builder() {
return new ReferralRequestTestBuilder();
}

public ReferralRequest build() {
return this.builder.build();
}

public ReferralRequestTestBuilder withOneReferral() {
builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build())
.referral(ReferralTestBuilder.builder().withId().withAuditDetails().build());
return this;
}

public ReferralRequestTestBuilder withApiOperationNotNullAndNotCreate() {
builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build())
.referral(ReferralTestBuilder.builder().withIdNull().build());
return this;
}

public ReferralRequestTestBuilder withApiOperationNotUpdate() {
builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build())
.referral(ReferralTestBuilder.builder().withIdNull().build());
return this;
}

public ReferralRequestTestBuilder withOneReferralHavingId() {
builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build())
.referral(ReferralTestBuilder.builder().withId().withAuditDetails().build());
return this;
}

public ReferralRequestTestBuilder withBadTenantIdInOneReferral() {

builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build())
.referral(ReferralTestBuilder.builder().withIdNull().withBadTenantId().build());
return this;
}

public ReferralRequestTestBuilder withRequestInfo(){
this.builder.requestInfo(RequestInfoTestBuilder.builder().withCompleteRequestInfo().build());
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.egov.referralmanagement.helper;

import org.egov.common.helper.AuditDetailsTestBuilder;
import org.egov.common.models.referralmanagement.Referral;

import java.util.ArrayList;
import java.util.Arrays;

public class ReferralTestBuilder {

private Referral.ReferralBuilder builder;

public ReferralTestBuilder() {
this.builder = Referral.builder();
}

public static ReferralTestBuilder builder() {
return new ReferralTestBuilder();
}

public Referral build() {
return this.builder.hasErrors(false).build();
}

public ReferralTestBuilder withIdNull() {
this.builder.projectBeneficiaryId("some-projectBeneficiary-id")
.clientReferenceId("ClientReferenceId")
.id(null)
.projectBeneficiaryClientReferenceId("projectBeneficiaryClientReferenceId")
.reasons(new ArrayList<>(Arrays.asList("fever")))
.tenantId("some-tenant-id")
.rowVersion(1);
return this;
}

public ReferralTestBuilder withId() {
withIdNull().builder.id("some-id")
.projectBeneficiaryId("some-projectBeneficiary-id")
.clientReferenceId("ClientReferenceId")
.projectBeneficiaryClientReferenceId("projectBeneficiaryClientReferenceId")
.reasons(new ArrayList<>(Arrays.asList("fever")))
.tenantId("some-tenant-id")
.rowVersion(1);
return this;
}

public ReferralTestBuilder withId(String id) {
this.builder.id(id);
return this;
}

public ReferralTestBuilder withBadTenantId() {
this.builder.tenantId(null);
return this;
}

public ReferralTestBuilder goodReferral() {
this.builder.id("some-id")
.projectBeneficiaryId("some-projectBeneficiary-id")
.clientReferenceId("ClientReferenceId")
.projectBeneficiaryClientReferenceId("projectBeneficiaryClientReferenceId")
.reasons(new ArrayList<>(Arrays.asList("fever")))
.tenantId("some-tenant-id")
.auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build())
.clientAuditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build());
return this;
}

public ReferralTestBuilder withAuditDetails() {
this.builder.auditDetails(AuditDetailsTestBuilder.builder().withAuditDetails().build());
return this;
}

public ReferralTestBuilder withDeleted() {
this.builder.isDeleted(true);
return this;
}
}
Loading

0 comments on commit 2eda751

Please sign in to comment.