use of org.springframework.http.RequestEntity in project spring-boot by spring-projects.
the class SampleSessionRedisApplicationTests method sessionExpiry.
@Test
public void sessionExpiry() throws Exception {
String port = null;
try {
ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(SampleSessionRedisApplication.class).properties("server.port:0").initializers(new ServerPortInfoApplicationContextInitializer()).run();
port = context.getEnvironment().getProperty("local.server.port");
} catch (RuntimeException ex) {
if (!redisServerRunning(ex)) {
return;
}
throw ex;
}
URI uri = URI.create("http://localhost:" + port + "/");
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
String uuid1 = response.getBody();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("Cookie", response.getHeaders().getFirst("Set-Cookie"));
RequestEntity<Void> request = new RequestEntity<>(requestHeaders, HttpMethod.GET, uri);
String uuid2 = restTemplate.exchange(request, String.class).getBody();
assertThat(uuid1).isEqualTo(uuid2);
Thread.sleep(5000);
String uuid3 = restTemplate.exchange(request, String.class).getBody();
assertThat(uuid2).isNotEqualTo(uuid3);
}
use of org.springframework.http.RequestEntity in project spring-boot by spring-projects.
the class BasicErrorControllerIntegrationTests method testBindingExceptionForMachineClient.
@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).contains("Error count: 1");
assertThat(resp).contains("errors=[{");
assertThat(resp).contains("codes=[");
assertThat(resp).contains("org.springframework.validation.BindException");
}
use of org.springframework.http.RequestEntity in project java-chassis by ServiceComb.
the class TestRestTemplateWrapper method testRestTemplateWrapper.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRestTemplateWrapper() {
try {
MockUtil.getInstance().mockConsumerProviderManager();
MockUtil.getInstance().mockRegisterManager();
MockUtil.getInstance().mockServicePathManager();
MockUtil.getInstance().mockOperationLocator();
MockUtil.getInstance().mockOperationMeta();
MockUtil.getInstance().mockSchemaMeta();
MockUtil.getInstance().mockSchemaUtils();
MockUtil.getInstance().mockBeanUtils();
MockUtil.getInstance().mockRequestMeta();
MockUtil.getInstance().mockInvokerUtils();
RestTemplateWrapper lRestTemplateWrapper = (RestTemplateWrapper) RestTemplateBuilder.create();
lRestTemplateWrapper.put(URI.create("cse://test"), new Object());
lRestTemplateWrapper.delete(URI.create("cse://test"));
lRestTemplateWrapper.put("cse://test", new Object());
lRestTemplateWrapper.getForObject("cse://test", new Object().getClass());
lRestTemplateWrapper.getForEntity("cse://test", new Object().getClass());
lRestTemplateWrapper.postForObject("cse://test", new Object(), new Object().getClass());
lRestTemplateWrapper.postForEntity("cse://test", new Object(), new Object().getClass());
lRestTemplateWrapper.exchange("cse://test", HttpMethod.GET, HttpEntity.EMPTY, new Object().getClass());
lRestTemplateWrapper.delete("cse://test", new Object());
lRestTemplateWrapper.delete("cse://test", new HashMap<>());
Map<String, ?> uriVariables = new HashMap<>();
lRestTemplateWrapper.getForObject("cse://test", new Object().getClass(), uriVariables);
lRestTemplateWrapper.getForEntity("cse://test", new Object().getClass(), uriVariables);
lRestTemplateWrapper.getForObject(URI.create("cse://test"), new Object().getClass());
lRestTemplateWrapper.getForEntity(URI.create("cse://test"), new Object().getClass());
lRestTemplateWrapper.postForObject("cse://test", new Object(), new Object().getClass(), uriVariables);
lRestTemplateWrapper.postForObject(URI.create("cse://test"), new Object(), new Object().getClass());
lRestTemplateWrapper.postForEntity("cse://test", new Object(), new Object().getClass(), uriVariables);
lRestTemplateWrapper.postForEntity(URI.create("cse://test"), new Object(), new Object().getClass());
lRestTemplateWrapper.put("cse://test", new Object(), uriVariables);
lRestTemplateWrapper.put(URI.create("cse://test"), new Object());
lRestTemplateWrapper.exchange("cse://test", HttpMethod.GET, HttpEntity.EMPTY, new Object().getClass(), uriVariables);
ParameterizedTypeReference instance = Mockito.mock(ParameterizedTypeReference.class);
lRestTemplateWrapper.exchange("cse://test", HttpMethod.GET, HttpEntity.EMPTY, instance, uriVariables);
lRestTemplateWrapper.exchange("cse://test", HttpMethod.GET, HttpEntity.EMPTY, instance, new Object().getClass());
RequestEntity requestEntity = new RequestEntity<>(HttpMethod.GET, URI.create("cse://test"));
lRestTemplateWrapper.exchange(requestEntity, new Object().getClass());
lRestTemplateWrapper.exchange(requestEntity, instance);
lRestTemplateWrapper.exchange(URI.create("cse://test"), HttpMethod.GET, HttpEntity.EMPTY, new Object().getClass());
lRestTemplateWrapper.exchange(URI.create("cse://test"), HttpMethod.GET, HttpEntity.EMPTY, instance);
Assert.assertTrue(RestTemplateBuilder.create().getClass().isAssignableFrom(RestTemplateWrapper.class));
} catch (Exception e) {
Assert.assertNotNull(e);
}
}
Aggregations