Skip to content

Commit b08f53c

Browse files
author
eugenp
committed
testing work and minor doc cleanup
1 parent 3130bcd commit b08f53c

3 files changed

Lines changed: 8 additions & 35 deletions

File tree

‎rest-testing/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55

66
### Relevant Articles:
7+
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)

‎rest-testing/src/test/java/org/baeldung/rest/ConvertUtil.java‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎rest-testing/src/test/java/org/baeldung/rest/RetrieveUtil.java‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,20 @@
22

33
import java.io.IOException;
44

5-
import org.apache.commons.io.IOUtils;
65
import org.apache.http.HttpResponse;
6+
import org.apache.http.util.EntityUtils;
77

8-
import com.google.common.base.Preconditions;
8+
import com.fasterxml.jackson.databind.DeserializationFeature;
9+
import com.fasterxml.jackson.databind.ObjectMapper;
910

1011
public class RetrieveUtil {
1112

12-
public static String retrieveJsonFromResponse(final HttpResponse response) throws IOException {
13-
Preconditions.checkNotNull(response);
14-
15-
return IOUtils.toString(response.getEntity().getContent());
16-
}
13+
// API
1714

1815
public static <T> T retrieveResourceFromResponse(final HttpResponse response, final Class<T> clazz) throws IOException {
19-
Preconditions.checkNotNull(response);
20-
Preconditions.checkNotNull(clazz);
21-
22-
final String jsonFromResponse = retrieveJsonFromResponse(response);
23-
return ConvertUtil.convertJsonToResource(jsonFromResponse, clazz);
16+
final String jsonFromResponse = EntityUtils.toString(response.getEntity());
17+
final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
18+
return mapper.readValue(jsonFromResponse, clazz);
2419
}
2520

2621
}

0 commit comments

Comments
 (0)