Search in sources :

Example 1 with ConfirmShippingResponse

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

the class GBFOrderServiceTest method getShippingConfirmationsErrorXml.

@Test
public void getShippingConfirmationsErrorXml() throws IOException {
    String errorMessage = "Failed to parse date range";
    String errorXml = "<Response><Error>" + errorMessage + "</Error></Response>";
    ConfirmShippingResponse confirmShippingResponse = new ConfirmShippingResponse(errorXml);
    HttpEntity mockEntity = mock(HttpEntity.class);
    doReturn(IOUtils.toInputStream(jsonMapper.writeValueAsString(confirmShippingResponse), UTF_8)).when(mockEntity).getContent();
    StatusLine mockStatusLine = mock(StatusLine.class);
    doReturn(200).when(mockStatusLine).getStatusCode();
    HttpResponse mockResponse = mock(HttpResponse.class);
    doReturn(mockStatusLine).when(mockResponse).getStatusLine();
    doReturn(mockEntity).when(mockResponse).getEntity();
    doReturn(mockResponse).when(service).postJson(eq(CONFIRMATION_URL), any(), any());
    try {
        service.requestShippingConfirmations(LocalDate.now().minusDays(2), LocalDate.now());
        fail("Exception expected");
    } catch (BadRequestException e) {
        assertEquals(errorMessage, e.getMessage());
    }
    verify(service).postJson(eq(CONFIRMATION_URL), any(), any());
}
Also used : ConfirmShippingResponse(org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingResponse) StatusLine(org.apache.http.StatusLine) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) Test(org.testng.annotations.Test)

Example 2 with ConfirmShippingResponse

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

the class GBFOrderServiceTest method getShippingConfirmations.

@Test
public void getShippingConfirmations() throws IOException {
    ShippingConfirmation shippingConfirmation1 = new ShippingConfirmation();
    shippingConfirmation1.OrderNumber = "1";
    ShippingConfirmation.Item item1a = new ShippingConfirmation.Item();
    item1a.ItemNumber = "Item 1a";
    shippingConfirmation1.Item = Lists.newArrayList(item1a);
    ShippingConfirmation shippingConfirmation2 = new ShippingConfirmation();
    shippingConfirmation1.OrderNumber = "2";
    ShippingConfirmation.Item item2a = new ShippingConfirmation.Item();
    item2a.ItemNumber = "Item 2a";
    shippingConfirmation2.Item = Lists.newArrayList(item2a);
    ShippingConfirmations shippingConfirmations = new ShippingConfirmations();
    shippingConfirmations.shippingConfirmation = Lists.newArrayList(shippingConfirmation1, shippingConfirmation2);
    ConfirmShippingResponse confirmShippingResponse = new ConfirmShippingResponse(xmlMapper.writeValueAsString(shippingConfirmations));
    HttpEntity mockEntity = mock(HttpEntity.class);
    doReturn(IOUtils.toInputStream(jsonMapper.writeValueAsString(confirmShippingResponse), UTF_8)).when(mockEntity).getContent();
    StatusLine mockStatusLine = mock(StatusLine.class);
    doReturn(200).when(mockStatusLine).getStatusCode();
    HttpResponse mockResponse = mock(HttpResponse.class);
    doReturn(mockStatusLine).when(mockResponse).getStatusLine();
    doReturn(mockEntity).when(mockResponse).getEntity();
    ArgumentCaptor<ConfirmShippingRequest> confirmShippingRequestArgumentCaptor = ArgumentCaptor.forClass(ConfirmShippingRequest.class);
    doReturn(mockResponse).when(service).postJson(eq(CONFIRMATION_URL), any(), confirmShippingRequestArgumentCaptor.capture());
    LocalDate startDate = LocalDate.now().minusDays(20);
    LocalDate endDate = LocalDate.now().plusDays(3);
    ShippingConfirmations shippingConfirmationsResult = service.requestShippingConfirmations(startDate, endDate);
    assertEquals(shippingConfirmation1, shippingConfirmationsResult.shippingConfirmation.get(0));
    assertEquals(shippingConfirmation2, shippingConfirmationsResult.shippingConfirmation.get(1));
    ConfirmShippingRequest confirmShippingRequest = confirmShippingRequestArgumentCaptor.getValue();
    assertEquals(startDate, confirmShippingRequest.startDate);
    assertEquals(endDate, confirmShippingRequest.endDate);
    verify(service).handleGbfHttpStatusErrors(any());
    verify(service).postJson(eq(CONFIRMATION_URL), any(), any());
}
Also used : ConfirmShippingResponse(org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingResponse) StatusLine(org.apache.http.StatusLine) HttpEntity(org.apache.http.HttpEntity) ShippingConfirmations(org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmations) ShippingConfirmation(org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmation) HttpResponse(org.apache.http.HttpResponse) LocalDate(org.joda.time.LocalDate) ConfirmShippingRequest(org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingRequest) Test(org.testng.annotations.Test)

Aggregations

HttpEntity (org.apache.http.HttpEntity)2 HttpResponse (org.apache.http.HttpResponse)2 StatusLine (org.apache.http.StatusLine)2 ConfirmShippingResponse (org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingResponse)2 Test (org.testng.annotations.Test)2 LocalDate (org.joda.time.LocalDate)1 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)1 ConfirmShippingRequest (org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingRequest)1 ShippingConfirmation (org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmation)1 ShippingConfirmations (org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmations)1