From e4bc0a44ce497d8a3c6450da601fdd493e67195a Mon Sep 17 00:00:00 2001 From: Jesus Boadas Date: Tue, 24 Jan 2017 04:42:09 -0400 Subject: [PATCH] Move intro inside main src (#1037) * Initial commit * Initial commit * deleted old files * classNotFoundException-contextLoaderListener * Spring Boot Application * delete ClassNotFoundException * Add intro package inside main source tree --- .../src/main/java/com/baeldung/intro/App.java | 13 +++++++ .../intro/controller/HomeController.java | 18 +++++++++ .../src/main/resources/public/error/404.html | 8 ++++ .../test/java/com/baeldung/intro/AppTest.java | 39 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/intro/App.java create mode 100644 spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java create mode 100644 spring-boot/src/main/resources/public/error/404.html create mode 100644 spring-boot/src/test/java/com/baeldung/intro/AppTest.java diff --git a/spring-boot/src/main/java/com/baeldung/intro/App.java b/spring-boot/src/main/java/com/baeldung/intro/App.java new file mode 100644 index 0000000000..30e1c2b5ba --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/intro/App.java @@ -0,0 +1,13 @@ +package com.baeldung.intro; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class App +{ + public static void main( String[] args ) + { + SpringApplication.run(App.class, args); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java b/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java new file mode 100644 index 0000000000..9109b0a292 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java @@ -0,0 +1,18 @@ +package com.baeldung.intro.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HomeController { + + @RequestMapping("/") + public String root(){ + return "Index Page"; + } + + @RequestMapping("/local") + public String local(){ + return "/local"; + } +} diff --git a/spring-boot/src/main/resources/public/error/404.html b/spring-boot/src/main/resources/public/error/404.html new file mode 100644 index 0000000000..02d6092bee --- /dev/null +++ b/spring-boot/src/main/resources/public/error/404.html @@ -0,0 +1,8 @@ + + + RESOURCE NOT FOUND + + +

404 RESOURCE NOT FOUND

+ + \ No newline at end of file diff --git a/spring-boot/src/test/java/com/baeldung/intro/AppTest.java b/spring-boot/src/test/java/com/baeldung/intro/AppTest.java new file mode 100644 index 0000000000..749fe68838 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/intro/AppTest.java @@ -0,0 +1,39 @@ +package com.baeldung.intro; + +import static org.hamcrest.Matchers.equalTo; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class AppTest { + + @Autowired + private MockMvc mvc; + + @Test + public void getIndex() throws Exception { + mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(equalTo("Index Page"))); + } + + @Test + public void getLocal() throws Exception { + mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(equalTo("/local"))); + } + +} \ No newline at end of file