use of org.springframework.core.ParameterizedTypeReference in project java-chassis by ServiceComb.
the class TestRestTemplateWrapper method testRestTemplate.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRestTemplate() {
new MockUp<RestTemplateWrapper>() {
@Mock
private boolean isCse(URI url) {
return false;
}
};
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();
MockUtil.getInstance().mockRestTemplate();
RestTemplateWrapper lRestTemplateWrapper = (RestTemplateWrapper) RestTemplateBuilder.create();
lRestTemplateWrapper.put(URI.create("csd://test"), new Object());
lRestTemplateWrapper.delete(URI.create("cse://test"));
lRestTemplateWrapper.put("csd://test", new Object());
lRestTemplateWrapper.getForObject("csd://test", new Object().getClass());
lRestTemplateWrapper.getForEntity("csd://test", new Object().getClass());
lRestTemplateWrapper.postForObject("csd://test", new Object(), new Object().getClass());
lRestTemplateWrapper.postForEntity("csd://test", new Object(), new Object().getClass());
lRestTemplateWrapper.exchange("csd://test", HttpMethod.GET, HttpEntity.EMPTY, new Object().getClass());
lRestTemplateWrapper.delete("csd://test", new Object());
lRestTemplateWrapper.delete("csd://test", new HashMap<>());
Map<String, ?> uriVariables = new HashMap<>();
lRestTemplateWrapper.getForObject("csd://test", new Object().getClass(), uriVariables);
lRestTemplateWrapper.getForEntity("csd://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("csd://test", new Object(), new Object().getClass(), uriVariables);
lRestTemplateWrapper.postForObject(URI.create("cse://test"), new Object(), new Object().getClass());
lRestTemplateWrapper.postForEntity("csd://test", new Object(), new Object().getClass(), uriVariables);
lRestTemplateWrapper.postForEntity(URI.create("cse://test"), new Object(), new Object().getClass());
lRestTemplateWrapper.put("csd://test", new Object(), uriVariables);
lRestTemplateWrapper.exchange("csd://test", HttpMethod.GET, HttpEntity.EMPTY, new Object().getClass(), uriVariables);
ParameterizedTypeReference instance = Mockito.mock(ParameterizedTypeReference.class);
lRestTemplateWrapper.exchange("csd://test", HttpMethod.GET, HttpEntity.EMPTY, instance, uriVariables);
lRestTemplateWrapper.exchange("csd://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);
}
}
use of org.springframework.core.ParameterizedTypeReference in project spring-framework by spring-projects.
the class RestTemplateIntegrationTests method jsonPostForObjectWithJacksonTypeInfoList.
// SPR-13154
@Test
public void jsonPostForObjectWithJacksonTypeInfoList() throws URISyntaxException {
List<ParentClass> list = new ArrayList<>();
list.add(new Foo("foo"));
list.add(new Bar("bar"));
ParameterizedTypeReference<?> typeReference = new ParameterizedTypeReference<List<ParentClass>>() {
};
RequestEntity<List<ParentClass>> entity = RequestEntity.post(new URI(baseUrl + "/jsonpost")).contentType(new MediaType("application", "json", StandardCharsets.UTF_8)).body(list, typeReference.getType());
String content = template.exchange(entity, String.class).getBody();
assertTrue(content.contains("\"type\":\"foo\""));
assertTrue(content.contains("\"type\":\"bar\""));
}
use of org.springframework.core.ParameterizedTypeReference in project amos-ss17-alexa by c-i-ber.
the class AccountAPI method getCardsForAccount.
/**
* Get all cards (credit / debit) for the given account.
*
* @param accountNumber Account number
* @return Collection of Cards
* @throws HttpClientErrorException
*/
public static Collection<Card> getCardsForAccount(String accountNumber) throws HttpClientErrorException {
// TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
Traverson traverson = null;
try {
traverson = new Traverson(new URI(BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/cards"), MediaTypes.HAL_JSON);
} catch (URISyntaxException e) {
log.error("getCardsForAccount failed", e);
return null;
}
ParameterizedTypeReference<Resources<Card>> typeRefDevices = new ParameterizedTypeReference<Resources<Card>>() {
};
Resources<Card> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
return resResponses.getContent();
}
use of org.springframework.core.ParameterizedTypeReference in project amos-ss17-alexa by c-i-ber.
the class TransactionAPI method getTransactions.
/**
* Get all transactions for the given account.
*
* @param accountNumber Account number
* @return Collection of Cards
* @throws HttpClientErrorException
*/
private static Collection<Transaction> getTransactions(String accountNumber) throws HttpClientErrorException {
// TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
Traverson traverson = null;
String uri = BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/transactions";
log.info("URI: " + uri);
try {
traverson = new Traverson(new URI(uri), MediaTypes.HAL_JSON);
} catch (URISyntaxException e) {
log.error("getTransactionsForAccount failed", e);
return null;
}
ParameterizedTypeReference<Resources<Transaction>> typeRefDevices = new ParameterizedTypeReference<Resources<Transaction>>() {
};
Resources<Transaction> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
return resResponses.getContent();
}
use of org.springframework.core.ParameterizedTypeReference in project incubator-servicecomb-java-chassis by apache.
the class TestRestTemplateWrapper method exchangeUsingParameterizedTypeWithUnderlyingRestTemplate.
@Test
public void exchangeUsingParameterizedTypeWithUnderlyingRestTemplate() {
ParameterizedTypeReference<List<String>> typeReference = new ParameterizedTypeReference<List<String>>() {
};
ResponseEntity<List<String>> actual;
for (HttpMethod method : httpMethods) {
when(underlying.exchange(url, method, requestEntity, typeReference, param1, param2)).thenReturn(typedResponse);
actual = wrapper.exchange(url, method, requestEntity, typeReference, param1, param2);
assertThat(actual, is(typedResponse));
verify(underlying).exchange(url, method, requestEntity, typeReference, param1, param2);
when(underlying.exchange(url, method, requestEntity, typeReference, paramsMap)).thenReturn(typedResponse);
actual = wrapper.exchange(url, method, requestEntity, typeReference, paramsMap);
assertThat(actual, is(typedResponse));
verify(underlying).exchange(url, method, requestEntity, typeReference, paramsMap);
when(underlying.exchange(uri, method, requestEntity, typeReference)).thenReturn(typedResponse);
actual = wrapper.exchange(uri, method, requestEntity, typeReference);
assertThat(actual, is(typedResponse));
verify(underlying).exchange(uri, method, requestEntity, typeReference);
RequestEntity<String> request = new RequestEntity<>(method, uri);
when(underlying.exchange(request, typeReference)).thenReturn(typedResponse);
actual = wrapper.exchange(request, typeReference);
assertThat(actual, is(typedResponse));
verify(underlying).exchange(request, typeReference);
}
}
Aggregations