diff --git a/src/main/java/de/kamillionlabs/hateoflux/http/HalListResponse.java b/src/main/java/de/kamillionlabs/hateoflux/http/HalListResponse.java index c1f353d..8a723bb 100644 --- a/src/main/java/de/kamillionlabs/hateoflux/http/HalListResponse.java +++ b/src/main/java/de/kamillionlabs/hateoflux/http/HalListResponse.java @@ -172,6 +172,19 @@ public static HalListResponse ok( return new HalListResponse<>(body, Mono.just(HttpStatus.OK), null); } + /** + * Creates a {@link HalListResponse} with {@link HttpStatus#OK}. + * + * @param + * the resource type + * @param + * the embedded resource type + * @return a {@link HalListResponse} with {@code OK} status + */ + public static HalListResponse ok() { + return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.OK), null); + } + /** * Creates a {@link HalListResponse} with a body and {@link HttpStatus#CREATED}. * @@ -192,6 +205,19 @@ public static HalListResponse creat return new HalListResponse<>(body, Mono.just(HttpStatus.CREATED), null); } + /** + * Creates a {@link HalListResponse} with {@link HttpStatus#CREATED}. + * + * @param + * the resource type + * @param + * the embedded resource type + * @return a {@link HalListResponse} with {@code CREATED} status + */ + public static HalListResponse created() { + return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.CREATED), null); + } + /** * Creates a {@link HalListResponse} with a body and {@link HttpStatus#ACCEPTED}. * @@ -213,29 +239,29 @@ public static HalListResponse accep } /** - * Creates a {@link HalListResponse} with no body and {@link HttpStatus#NO_CONTENT}. + * Creates a {@link HalListResponse} with {@link HttpStatus#ACCEPTED}. * * @param * the resource type * @param * the embedded resource type - * @return a {@link HalListResponse} with {@code NO_CONTENT} status + * @return a {@link HalListResponse} with {@code ACCEPTED} status */ - public static HalListResponse noContent() { - return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.NO_CONTENT), null); + public static HalListResponse accepted() { + return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.ACCEPTED), null); } /** - * Creates a {@link HalListResponse} with no body and {@link HttpStatus#BAD_REQUEST}. + * Creates a {@link HalListResponse} with no body and {@link HttpStatus#NO_CONTENT}. * * @param * the resource type * @param * the embedded resource type - * @return a {@link HalListResponse} with {@code BAD_REQUEST} status + * @return a {@link HalListResponse} with {@code NO_CONTENT} status */ - public static HalListResponse badRequest() { - return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.BAD_REQUEST), null); + public static HalListResponse noContent() { + return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.NO_CONTENT), null); } /** @@ -250,30 +276,4 @@ public static HalListResponse badRe public static HalListResponse notFound() { return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.NOT_FOUND), null); } - - /** - * Creates a {@link HalListResponse} with no body and {@link HttpStatus#FORBIDDEN}. - * - * @param - * the resource type - * @param - * the embedded resource type - * @return a {@link HalListResponse} with {@code FORBIDDEN} status - */ - public static HalListResponse forbidden() { - return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.FORBIDDEN), null); - } - - /** - * Creates a {@link HalListResponse} with no body and {@link HttpStatus#UNAUTHORIZED}. - * - * @param - * the resource type - * @param - * the embedded resource type - * @return a {@link HalListResponse} with {@code UNAUTHORIZED} status - */ - public static HalListResponse unauthorized() { - return new HalListResponse<>(Mono.empty(), Mono.just(HttpStatus.UNAUTHORIZED), null); - } } diff --git a/src/main/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponse.java b/src/main/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponse.java index 4ef4d46..0536bbe 100644 --- a/src/main/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponse.java +++ b/src/main/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponse.java @@ -52,7 +52,8 @@ * {@link HalResourceWrapper}/li> *
  • {@link HalMultiResourceResponse}: Use when your endpoint returns multiple * {@link HalResourceWrapper}
  • - *
  • {@link HalListResponse}: Use when your endpoint returns a single {@link HalListWrapper}
  • + *
  • {@link HalMultiResourceResponse}: Use when your endpoint returns a single + * {@link HalListWrapper}
  • * * * @param @@ -166,6 +167,19 @@ public static HalMultiResourceResponse(body, HttpStatus.OK, null); } + /** + * Creates a {@link HalMultiResourceResponse} with {@link HttpStatus#OK}. + * + * @param + * the resource type + * @param + * the embedded resource type + * @return a {@link HalMultiResourceResponse} with {@code OK} status + */ + public static HalMultiResourceResponse ok() { + return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.OK, null); + } + /** * Creates a {@link HalMultiResourceResponse} with the given HAL resource body and {@link HttpStatus#CREATED}. * @@ -187,6 +201,19 @@ public static HalMultiResourceResponse(body, HttpStatus.CREATED, null); } + /** + * Creates a {@link HalMultiResourceResponse} with {@link HttpStatus#CREATED}. + * + * @param + * the resource type + * @param + * the embedded resource type + * @return a {@link HalMultiResourceResponse} with {@code CREATED} status + */ + public static HalMultiResourceResponse created() { + return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.CREATED, null); + } + /** * Creates a {@link HalMultiResourceResponse} with the given HAL resource body and {@link HttpStatus#ACCEPTED}. * @@ -209,29 +236,29 @@ public static HalMultiResourceResponse * the resource type * @param * the embedded resource type - * @return a {@link HalMultiResourceResponse} with {@code NO_CONTENT} status + * @return a {@link HalMultiResourceResponse} with {@code ACCEPTED} status */ - public static HalMultiResourceResponse noContent() { - return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.NO_CONTENT, null); + public static HalMultiResourceResponse accepted() { + return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.ACCEPTED, null); } /** - * Creates a {@link HalMultiResourceResponse} with no body and {@link HttpStatus#BAD_REQUEST}. + * Creates a {@link HalMultiResourceResponse} with no body and {@link HttpStatus#NO_CONTENT}. * * @param * the resource type * @param * the embedded resource type - * @return a {@link HalMultiResourceResponse} with {@code BAD_REQUEST} status + * @return a {@link HalMultiResourceResponse} with {@code NO_CONTENT} status */ - public static HalMultiResourceResponse badRequest() { - return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.BAD_REQUEST, null); + public static HalMultiResourceResponse noContent() { + return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.NO_CONTENT, null); } /** @@ -246,30 +273,4 @@ public static HalMultiResourceResponse HalMultiResourceResponse notFound() { return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.NOT_FOUND, null); } - - /** - * Creates a {@link HalMultiResourceResponse} with no body and {@link HttpStatus#FORBIDDEN}. - * - * @param - * the resource type - * @param - * the embedded resource type - * @return a {@link HalMultiResourceResponse} with {@code FORBIDDEN} status - */ - public static HalMultiResourceResponse forbidden() { - return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.FORBIDDEN, null); - } - - /** - * Creates a {@link HalMultiResourceResponse} with no body and {@link HttpStatus#UNAUTHORIZED}. - * - * @param - * the resource type - * @param - * the embedded resource type - * @return a {@link HalMultiResourceResponse} with {@code UNAUTHORIZED} status - */ - public static HalMultiResourceResponse unauthorized() { - return new HalMultiResourceResponse<>(Flux.empty(), HttpStatus.UNAUTHORIZED, null); - } } diff --git a/src/main/java/de/kamillionlabs/hateoflux/http/HalResourceResponse.java b/src/main/java/de/kamillionlabs/hateoflux/http/HalResourceResponse.java index b114aea..874d253 100644 --- a/src/main/java/de/kamillionlabs/hateoflux/http/HalResourceResponse.java +++ b/src/main/java/de/kamillionlabs/hateoflux/http/HalResourceResponse.java @@ -49,7 +49,8 @@ * {@link HalResourceWrapper}/li> *
  • {@link HalMultiResourceResponse}: Use when your endpoint returns multiple * {@link HalResourceWrapper}
  • - *
  • {@link HalListResponse}: Use when your endpoint returns a single {@link HalListWrapper}
  • + *
  • {@link HalResourceResponse}: Use when your endpoint returns a single {@link HalListWrapper} + *
  • * * * @param @@ -173,6 +174,19 @@ public static HalResourceResponse o return new HalResourceResponse<>(body, Mono.just(HttpStatus.OK), null); } + /** + * Creates a {@link HalResourceResponse} with {@link HttpStatus#OK}. + * + * @param + * the resource type + * @param + * the embedded resource type + * @return a {@link HalResourceResponse} with {@code OK} status + */ + public static HalResourceResponse ok() { + return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.OK), null); + } + /** * Creates a {@code HalResourceResponse} with a body and {@link HttpStatus#CREATED}. * @@ -193,6 +207,19 @@ public static HalResourceResponse c return new HalResourceResponse<>(body, Mono.just(HttpStatus.CREATED), null); } + /** + * Creates a {@link HalResourceResponse} with {@link HttpStatus#CREATED}. + * + * @param + * the resource type + * @param + * the embedded resource type + * @return a {@link HalResourceResponse} with {@code CREATED} status + */ + public static HalResourceResponse created() { + return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.CREATED), null); + } + /** * Creates a {@code HalResourceResponse} with a body and {@link HttpStatus#ACCEPTED}. * @@ -214,29 +241,29 @@ public static HalResourceResponse a } /** - * Creates a {@code HalResourceResponse} with no body and {@link HttpStatus#NO_CONTENT}. + * Creates a {@link HalResourceResponse} with {@link HttpStatus#ACCEPTED}. * * @param * the resource type * @param * the embedded resource type - * @return a {@code HalResourceResponse} with {@code NO_CONTENT} status + * @return a {@link HalResourceResponse} with {@code ACCEPTED} status */ - public static HalResourceResponse noContent() { - return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.NO_CONTENT), null); + public static HalResourceResponse accepted() { + return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.ACCEPTED), null); } /** - * Creates a {@code HalResourceResponse} with no body and {@link HttpStatus#BAD_REQUEST}. + * Creates a {@code HalResourceResponse} with no body and {@link HttpStatus#NO_CONTENT}. * * @param * the resource type * @param * the embedded resource type - * @return a {@code HalResourceResponse} with {@code BAD_REQUEST} status + * @return a {@code HalResourceResponse} with {@code NO_CONTENT} status */ - public static HalResourceResponse badRequest() { - return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.BAD_REQUEST), null); + public static HalResourceResponse noContent() { + return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.NO_CONTENT), null); } /** @@ -251,30 +278,4 @@ public static HalResourceResponse b public static HalResourceResponse notFound() { return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.NOT_FOUND), null); } - - /** - * Creates a {@code HalResourceResponse} with no body and {@link HttpStatus#FORBIDDEN}. - * - * @param - * the resource type - * @param - * the embedded resource type - * @return a {@code HalResourceResponse} with {@code FORBIDDEN} status - */ - public static HalResourceResponse forbidden() { - return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.FORBIDDEN), null); - } - - /** - * Creates a {@code HalResourceResponse} with no body and {@link HttpStatus#UNAUTHORIZED}. - * - * @param - * the resource type - * @param - * the embedded resource type - * @return a {@code HalResourceResponse} with {@code UNAUTHORIZED} status - */ - public static HalResourceResponse unauthorized() { - return new HalResourceResponse<>(Mono.empty(), Mono.just(HttpStatus.UNAUTHORIZED), null); - } } diff --git a/src/test/java/de/kamillionlabs/hateoflux/http/HalListResponseTest.java b/src/test/java/de/kamillionlabs/hateoflux/http/HalListResponseTest.java index a607eac..c76fe66 100644 --- a/src/test/java/de/kamillionlabs/hateoflux/http/HalListResponseTest.java +++ b/src/test/java/de/kamillionlabs/hateoflux/http/HalListResponseTest.java @@ -104,31 +104,16 @@ void givenFactoryMethodOk_whenCalled_thenCreatesResponseWithOkStatus() { } @Test - void givenFactoryMethodUnauthorized_whenCalled_thenCreatesResponseWithUnauthorizedStatus() { + void givenFactoryMethodOkWithoutBody_whenCalled_thenCreatesResponseWithOkStatus() { // GIVEN - HalListResponse response = HalListResponse.unauthorized(); + HalListResponse response = HalListResponse.ok(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); // THEN assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void givenFactoryMethodForbidden_whenCalled_thenCreatesResponseWithForbiddenStatus() { - // GIVEN - HalListResponse response = HalListResponse.forbidden(); - - // WHEN - ResponseEntity entity = response.toResponseEntity().block(); - - // THEN - assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test @@ -145,20 +130,6 @@ void givenFactoryMethodNotFound_whenCalled_thenCreatesResponseWithNotFoundStatus assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } - @Test - void givenFactoryMethodBadRequest_whenCalled_thenCreatesResponseWithBadRequestStatus() { - // GIVEN - HalListResponse response = HalListResponse.badRequest(); - - // WHEN - ResponseEntity entity = response.toResponseEntity().block(); - - // THEN - assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); - } - @Test void givenFactoryMethodOfWithBodyAndStatus_whenCalled_thenCreatesResponseCorrectly() { // GIVEN @@ -215,6 +186,19 @@ void givenFactoryMethodCreated_whenCalled_thenCreatesResponseWithCreatedStatus() assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CREATED); } + @Test + void givenFactoryMethodCreatedWithoutBody_whenCalled_thenCreatesResponseWithCreatedStatus() { + // GIVEN + HalListResponse response = HalListResponse.created(); + + // WHEN + ResponseEntity entity = response.toResponseEntity().block(); + + // THEN + assertThat(entity).isNotNull(); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + } + @Test void givenFactoryMethodAccepted_whenCalled_thenCreatesResponseWithAcceptedStatus() { // GIVEN @@ -228,4 +212,17 @@ void givenFactoryMethodAccepted_whenCalled_thenCreatesResponseWithAcceptedStatus assertThat(entity.getBody()).isEqualTo(mockWrapper); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); } + + @Test + void givenFactoryMethodAcceptedWithoutBody_whenCalled_thenCreatesResponseWithAcceptedStatus() { + // GIVEN + HalListResponse response = HalListResponse.accepted(); + + // WHEN + ResponseEntity entity = response.toResponseEntity().block(); + + // THEN + assertThat(entity).isNotNull(); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); + } } diff --git a/src/test/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponseTest.java b/src/test/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponseTest.java index 2eadb47..ef17cd9 100644 --- a/src/test/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponseTest.java +++ b/src/test/java/de/kamillionlabs/hateoflux/http/HalMultiResourceResponseTest.java @@ -122,26 +122,22 @@ void givenFactoryMethodOk_whenCalled_thenCreatesResponseWithOkStatus() { } @Test - void givenFactoryMethodUnauthorized_whenCalled_thenCreatesResponseWithUnauthorizedStatus() { + void givenFactoryMethodOkWithoutBody_whenCalled_thenCreatesResponseWithOkStatus() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.unauthorized(); + HalMultiResourceResponse response = HalMultiResourceResponse.ok(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); // THEN assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNotNull(); - Flux body = (Flux) entity.getBody(); - Mono hasElements = body.hasElements(); - assertEquals(Boolean.FALSE, hasElements.block()); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test - void givenFactoryMethodForbidden_whenCalled_thenCreatesResponseWithForbiddenStatus() { + void givenFactoryMethodNotFound_whenCalled_thenCreatesResponseWithNotFoundStatus() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.forbidden(); + HalMultiResourceResponse response = HalMultiResourceResponse.notFound(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); @@ -152,13 +148,13 @@ void givenFactoryMethodForbidden_whenCalled_thenCreatesResponseWithForbiddenStat Flux body = (Flux) entity.getBody(); Mono hasElements = body.hasElements(); assertEquals(Boolean.FALSE, hasElements.block()); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } @Test - void givenFactoryMethodNotFound_whenCalled_thenCreatesResponseWithNotFoundStatus() { + void givenFactoryMethodOfWithBodyAndStatus_whenCalled_thenCreatesResponseCorrectly() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.notFound(); + HalMultiResourceResponse response = HalMultiResourceResponse.of(mockBody, conflictStatus); // WHEN ResponseEntity entity = response.toResponseEntity().block(); @@ -166,16 +162,15 @@ void givenFactoryMethodNotFound_whenCalled_thenCreatesResponseWithNotFoundStatus // THEN assertThat(entity).isNotNull(); assertThat(entity.getBody()).isNotNull(); - Flux body = (Flux) entity.getBody(); - Mono hasElements = body.hasElements(); - assertEquals(Boolean.FALSE, hasElements.block()); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + Flux> body = (Flux) entity.getBody(); + assertThat(body.blockFirst()).isEqualTo(mockWrapper); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CONFLICT); } @Test - void givenFactoryMethodBadRequest_whenCalled_thenCreatesResponseWithBadRequestStatus() { + void givenFactoryMethodOfWithOnlyStatus_whenCalled_thenCreatesResponseCorrectly() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.badRequest(); + HalMultiResourceResponse response = HalMultiResourceResponse.of(conflictStatus); // WHEN ResponseEntity entity = response.toResponseEntity().block(); @@ -186,13 +181,13 @@ void givenFactoryMethodBadRequest_whenCalled_thenCreatesResponseWithBadRequestSt Flux body = (Flux) entity.getBody(); Mono hasElements = body.hasElements(); assertEquals(Boolean.FALSE, hasElements.block()); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CONFLICT); } @Test - void givenFactoryMethodOfWithBodyAndStatus_whenCalled_thenCreatesResponseCorrectly() { + void givenNoContentFactory_whenCalled_thenCreatesResponseWithNoContentStatus() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.of(mockBody, conflictStatus); + HalMultiResourceResponse response = HalMultiResourceResponse.noContent(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); @@ -200,43 +195,36 @@ void givenFactoryMethodOfWithBodyAndStatus_whenCalled_thenCreatesResponseCorrect // THEN assertThat(entity).isNotNull(); assertThat(entity.getBody()).isNotNull(); - Flux> body = (Flux) entity.getBody(); - assertThat(body.blockFirst()).isEqualTo(mockWrapper); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CONFLICT); + Flux body = (Flux) entity.getBody(); + Mono hasElements = body.hasElements(); + assertEquals(Boolean.FALSE, hasElements.block()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } @Test - void givenFactoryMethodOfWithOnlyStatus_whenCalled_thenCreatesResponseCorrectly() { + void givenFactoryMethodCreatedWithoutBody_whenCalled_thenCreatesResponseWithCreatedStatus() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.of(conflictStatus); + HalMultiResourceResponse response = HalMultiResourceResponse.created(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); // THEN assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNotNull(); - Flux body = (Flux) entity.getBody(); - Mono hasElements = body.hasElements(); - assertEquals(Boolean.FALSE, hasElements.block()); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CONFLICT); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CREATED); } @Test - void givenNoContentFactory_whenCalled_thenCreatesResponseWithNoContentStatus() { + void givenFactoryMethodAcceptedWithoutBody_whenCalled_thenCreatesResponseWithAcceptedStatus() { // GIVEN - HalMultiResourceResponse response = HalMultiResourceResponse.noContent(); + HalMultiResourceResponse response = HalMultiResourceResponse.accepted(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); // THEN assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNotNull(); - Flux body = (Flux) entity.getBody(); - Mono hasElements = body.hasElements(); - assertEquals(Boolean.FALSE, hasElements.block()); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); } @Test diff --git a/src/test/java/de/kamillionlabs/hateoflux/http/HalResourceResponseTest.java b/src/test/java/de/kamillionlabs/hateoflux/http/HalResourceResponseTest.java index 9eedc60..00b21ae 100644 --- a/src/test/java/de/kamillionlabs/hateoflux/http/HalResourceResponseTest.java +++ b/src/test/java/de/kamillionlabs/hateoflux/http/HalResourceResponseTest.java @@ -102,31 +102,16 @@ void givenFactoryMethodOk_whenCalled_thenCreatesResponseWithOkStatus() { } @Test - void givenFactoryMethodUnauthorized_whenCalled_thenCreatesResponseWithUnauthorizedStatus() { + void givenFactoryMethodOkWithoutBody_whenCalled_thenCreatesResponseWithBadRequestStatus() { // GIVEN - HalResourceResponse response = HalResourceResponse.unauthorized(); + HalResourceResponse response = HalResourceResponse.ok(); // WHEN ResponseEntity entity = response.toResponseEntity().block(); // THEN assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void givenFactoryMethodForbidden_whenCalled_thenCreatesResponseWithForbiddenStatus() { - // GIVEN - HalResourceResponse response = HalResourceResponse.forbidden(); - - // WHEN - ResponseEntity entity = response.toResponseEntity().block(); - - // THEN - assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test @@ -139,24 +124,9 @@ void givenFactoryMethodNotFound_whenCalled_thenCreatesResponseWithNotFoundStatus // THEN assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } - @Test - void givenFactoryMethodBadRequest_whenCalled_thenCreatesResponseWithBadRequestStatus() { - // GIVEN - HalResourceResponse response = HalResourceResponse.badRequest(); - - // WHEN - ResponseEntity entity = response.toResponseEntity().block(); - - // THEN - assertThat(entity).isNotNull(); - assertThat(entity.getBody()).isNull(); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); - } - @Test void givenFactoryMethodOfWithBodyAndStatus_whenCalled_thenCreatesResponseCorrectly() { // GIVEN @@ -226,4 +196,31 @@ void givenFactoryMethodAccepted_whenCalled_thenCreatesResponseWithAcceptedStatus assertThat(entity.getBody()).isEqualTo(mockWrapper); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); } + + @Test + void givenFactoryMethodCreatedWithoutBody_whenCalled_thenCreatesResponseWithUnauthorizedStatus() { + // GIVEN + HalResourceResponse response = HalResourceResponse.created(); + + // WHEN + ResponseEntity entity = response.toResponseEntity().block(); + + // THEN + assertThat(entity).isNotNull(); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + } + + @Test + void givenFactoryMethodAcceptedWithoutBody_whenCalled_thenCreatesResponseWithForbiddenStatus() { + // GIVEN + HalResourceResponse response = HalResourceResponse.accepted(); + + // WHEN + ResponseEntity entity = response.toResponseEntity().block(); + + // THEN + assertThat(entity).isNotNull(); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); + } + } \ No newline at end of file