Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to correctly serialize datetimes & refactor lifecycle status endpoint #2251

Merged
merged 11 commits into from
Nov 28, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.va.vro.mockbipclaims.controller;

import gov.va.vro.mockbipclaims.api.ClaimsApi;
import gov.va.vro.mockbipclaims.model.bip.Message;
import gov.va.vro.mockbipclaims.model.bip.request.CloseClaimRequest;
import gov.va.vro.mockbipclaims.model.bip.request.PutTemporaryStationOfJurisdictionRequest;
import gov.va.vro.mockbipclaims.model.bip.response.ClaimDetailResponse;
Expand All @@ -11,7 +10,6 @@
import gov.va.vro.mockbipclaims.model.store.ClaimStoreItem;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;

Expand Down Expand Up @@ -63,12 +61,8 @@ public ResponseEntity<CloseClaimResponse> cancelClaimById(
log.info("Received closeReasonText: {}", closeClaimRequest.getCloseReasonText());
}

claimStore.cancel(claimId);
item.getClaimDetail().setClaimLifecycleStatus("Cancelled");

Message message = new Message();
message.setText("Successfully canceled the claim with id: " + claimId);
message.setStatus(HttpStatus.OK.value());
response.addMessagesItem(message);
return create200(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.va.vro.mockbipclaims.controller;

import gov.va.vro.mockbipclaims.api.LifecycleStatusesApi;
import gov.va.vro.mockbipclaims.model.bip.Message;
import gov.va.vro.mockbipclaims.model.bip.request.UpdateClaimLifecycleStatusRequest;
import gov.va.vro.mockbipclaims.model.bip.response.UpdateClaimLifecycleStatusResponse;
import gov.va.vro.mockbipclaims.model.store.ClaimStore;
Expand All @@ -12,12 +11,11 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.server.ResponseStatusException;

@Controller
@Slf4j
@RequiredArgsConstructor
public class LifecycleStatusesController implements LifecycleStatusesApi {
public class LifecycleStatusesController extends BaseController implements LifecycleStatusesApi {
private final ClaimStore claimStore;

private final UpdatesStore actionStore;
Expand All @@ -27,22 +25,17 @@ public ResponseEntity<UpdateClaimLifecycleStatusResponse> updateClaimLifecycleSt
Long claimId, UpdateClaimLifecycleStatusRequest updateClaimLifecycleStatusRequest) {
log.info("Updating claim lifecycle status (id: {})", claimId);
ClaimStoreItem item = claimStore.get(claimId);

UpdateClaimLifecycleStatusResponse response = new UpdateClaimLifecycleStatusResponse();
if (item == null) {
String reason = "No claim found for id: " + claimId;
throw new ResponseStatusException(HttpStatus.NOT_FOUND, reason);
return createClaim404(response, claimId);
}

if (claimId.longValue() == 1370L) {
String reason = "Intentional exception for testing: " + claimId;
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, reason);
if (claimId == CLAIM_YIELDS_500) {
return create500(response);
}

String status = updateClaimLifecycleStatusRequest.getClaimLifecycleStatus();
item.getClaimDetail().setClaimLifecycleStatus(status);
var response = new UpdateClaimLifecycleStatusResponse();
Message message = new Message();
message.setText("Success");
response.addMessagesItem(message);

actionStore.addLifecycleStatusUpdate(claimId);
return new ResponseEntity<>(response, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
package gov.va.vro.mockbipclaims.model.bip.response;

import gov.va.vro.mockbipclaims.model.bip.Message;
import jakarta.validation.Valid;
import gov.va.vro.mockbipclaims.model.bip.ProviderResponse;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/** UpdateClaimLifecycleStatusResponse. */
@Data
public class UpdateClaimLifecycleStatusResponse {
@Valid private List<Message> messages = null;

/**
* Adds a new message.
*
* @param message message to be added
*/
public void addMessagesItem(Message message) {
if (messages == null) {
messages = new ArrayList<>();
}
messages.add(message);
}
}
public class UpdateClaimLifecycleStatusResponse extends ProviderResponse {}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,4 @@ public void put(ClaimStoreItem item) {
String key = String.valueOf(id);
store.put(key, item);
}

/**
* Removes an item from Claim Store.
*
* @param claimId
*/
public void cancel(Long claimId) {
String key = String.valueOf(claimId);
store.remove(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"claimDetail": {
"claimId": 1000,
"phase": "Claim Received",
"endProductCode": "400"
"endProductCode": "400",
"claimLifecycleStatus": "Open"
},
"contentions": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import gov.va.vro.mockbipclaims.controller.BaseController;
Expand Down Expand Up @@ -30,6 +29,9 @@ public class ClaimsControllerTest {

@Mock private ClaimStore claimStore;

private static final String OPEN = "Open";
private static final String CANCELLED = "Cancelled";

@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
Expand Down Expand Up @@ -70,6 +72,10 @@ public void testGetClaimById_NotFound() {
public void testCancelClaimById_Success() {
Long claimId = 1010L;
ClaimStoreItem item = new ClaimStoreItem();
ClaimDetail claimDetail = new ClaimDetail();
claimDetail.setClaimLifecycleStatus(OPEN);
item.setClaimDetail(claimDetail);

when(claimStore.get(claimId)).thenReturn(item);
CloseClaimRequest closeClaimRequest = new CloseClaimRequest();
closeClaimRequest.setLifecycleStatusReasonCode("60");
Expand All @@ -80,10 +86,7 @@ public void testCancelClaimById_Success() {
claimsController.cancelClaimById(claimId, closeClaimRequest);

assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(
"Successfully canceled the claim with id: " + claimId,
response.getBody().getMessages().get(0).getText());
verify(claimStore).cancel(claimId);
assertEquals(CANCELLED, item.getClaimDetail().getClaimLifecycleStatus());
}

@Test
Expand Down
1 change: 1 addition & 0 deletions svc-bip-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {

implementation "com.fasterxml.jackson.core:jackson-core"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.0"

def jjwt_version = "0.12.3"
implementation "io.jsonwebtoken:jjwt-api:${jjwt_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import gov.va.vro.bip.model.BipClaim;
import gov.va.vro.bip.model.BipPayloadRequest;
import gov.va.vro.bip.model.BipPayloadResponse;
import gov.va.vro.bip.model.ExistingContention;
import gov.va.vro.bip.model.claim.GetClaimResponse;
import gov.va.vro.bip.model.contentions.GetClaimContentionsResponse;
import gov.va.vro.bip.service.BipResetMockController;
import gov.va.vro.bip.service.IBipApiService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -25,6 +30,7 @@
public class BaseIntegrationTest {
@Autowired private RabbitTemplate rabbitTemplate;
@Autowired private BipResetMockController resetMockController;
@Autowired private IBipApiService bipApiService;

protected static final long CLAIM_ID_200 = 1000L;
protected static final long CLAIM_ID_404 = 0L;
Expand All @@ -36,17 +42,17 @@ public class BaseIntegrationTest {
@Value("${putTempStationOfJurisdictionQueue}")
protected String putTempStationOfJurisdictionQueue;

@Value("${updateClaimStatusQueue}")
protected String updateClaimStatusQueue;

@Value("${getClaimContentionsQueue}")
protected String getClaimContentionsQueue;

@Value("${getClaimDetailsQueue}")
protected String getClaimDetailsQueue;

@Value("${setClaimToRfdStatusQueue}")
protected String setClaimToRfdStatusQueue;
@Value("${cancelClaimQueue}")
protected String cancelClaimQueue;

@Value("${putClaimLifecycleStatusQueue}")
protected String putClaimLifecycleStatusQueue;

@Value("${updateClaimContentionsQueue}")
protected String updateClaimContentionsQueue;
Expand All @@ -65,6 +71,21 @@ protected <T extends BipPayloadResponse> T sendAndReceive(
return (T) rabbitTemplate.convertSendAndReceive(exchangeName, queue, request);
}

protected ExistingContention getExistingContention(long claimId) {
GetClaimContentionsResponse getResponse = bipApiService.getClaimContentions(claimId);
assertBaseResponseIs2xx(getResponse, HttpStatus.OK);
assertNotNull(getResponse.getContentions());
assertEquals(1, getResponse.getContentions().size());
return getResponse.getContentions().get(0);
}

protected BipClaim getExistingClaim(long claimId) {
GetClaimResponse getResponse = bipApiService.getClaimDetails(claimId);
assertBaseResponseIs2xx(getResponse, HttpStatus.OK);
assertNotNull(getResponse.getClaim());
return getResponse.getClaim();
}

protected void assertBaseResponseIs2xx(BipPayloadResponse response, HttpStatus status) {
assertNotNull(response);
assertEquals(status.value(), response.getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package gov.va.vro.bip;

import static org.junit.jupiter.api.Assertions.assertEquals;

import gov.va.vro.bip.model.BipClaim;
import gov.va.vro.bip.model.cancel.CancelClaimRequest;
import gov.va.vro.bip.model.cancel.CancelClaimResponse;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;

public class CancelClaimTest extends BaseIntegrationTest {

private static final String OPEN = "Open";
private static final String CANCELLED = "Cancelled";

@Test
void testCancelClaim_200() {
BipClaim existingClaim = getExistingClaim(CLAIM_ID_200);
assertEquals(OPEN, existingClaim.getClaimLifecycleStatus());

CancelClaimRequest request =
CancelClaimRequest.builder()
.claimId(CLAIM_ID_200)
.closeReasonText("because we are testing")
.lifecycleStatusReasonCode("60")
.build();
CancelClaimResponse response = sendAndReceive(cancelClaimQueue, request);
assertBaseResponseIs2xx(response, HttpStatus.OK);

BipClaim updatedClaim = getExistingClaim(CLAIM_ID_200);
assertEquals(CANCELLED, updatedClaim.getClaimLifecycleStatus());
}

@Test
void testPutTempStationOfJurisdiction_404() {
CancelClaimRequest request =
CancelClaimRequest.builder()
.claimId(CLAIM_ID_404)
.closeReasonText("because we are testing")
.lifecycleStatusReasonCode("60")
.build();
CancelClaimResponse response = sendAndReceive(cancelClaimQueue, request);
assertBaseResponseIsNot2xx(response, HttpStatus.NOT_FOUND);
}

@Test
void testPutTempStationOfJurisdiction_500() {
CancelClaimRequest request =
CancelClaimRequest.builder()
.claimId(CLAIM_ID_500)
.closeReasonText("because we are testing")
.lifecycleStatusReasonCode("60")
.build();
CancelClaimResponse response = sendAndReceive(cancelClaimQueue, request);
assertBaseResponseIsNot2xx(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;

import java.time.Instant;
import java.util.List;

public class CreateClaimContentionsTest extends BaseIntegrationTest {
Expand Down Expand Up @@ -70,10 +71,10 @@ void testCreateClaimContentions_500() {
private static Contention getNewContention() {
return Contention.builder()
.medicalInd(true)
.beginDate("2023-02-01T00:00:00Z")
.beginDate(Instant.parse("2023-02-01T00:00:00Z"))
.contentionTypeCode("NEW")
.classificationType(1250)
.diagnosticTypeCode(6260)
.diagnosticTypeCode("6260")
.claimantText("tinnitus")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package gov.va.vro.bip;

import gov.va.vro.bip.model.lifecycle.PutClaimLifecycleRequest;
import gov.va.vro.bip.model.lifecycle.PutClaimLifecycleResponse;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;

class PutClaimLifecycleStatusTest extends BaseIntegrationTest {

@Test
void testPutClaimLifecycleStatusTest_200() {
PutClaimLifecycleRequest request =
PutClaimLifecycleRequest.builder()
.claimId(CLAIM_ID_200)
.claimLifecycleStatus("Ready for Decision")
.build();
PutClaimLifecycleResponse response = sendAndReceive(putClaimLifecycleStatusQueue, request);
assertBaseResponseIs2xx(response, HttpStatus.OK);
}

@Test
void testPutClaimLifecycleStatusTest_404() {
PutClaimLifecycleRequest request =
PutClaimLifecycleRequest.builder()
.claimId(CLAIM_ID_404)
.claimLifecycleStatus("Ready for Decision")
.build();
PutClaimLifecycleResponse response = sendAndReceive(putClaimLifecycleStatusQueue, request);
assertBaseResponseIsNot2xx(response, HttpStatus.NOT_FOUND);
}

@Test
void testPutClaimLifecycleStatusTest_500() {
PutClaimLifecycleRequest request =
PutClaimLifecycleRequest.builder()
.claimId(CLAIM_ID_500)
.claimLifecycleStatus("Ready for Decision")
.build();
PutClaimLifecycleResponse response = sendAndReceive(putClaimLifecycleStatusQueue, request);
assertBaseResponseIsNot2xx(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Loading