44import static org .hamcrest .Matchers .hasSize ;
55import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
66
7- import java .nio .charset .Charset ;
8-
9- import org .baeldung .config .H2JpaConfig ;
107import org .baeldung .domain .Modes ;
118import org .junit .Before ;
129import org .junit .Test ;
2219import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
2320import org .springframework .web .context .WebApplicationContext ;
2421
22+ import java .nio .charset .Charset ;
23+
2524@ RunWith (SpringJUnit4ClassRunner .class )
26- @ SpringBootTest (classes = { Application .class , H2JpaConfig . class } )
25+ @ SpringBootTest (classes = Application .class )
2726@ WebAppConfiguration
2827public class SpringBootApplicationIntegrationTest {
2928 @ Autowired
@@ -32,56 +31,36 @@ public class SpringBootApplicationIntegrationTest {
3231
3332 @ Before
3433 public void setupMockMvc () {
35- mockMvc = MockMvcBuilders .webAppContextSetup (webApplicationContext )
36- .build ();
34+ mockMvc = MockMvcBuilders .webAppContextSetup (webApplicationContext ).build ();
3735 }
3836
3937 @ Test
4038 public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect () throws Exception {
41- final MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
39+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
4240
43- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/all" ))
44- .andExpect (MockMvcResultMatchers .status ()
45- .isOk ())
46- .andExpect (MockMvcResultMatchers .content ()
47- .contentType (contentType ))
48- .andExpect (jsonPath ("$" , hasSize (4 )));
41+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/all" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType )).andExpect (jsonPath ("$" , hasSize (4 )));
4942 }
5043
5144 @ Test
5245 public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCorrect () throws Exception {
53- final MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
46+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
5447
55- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbydate/{date}" , "2011-12-03T10:15:30" ))
56- .andExpect (MockMvcResultMatchers .status ()
57- .isOk ())
58- .andExpect (MockMvcResultMatchers .content ()
59- .contentType (contentType ))
60- .andExpect (jsonPath ("$.id" , equalTo (1 )));
48+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbydate/{date}" , "2011-12-03T10:15:30" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
49+ .andExpect (jsonPath ("$.id" , equalTo (1 )));
6150 }
6251
6352 @ Test
6453 public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect () throws Exception {
65- final MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
54+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
6655
67- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbymode/{mode}" , Modes .ALPHA .name ()))
68- .andExpect (MockMvcResultMatchers .status ()
69- .isOk ())
70- .andExpect (MockMvcResultMatchers .content ()
71- .contentType (contentType ))
72- .andExpect (jsonPath ("$.id" , equalTo (1 )));
56+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbymode/{mode}" , Modes .ALPHA .name ())).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType )).andExpect (jsonPath ("$.id" , equalTo (1 )));
7357 }
7458
7559 @ Test
7660 public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect () throws Exception {
77- final MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
61+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
7862
79- mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbyversion" )
80- .header ("Version" , "1.0.0" ))
81- .andExpect (MockMvcResultMatchers .status ()
82- .isOk ())
83- .andExpect (MockMvcResultMatchers .content ()
84- .contentType (contentType ))
85- .andExpect (jsonPath ("$.id" , equalTo (1 )));
63+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbyversion" ).header ("Version" , "1.0.0" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
64+ .andExpect (jsonPath ("$.id" , equalTo (1 )));
8665 }
87- }
66+ }
0 commit comments