This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ralf Ueberfuhr
committed
Dec 19, 2023
1 parent
2a3ab32
commit eb14603
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/test/java/de/sample/schulung/spring/blog/BlogPostControllerIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/de/sample/schulung/spring/blog/BlogPostControllerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
|
||
} | ||
|
||
} |