11package org .baeldung ;
22
3- import org .baeldung .domain .GenericEntity ;
4- import org .baeldung .repository .GenericEntityRepository ;
3+ import static org .hamcrest .Matchers .equalTo ;
4+ import static org .hamcrest .Matchers .hasSize ;
5+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
6+
57import org .junit .Before ;
68import org .junit .Test ;
79import org .junit .runner .RunWith ;
1820
1921import java .nio .charset .Charset ;
2022
21- import static org .hamcrest .Matchers .hasSize ;
22- import static org .junit .Assert .assertEquals ;
23- import static org .junit .Assert .assertNotNull ;
24- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
25-
2623@ RunWith (SpringJUnit4ClassRunner .class )
2724@ SpringApplicationConfiguration (classes = Application .class )
2825@ WebAppConfiguration
@@ -42,4 +39,34 @@ public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect()
4239
4340 mockMvc .perform (MockMvcRequestBuilders .get ("/entity/all" )).andExpect (MockMvcResultMatchers .status ().isOk ()).andExpect (MockMvcResultMatchers .content ().contentType (contentType )).andExpect (jsonPath ("$" , hasSize (4 )));
4441 }
42+
43+ @ Test
44+ public void givenRequestHasBeenMade_whenMeetsFindByDateOfGivenConditions_thenCorrect () throws Exception {
45+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
46+
47+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbydate/{date}" , "2011-12-03T10:15:30" ))
48+ .andExpect (MockMvcResultMatchers .status ().isOk ())
49+ .andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
50+ .andExpect (jsonPath ("$.id" , equalTo (1 )));
51+ }
52+
53+ @ Test
54+ public void givenRequestHasBeenMade_whenMeetsFindByModeOfGivenConditions_thenCorrect () throws Exception {
55+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
56+
57+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbymode/{mode}" , "Alpha" ))
58+ .andExpect (MockMvcResultMatchers .status ().isOk ())
59+ .andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
60+ .andExpect (jsonPath ("$.id" , equalTo (1 )));
61+ }
62+
63+ @ Test
64+ public void givenRequestHasBeenMade_whenMeetsFindByVersionOfGivenConditions_thenCorrect () throws Exception {
65+ MediaType contentType = new MediaType (MediaType .APPLICATION_JSON .getType (), MediaType .APPLICATION_JSON .getSubtype (), Charset .forName ("utf8" ));
66+
67+ mockMvc .perform (MockMvcRequestBuilders .get ("/entity/findbyversion" ).header ("Version" , "1.0.0" ))
68+ .andExpect (MockMvcResultMatchers .status ().isOk ())
69+ .andExpect (MockMvcResultMatchers .content ().contentType (contentType ))
70+ .andExpect (jsonPath ("$.id" , equalTo (1 )));
71+ }
4572}
0 commit comments