From eb1460377e501a92e32495bced0e791cfd6eda9f Mon Sep 17 00:00:00 2001 From: Ralf Ueberfuhr Date: Tue, 19 Dec 2023 11:33:54 +0100 Subject: [PATCH] add further tests --- .../BlogPostControllerIntegrationTests.java | 33 +++++++++++++++++++ .../spring/blog/BlogPostControllerTests.java | 28 ++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/test/java/de/sample/schulung/spring/blog/BlogPostControllerIntegrationTests.java create mode 100644 src/test/java/de/sample/schulung/spring/blog/BlogPostControllerTests.java diff --git a/src/test/java/de/sample/schulung/spring/blog/BlogPostControllerIntegrationTests.java b/src/test/java/de/sample/schulung/spring/blog/BlogPostControllerIntegrationTests.java new file mode 100644 index 0000000..8f4356a --- /dev/null +++ b/src/test/java/de/sample/schulung/spring/blog/BlogPostControllerIntegrationTests.java @@ -0,0 +1,33 @@ +package de.sample.schulung.spring.blog; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; + +import static org.assertj.core.api.Assertions.assertThat; + +// SO NICHT! +@SpringBootTest +public class BlogPostControllerIntegrationTests { + + @Autowired + BlogPostController controller; + + @Test + void shouldCreateBlogPostSuccessfully() { + final var blogPost = new BlogPostDto(); + blogPost.setTitle("test"); + blogPost.setContent("Das ist ein Test"); + + final var result = controller.createBlogPost(blogPost); + + assertThat(result.getStatusCode().value()) + .isEqualTo(HttpStatus.CREATED.value()); + assertThat(result.getBody()) + .isNotNull(); + assertThat(result.getBody().getTitle()) + .isEqualTo(blogPost.getTitle()); + + } +} diff --git a/src/test/java/de/sample/schulung/spring/blog/BlogPostControllerTests.java b/src/test/java/de/sample/schulung/spring/blog/BlogPostControllerTests.java new file mode 100644 index 0000000..0c2a707 --- /dev/null +++ b/src/test/java/de/sample/schulung/spring/blog/BlogPostControllerTests.java @@ -0,0 +1,28 @@ +package de.sample.schulung.spring.blog; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; + +import static org.assertj.core.api.Assertions.assertThat; + +public class BlogPostControllerTests { + + @Test + void shouldCreateBlogPostSuccessfully() { + final var controller = new BlogPostController(); + final var blogPost = new BlogPostDto(); + blogPost.setTitle("test"); + blogPost.setContent("Das ist ein Test"); + + final var result = controller.createBlogPost(blogPost); + + assertThat(result.getStatusCode().value()) + .isEqualTo(HttpStatus.CREATED.value()); + assertThat(result.getBody()) + .isNotNull(); + assertThat(result.getBody().getTitle()) + .isEqualTo(blogPost.getTitle()); + + } + +}