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());
}
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());
}
Aggregations