Search in sources :

Example 1 with ShippingConfirmation

use of org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmation 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)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 LocalDate (org.joda.time.LocalDate)1 ConfirmShippingRequest (org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingRequest)1 ConfirmShippingResponse (org.sagebionetworks.bridge.models.crc.gbf.external.ConfirmShippingResponse)1 ShippingConfirmation (org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmation)1 ShippingConfirmations (org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmations)1 Test (org.testng.annotations.Test)1