use of org.springframework.core.ParameterizedTypeReference in project spring-cloud-gateway by spring-cloud.
the class SseIntegrationTests method sseAsEvent.
@Test
@SuppressWarnings("Duplicates")
public void sseAsEvent() {
ResolvableType type = forClassWithGenerics(ServerSentEvent.class, String.class);
Flux<ServerSentEvent<String>> result = this.webClient.get().uri("/event").accept(TEXT_EVENT_STREAM).exchange().flatMapMany(response -> response.body(toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {
})));
StepVerifier.create(result).consumeNextWith(event -> {
assertEquals("0", event.id());
assertEquals("foo", event.data());
assertEquals("bar", event.comment());
assertNull(event.event());
assertNull(event.retry());
}).consumeNextWith(event -> {
assertEquals("1", event.id());
assertEquals("foo", event.data());
assertEquals("bar", event.comment());
assertNull(event.event());
assertNull(event.retry());
}).thenCancel().verify(Duration.ofSeconds(5L));
}
use of org.springframework.core.ParameterizedTypeReference in project apollo by ctripcorp.
the class RetryableRestTemplateTest method testGetEntityWithNoAccessTokenForEnv.
@Test
public void testGetEntityWithNoAccessTokenForEnv() {
Env someEnv = Env.DEV;
Env anotherEnv = Env.PRO;
String someToken = "someToken";
ParameterizedTypeReference requestType = mock(ParameterizedTypeReference.class);
ResponseEntity someEntity = mock(ResponseEntity.class);
when(portalConfig.getAdminServiceAccessTokens()).thenReturn(mockAdminServiceTokens(someEnv, someToken));
when(serviceAddressLocator.getServiceList(someEnv)).thenReturn(Collections.singletonList(mockService(serviceOne)));
when(serviceAddressLocator.getServiceList(anotherEnv)).thenReturn(Collections.singletonList(mockService(serviceTwo)));
when(restTemplate.exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), any(HttpEntity.class), eq(requestType))).thenReturn(someEntity);
ResponseEntity actualResult = retryableRestTemplate.get(anotherEnv, path, requestType);
assertEquals(someEntity, actualResult);
ArgumentCaptor<HttpEntity> argumentCaptor = ArgumentCaptor.forClass(HttpEntity.class);
verify(restTemplate, times(1)).exchange(eq(serviceTwo + "/" + path), eq(HttpMethod.GET), argumentCaptor.capture(), eq(requestType));
HttpHeaders headers = argumentCaptor.getValue().getHeaders();
assertTrue(headers.isEmpty());
}
Aggregations