Search in sources :

Example 1 with DynamicPageTypeReference

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());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) UUID(java.util.UUID) URI(java.net.URI) Test(org.junit.Test)

Example 2 with DynamicPageTypeReference

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageImplRepresentation(org.openlmis.stockmanagement.util.PageImplRepresentation) ArrayList(java.util.ArrayList) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) URI(java.net.URI)

Example 3 with DynamicPageTypeReference

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());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) ApprovedProductDto(org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto) URI(java.net.URI) RequestParameters(org.openlmis.stockmanagement.util.RequestParameters) Test(org.junit.Test)

Example 4 with DynamicPageTypeReference

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());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) ApprovedProductDto(org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto) URI(java.net.URI) RequestParameters(org.openlmis.stockmanagement.util.RequestParameters) Test(org.junit.Test)

Example 5 with DynamicPageTypeReference

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());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)5 DynamicPageTypeReference (org.openlmis.stockmanagement.util.DynamicPageTypeReference)5 Test (org.junit.Test)4 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)4 UUID (java.util.UUID)3 UUID.randomUUID (java.util.UUID.randomUUID)2 ApprovedProductDto (org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto)2 RequestParameters (org.openlmis.stockmanagement.util.RequestParameters)2 ArrayList (java.util.ArrayList)1 PageImplRepresentation (org.openlmis.stockmanagement.util.PageImplRepresentation)1 ResponseEntity (org.springframework.http.ResponseEntity)1