Skip to content

Commit e435948

Browse files
authored
add returnCustom to httpTestSecurity (#34)
1 parent 4637b60 commit e435948

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>it.aboutbits</groupId>
1313
<artifactId>spring-boot-testing</artifactId>
14-
<version>2.2.0</version>
14+
<version>2.3.0</version>
1515
<description>Testing library for Spring Boot projects.</description>
1616

1717
<properties>
@@ -25,7 +25,7 @@
2525
<dependency>
2626
<groupId>it.aboutbits</groupId>
2727
<artifactId>spring-boot-toolbox</artifactId>
28-
<version>2.4.1</version>
28+
<version>2.4.4</version>
2929
</dependency>
3030
<dependency>
3131
<groupId>it.aboutbits</groupId>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void testValidation() {
109109
}
110110
```
111111

112-
Alternatively you can use a method call to a service function to verify the validation. This is the preferred way as it makes sure that the bean validation is both triggered and also valid.
112+
Alternatively, you can use a method call to a service function to verify the validation. This is the preferred way as it makes sure that the bean validation is both triggered and also valid.
113113

114114
```java
115115
import org.springframework.beans.factory.annotation.Autowired;

src/main/java/it/aboutbits/springboot/testing/web/request/HttpTestSecurity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void assertDeleteGranted(String url, Object... pathVariables) {
170170
assertThatRequest(result).wasGranted();
171171
}
172172

173+
@SuppressWarnings("unused")
173174
public void assertDeleteDenied(String url, Object... pathVariables) {
174175
var result = httpTestClient.delete(url, pathVariables)
175176
.body("{}")

src/main/java/it/aboutbits/springboot/testing/web/request/Request.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ public <T> PagedResponse<T> returnPage(Class<T> clazz) {
193193
}
194194
}
195195

196+
@SneakyThrows(UnsupportedEncodingException.class)
197+
@SuppressWarnings("unused")
198+
public <T> T returnCustom(Class<T> clazz) {
199+
var res = _execute();
200+
201+
var resString = res.andReturn().getResponse().getContentAsString(StandardCharsets.UTF_8);
202+
203+
try {
204+
return jsonMapper.readValue(resString, clazz);
205+
} catch (JacksonException e) {
206+
log.error("Failed to read response as JSON.", e);
207+
throw new ResponseBodyException(e);
208+
}
209+
}
210+
196211
@SneakyThrows(UnsupportedEncodingException.class)
197212
@SuppressWarnings("unused")
198213
public ErrorResponse returnError() {

0 commit comments

Comments
 (0)