-
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.
impl get post by id & get all post with a basic int. test
- Loading branch information
Showing
4 changed files
with
92 additions
and
53 deletions.
There are no files selected for viewing
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
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
38 changes: 0 additions & 38 deletions
38
src/test/java/com/thoughtworks/SpringBootPocApplicationTest.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/test/java/com/thoughtworks/post/PostControllerIntegrationTest.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,44 @@ | ||
package com.thoughtworks.post; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
public class PostControllerIntegrationTest { | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Autowired | ||
private PostController postController; | ||
|
||
@Test | ||
public void testThatAPostIsCreated() throws Exception { | ||
Post post = new Post("Test Title", "Test Content"); | ||
ResponseEntity<String> entity = this.restTemplate.postForEntity("/post", post, String.class); | ||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.CREATED); | ||
String entityBody = entity.getBody(); | ||
assertThat(entityBody).startsWith( | ||
"{\"title\":\"Test Title\",\"content\":\"Test Content\""); | ||
assertThat(entityBody).contains("_links\":{\"self\":{\"href\""); | ||
|
||
int idStartIndex = entityBody.lastIndexOf("/") + 1; | ||
String id = entityBody.substring(idStartIndex, entityBody.length() - 4); | ||
|
||
assertNotNull(postController.getPosts().get(UUID.fromString(id))); | ||
} | ||
|
||
} |