@Test public void accessServiceUsingRestTemplate() { // Access root resource URI uri = URI.create(String.format(SERVICE_URI, port)); RequestEntity<Void> request = RequestEntity.get(uri).accept(HAL_JSON).build(); Resource<Object> rootLinks = restOperations.exchange(request, new ResourceType<Object>() {}).getBody(); Links links = new Links(rootLinks.getLinks()); // Follow stores link Link storesLink = links.getLink("stores").expand(); request = RequestEntity.get(URI.create(storesLink.getHref())).accept(HAL_JSON).build(); Resources<Store> stores = restOperations.exchange(request, new ResourcesType<Store>() {}).getBody(); stores.getContent().forEach(store -> log.info("{} - {}", store.name, store.address)); }
@Test @SuppressWarnings("rawtypes") public void testBindingExceptionForMachineClient() throws Exception { load(); RequestEntity request = RequestEntity.get(URI.create(createUrl("/bind"))) .accept(MediaType.APPLICATION_JSON) .build(); ResponseEntity<Map> entity = new TestRestTemplate().exchange(request, Map.class); String resp = entity.getBody().toString(); assertThat(resp, containsString("Error count: 1")); assertThat(resp, containsString("errors=[{")); assertThat(resp, containsString("codes=[")); assertThat(resp, containsString("org.springframework.validation.BindException")); }