Skip to content

Commit a41093d

Browse files
committed
BENCH-187 Example Integration test added
1 parent cb4087f commit a41093d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
package com.answerdigital.answerking;
22

33
import com.answerdigital.answerking.utility.AbstractContainerBaseTest;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
45
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
58
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.mock.web.MockHttpServletResponse;
11+
import org.springframework.test.web.servlet.MockMvc;
12+
import org.springframework.test.web.servlet.RequestBuilder;
13+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
14+
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertFalse;
617

718
@SpringBootTest
19+
@AutoConfigureMockMvc(addFilters = false)
820
class AnswerKingApplicationTest extends AbstractContainerBaseTest
921
{
22+
@Autowired
23+
private MockMvc mockMvc;
24+
1025
@Test
11-
void contextLoads(){
26+
void getAllProductsReturnListOfProductObjects() throws Exception {
27+
//when
28+
RequestBuilder request = MockMvcRequestBuilders.get("/products");
29+
MockHttpServletResponse response = mockMvc.perform(request).andReturn().getResponse();
1230

31+
//then
32+
assertEquals(HttpStatus.OK.value(), response.getStatus());
33+
assertFalse(response.getContentAsString().isEmpty());
34+
ObjectMapper mapper = new ObjectMapper();
35+
assertEquals("Burger", mapper.readTree(response.getContentAsString()).get(0).get("name").textValue());
36+
assertEquals("300g Beef", mapper.readTree(response.getContentAsString()).get(0).get("description").textValue());
37+
assertEquals(6.69, mapper.readTree(response.getContentAsString()).get(0).get("price").asDouble());
1338
}
1439
}

0 commit comments

Comments
 (0)