Search in sources :

Example 1 with Order

use of org.sagebionetworks.bridge.models.crc.gbf.external.Order in project BridgeServer2 by Sage-Bionetworks.

the class GBFOrderServiceTest method placeOrder.

@Test
public void placeOrder() throws IOException {
    Order mockOrder = mock(Order.class);
    PlaceOrderResponse response = new PlaceOrderResponse(true, null);
    HttpResponse mockResponse = createMockResponse(response);
    doReturn(mockResponse).when(service).postJson(eq(PLACE_URL), any(), any());
    service.placeOrder(mockOrder, true);
    verify(service).postJson(eq(PLACE_URL), any(), any());
    verify(service).handleGbfHttpStatusErrors(any());
}
Also used : Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) HttpResponse(org.apache.http.HttpResponse) PlaceOrderResponse(org.sagebionetworks.bridge.models.crc.gbf.external.PlaceOrderResponse) Test(org.testng.annotations.Test)

Example 2 with Order

use of org.sagebionetworks.bridge.models.crc.gbf.external.Order in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method internalLabShipmentRequest.

ResponseEntity<StatusMessage> internalLabShipmentRequest(App app, AccountId accountId) {
    Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
    if (account.getDataGroups().contains(SHIP_TESTS_REQUESTED.name().toLowerCase())) {
        throw new LimitExceededException("Limited to one active shipment request.");
    }
    boolean isTestUser = account.getDataGroups().contains(TEST_USER_GROUP);
    LOG.info("Lab shipment requested for {} participant", isTestUser ? "test" : "non-test");
    LocalDate date = LocalDate.now();
    Order.ShippingInfo.Address address = validateAndGetAddress(account);
    String orderNumber = account.getId() + "_" + date;
    Order o = new Order(isTestUser, orderNumber, account.getId(), date, new Order.ShippingInfo(address, GBF_TEST_KIT_SHIP_METHOD), new Order.LineItem(GBF_TEST_KIT_PART_NUMBER, 1));
    gbfOrderService.placeOrder(o, isTestUser);
    JsonNode node = JsonNodeFactory.instance.objectNode().put(SHIPMENT_REPORT_KEY_ORDER_ID, orderNumber);
    // participants will not have Org Sponsored Studies in RequestContext, so for lab shipment reports, don't set study IDs
    writeReportAndUpdateState(app, account.getId(), node, SHIPMENT_REPORT, SHIP_TESTS_REQUESTED, false);
    return ResponseEntity.accepted().body(new StatusMessage(isTestUser ? "Test" : "Non-test" + " shipment requested."));
}
Also used : Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) Account(org.sagebionetworks.bridge.models.accounts.Account) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) LocalDate(org.joda.time.LocalDate) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) LimitExceededException(org.sagebionetworks.bridge.exceptions.LimitExceededException)

Example 3 with Order

use of org.sagebionetworks.bridge.models.crc.gbf.external.Order in project BridgeServer2 by Sage-Bionetworks.

the class GBFOrderServiceTest method placeOrderThrowsExceptionOnGbfResponseObjectSuccessFalse.

@Test(expectedExceptions = BridgeServiceException.class)
public void placeOrderThrowsExceptionOnGbfResponseObjectSuccessFalse() throws IOException {
    Order mockOrder = mock(Order.class);
    PlaceOrderResponse response = new PlaceOrderResponse(false, null);
    HttpResponse mockResponse = createMockResponse(response);
    doReturn(mockResponse).when(service).postJson(eq(PLACE_URL), any(), any());
    service.placeOrder(mockOrder, true);
}
Also used : Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) HttpResponse(org.apache.http.HttpResponse) PlaceOrderResponse(org.sagebionetworks.bridge.models.crc.gbf.external.PlaceOrderResponse) Test(org.testng.annotations.Test)

Example 4 with Order

use of org.sagebionetworks.bridge.models.crc.gbf.external.Order in project BridgeServer2 by Sage-Bionetworks.

the class CRCControllerTest method internalLabShipmentRequestSetsShipMethod.

@Test
public void internalLabShipmentRequestSetsShipMethod() {
    setupParticipantAuthentication();
    setupShippingAddress();
    DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
    doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, SHIPMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
    ArgumentCaptor<Order> orderCaptor = ArgumentCaptor.forClass(Order.class);
    controller.internalLabShipmentRequest(mockApp, AccountId.forId(APP_ID, TEST_USER_ID));
    verify(mockGBFOrderService).placeOrder(orderCaptor.capture(), anyBoolean());
    Order requestedOrder = orderCaptor.getValue();
    assertEquals(requestedOrder.ShippingInfo.ShipMethod, GBF_TEST_KIT_SHIP_METHOD);
}
Also used : Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) InOrder(org.mockito.InOrder) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) Test(org.testng.annotations.Test)

Aggregations

Order (org.sagebionetworks.bridge.models.crc.gbf.external.Order)4 Test (org.testng.annotations.Test)3 HttpResponse (org.apache.http.HttpResponse)2 PlaceOrderResponse (org.sagebionetworks.bridge.models.crc.gbf.external.PlaceOrderResponse)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 LocalDate (org.joda.time.LocalDate)1 InOrder (org.mockito.InOrder)1 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 LimitExceededException (org.sagebionetworks.bridge.exceptions.LimitExceededException)1 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)1 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)1 Account (org.sagebionetworks.bridge.models.accounts.Account)1