Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
add further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Ueberfuhr committed Dec 19, 2023
1 parent 2a3ab32 commit eb14603
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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());

}
}
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());

}

}

0 comments on commit eb14603

Please sign in to comment.