use of org.openlmis.stockmanagement.util.DynamicPageTypeReference in project openlmis-stockmanagement by OpenLMIS.
the class OrderableReferenceDataServiceTest method shouldReturnOrderablesById.
@Test
public void shouldReturnOrderablesById() {
OrderableDto product = mockPageResponseEntityAndGetDto();
UUID orderableId = UUID.randomUUID();
List<OrderableDto> response = service.findByIds(Collections.singleton(orderableId));
assertThat(response, hasSize(1));
assertThat(response, hasItem(product));
verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(OrderableDto.class)));
URI uri = uriCaptor.getValue();
assertEquals(serviceUrl + service.getUrl() + "?id=" + orderableId.toString(), uri.toString());
assertAuthHeader(entityCaptor.getValue());
assertNull(entityCaptor.getValue().getBody());
}
use of org.openlmis.stockmanagement.util.DynamicPageTypeReference in project openlmis-stockmanagement by OpenLMIS.
the class BaseCommunicationService method doPageRequest.
private <E> ResponseEntity<PageImplRepresentation<E>> doPageRequest(String url, RequestParameters parameters, Object payload, HttpMethod method, Class<E> type) {
HttpEntity<Object> entity = createEntity(payload);
ParameterizedTypeReference<PageImplRepresentation<E>> parameterizedType = new DynamicPageTypeReference<>(type);
List<PageImplRepresentation<E>> pages = new ArrayList<>();
for (URI uri : RequestHelper.splitRequest(url, parameters, maxUrlLength)) {
pages.add(restTemplate.exchange(uri, method, entity, parameterizedType).getBody());
}
PageImplRepresentation<E> body = Merger.ofPages(pages).withDefaultValue(PageImplRepresentation::new).merge();
return new ResponseEntity<>(body, HttpStatus.OK);
}
use of org.openlmis.stockmanagement.util.DynamicPageTypeReference in project openlmis-stockmanagement by OpenLMIS.
the class ApprovedProductReferenceDataServiceTest method shouldReturnFullMapOfOrderableFulfills.
@Test
public void shouldReturnFullMapOfOrderableFulfills() {
UUID programId = randomUUID();
RequestParameters parameters = RequestParameters.init();
parameters.set("programId", programId);
ApprovedProductDto approvedProduct = generateInstance();
UUID facilityId = randomUUID();
mockPageResponseEntity(approvedProduct);
Page<OrderableDto> result = service.getApprovedProducts(facilityId, programId, null);
assertEquals(1, result.getTotalElements());
assertEquals(approvedProduct.getOrderable(), result.getContent().get(0));
verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(ApprovedProductDto.class)));
URI uri = uriCaptor.getValue();
assertThat(uri.toString(), not(containsString("orderableId")));
assertAuthHeader(entityCaptor.getValue());
assertNull(entityCaptor.getValue().getBody());
}
use of org.openlmis.stockmanagement.util.DynamicPageTypeReference in project openlmis-stockmanagement by OpenLMIS.
the class ApprovedProductReferenceDataServiceTest method shouldReturnMapOfOrderableFulfillsForGivenOrderables.
@Test
public void shouldReturnMapOfOrderableFulfillsForGivenOrderables() {
UUID programId = randomUUID();
List<UUID> orderableIds = asList(randomUUID(), randomUUID());
RequestParameters parameters = RequestParameters.init();
parameters.set("programId", programId);
parameters.set("orderableId", orderableIds);
ApprovedProductDto approvedProduct = generateInstance();
UUID facilityId = randomUUID();
mockPageResponseEntity(approvedProduct);
Page<OrderableDto> result = service.getApprovedProducts(facilityId, programId, orderableIds);
assertEquals(1, result.getTotalElements());
assertEquals(approvedProduct.getOrderable(), result.getContent().get(0));
verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(ApprovedProductDto.class)));
URI uri = uriCaptor.getValue();
assertThat(uri.toString(), containsString("orderableId=" + orderableIds.get(0)));
assertThat(uri.toString(), containsString("orderableId=" + orderableIds.get(1)));
assertAuthHeader(entityCaptor.getValue());
assertNull(entityCaptor.getValue().getBody());
}
use of org.openlmis.stockmanagement.util.DynamicPageTypeReference in project openlmis-stockmanagement by OpenLMIS.
the class OrderableReferenceDataServiceTest method shouldReturnOrderables.
@Test
public void shouldReturnOrderables() {
OrderableDto product = mockPageResponseEntityAndGetDto();
List<OrderableDto> response = service.findAll();
assertThat(response, hasSize(1));
assertThat(response, hasItem(product));
verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(OrderableDto.class)));
URI uri = uriCaptor.getValue();
assertEquals(serviceUrl + service.getUrl(), uri.toString());
assertAuthHeader(entityCaptor.getValue());
assertNull(entityCaptor.getValue().getBody());
}
Aggregations