|
10 | 10 | import javax.ws.rs.core.Form; |
11 | 11 | import javax.ws.rs.core.MediaType; |
12 | 12 | import javax.ws.rs.core.Response; |
| 13 | +import javax.ws.rs.core.Response.Status; |
13 | 14 |
|
14 | 15 | import org.glassfish.jersey.test.JerseyTest; |
15 | 16 | import org.glassfish.jersey.test.TestProperties; |
@@ -63,6 +64,15 @@ public void givenCreateFruit_whenFormContainsNullParam_thenResponseCodeIsBadRequ |
63 | 64 | assertEquals("Http Response should be 400 ", 400, response.getStatus()); |
64 | 65 | assertThat(response.readEntity(String.class), containsString("Fruit colour must not be null")); |
65 | 66 | } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void givenCreateFruit_whenJsonIsCorrect_thenResponseCodeIsCreated() { |
| 70 | + Response response = target("fruit/created").request() |
| 71 | + .post(Entity.json("{\"name\":\"strawberry\",\"weight\":20}")); |
| 72 | + |
| 73 | + assertEquals("Http Response should be 201 ", Status.CREATED.getStatusCode(), response.getStatus()); |
| 74 | + assertThat(response.readEntity(String.class), containsString("Fruit saved : Fruit [name: strawberry colour: null]")); |
| 75 | + } |
66 | 76 |
|
67 | 77 | @Test |
68 | 78 | public void givenUpdateFruit_whenFormContainsBadSerialParam_thenResponseCodeIsBadRequest() { |
@@ -102,6 +112,23 @@ public void givenFruitExists_whenSearching_thenResponseContainsFruit() { |
102 | 112 | .get(String.class); |
103 | 113 | assertThat(json, containsString("{\"name\":\"strawberry\",\"weight\":20}")); |
104 | 114 | } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void givenFruitExists_whenSearching_thenResponseContainsFruitEntity() { |
| 118 | + Fruit fruit = new Fruit(); |
| 119 | + fruit.setName("strawberry"); |
| 120 | + fruit.setWeight(20); |
| 121 | + Response response = target("fruit/create").request(MediaType.APPLICATION_JSON_TYPE) |
| 122 | + .post(Entity.entity(fruit, MediaType.APPLICATION_JSON_TYPE)); |
| 123 | + |
| 124 | + assertEquals("Http Response should be 204 ", 204, response.getStatus()); |
| 125 | + |
| 126 | + final Fruit entity = target("fruit/search/strawberry").request() |
| 127 | + .get(Fruit.class); |
| 128 | + |
| 129 | + assertEquals("Fruit name: ", "strawberry", entity.getName()); |
| 130 | + assertEquals("Fruit weight: ", Integer.valueOf(20), entity.getWeight()); |
| 131 | + } |
105 | 132 |
|
106 | 133 | @Test |
107 | 134 | public void givenFruit_whenFruitIsInvalid_thenReponseContainsCustomExceptions() { |
|
0 commit comments