File tree Expand file tree Collapse file tree
spring-boot/MyFirstSpringBoot Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+
5+ <groupId >com.baeldung</groupId >
6+ <artifactId >MyFirstSpringBoot</artifactId >
7+ <version >0.0.1-SNAPSHOT</version >
8+ <packaging >jar</packaging >
9+
10+ <parent >
11+ <groupId >org.springframework.boot</groupId >
12+ <artifactId >spring-boot-starter-parent</artifactId >
13+ <version >1.4.3.RELEASE</version >
14+ </parent >
15+
16+ <name >MyFirstSpringBoot</name >
17+ <url >http://maven.apache.org</url >
18+
19+ <properties >
20+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
21+ </properties >
22+
23+ <dependencies >
24+ <dependency >
25+ <groupId >org.springframework.boot</groupId >
26+ <artifactId >spring-boot-starter-web</artifactId >
27+ </dependency >
28+ <dependency >
29+ <groupId >org.springframework.boot</groupId >
30+ <artifactId >spring-boot-starter-test</artifactId >
31+ <scope >test</scope >
32+ </dependency >
33+ <dependency >
34+ <groupId >junit</groupId >
35+ <artifactId >junit</artifactId >
36+ <scope >test</scope >
37+ </dependency >
38+ </dependencies >
39+ </project >
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+
6+ @ SpringBootApplication
7+ public class App
8+ {
9+ public static void main ( String [] args )
10+ {
11+ SpringApplication .run (App .class , args );
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .controller ;
2+
3+ import org .springframework .web .bind .annotation .RequestMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
5+
6+ @ RestController
7+ public class HomeController {
8+
9+ @ RequestMapping ("/" )
10+ public String root (){
11+ return "Index Page" ;
12+ }
13+
14+ @ RequestMapping ("/local" )
15+ public String local (){
16+ return "/local" ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < title > RESOURCE NOT FOUND</ title >
4+ </ head >
5+ < body >
6+ < h1 > 404 RESOURCE NOT FOUND</ h1 >
7+ </ body >
8+ </ html >
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import static org .hamcrest .Matchers .equalTo ;
4+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .content ;
5+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
6+
7+ import org .junit .Test ;
8+ import org .junit .runner .RunWith ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
11+ import org .springframework .boot .test .context .SpringBootTest ;
12+ import org .springframework .http .MediaType ;
13+ import org .springframework .test .context .junit4 .SpringRunner ;
14+ import org .springframework .test .web .servlet .MockMvc ;
15+ import org .springframework .test .web .servlet .request .MockMvcRequestBuilders ;
16+
17+ @ RunWith (SpringRunner .class )
18+ @ SpringBootTest
19+ @ AutoConfigureMockMvc
20+ public class AppTest {
21+
22+ @ Autowired
23+ private MockMvc mvc ;
24+
25+ @ Test
26+ public void getIndex () throws Exception {
27+ mvc .perform (MockMvcRequestBuilders .get ("/" ).accept (MediaType .APPLICATION_JSON ))
28+ .andExpect (status ().isOk ())
29+ .andExpect (content ().string (equalTo ("Index Page" )));
30+ }
31+
32+ @ Test
33+ public void getLocal () throws Exception {
34+ mvc .perform (MockMvcRequestBuilders .get ("/local" ).accept (MediaType .APPLICATION_JSON ))
35+ .andExpect (status ().isOk ())
36+ .andExpect (content ().string (equalTo ("/local" )));
37+ }
38+
39+ }
You can’t perform that action at this time.
0 commit comments