From c456f18b6eeef3cbfcd08f9b1a980cc5b6f10502 Mon Sep 17 00:00:00 2001 From: "bhavesh.shah" Date: Thu, 4 Feb 2016 06:58:30 +0530 Subject: [PATCH] web application in less than 140 characters --- .gitignore | 3 ++ README.md | 10 +++- pom.xml | 49 +++++++++++++++++++ src/main/java/com/meetup/App.java | 14 ++++++ .../java/com/meetup/web/RootController.java | 12 +++++ src/main/resources/application.yml | 4 ++ src/main/resources/banner.txt | 8 +++ .../java/com/meetup/ApplicationTests.java | 37 ++++++++++++++ 8 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/com/meetup/App.java create mode 100644 src/main/java/com/meetup/web/RootController.java create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/banner.txt create mode 100644 src/test/java/com/meetup/ApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b178533 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/spring-boot-workshop.iml +/target +/.idea \ No newline at end of file diff --git a/README.md b/README.md index b97af89..6c1551f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -# spring-boot-workshop -Spring Boot Workshop - Java Meetup - Ahmedabad +# Spring Boot Workshop - Java Meetup - Ahmedabad + +# Getting Started - Prerequisites + +1. JDK 8 latest stable version installed +2. Latest maven plugin installed + +Generate spring project through spring hosted web based quick starter service: [Spring Initializr] (http://start.spring.io/) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5aa5c80 --- /dev/null +++ b/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + com.meetup + spring-boot-workshop + 0.0.1-SNAPSHOT + jar + + spring-boot-workshop + Spring Boot Workshop + + + org.springframework.boot + spring-boot-starter-parent + 1.3.2.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/src/main/java/com/meetup/App.java b/src/main/java/com/meetup/App.java new file mode 100644 index 0000000..f112707 --- /dev/null +++ b/src/main/java/com/meetup/App.java @@ -0,0 +1,14 @@ +package com.meetup; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * The Application + */ +@SpringBootApplication +public class App { + public static void main(String[] args) { + SpringApplication.run(App.class, args); + } +} diff --git a/src/main/java/com/meetup/web/RootController.java b/src/main/java/com/meetup/web/RootController.java new file mode 100644 index 0000000..c4fa77a --- /dev/null +++ b/src/main/java/com/meetup/web/RootController.java @@ -0,0 +1,12 @@ +package com.meetup.web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class RootController { + @RequestMapping("/") + public String home(){ + return "Hello, World"; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..c37bf54 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,4 @@ +server: + address: localhost + port: 8585 + context-path: diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000..4eecb6e --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,8 @@ + ___ ___ ___ _ _____ _ ______ _ + |_ | | \/ | | | / ___| (_) | ___ \ | | + | | __ ___ ____ _ | . . | ___ ___| |_ _ _ _ __ ______ \ `--. _ __ _ __ _ _ __ __ _ ______ | |_/ / ___ ___ | |_ + | |/ _` \ \ / / _` | | |\/| |/ _ \/ _ \ __| | | | '_ \ |______| `--. \ '_ \| '__| | '_ \ / _` | |______| | ___ \/ _ \ / _ \| __| +/\__/ / (_| |\ V / (_| | | | | | __/ __/ |_| |_| | |_) | /\__/ / |_) | | | | | | | (_| | | |_/ / (_) | (_) | |_ +\____/ \__,_| \_/ \__,_| \_| |_/\___|\___|\__|\__,_| .__/ \____/| .__/|_| |_|_| |_|\__, | \____/ \___/ \___/ \__| + | | | | __/ | + |_| |_| |___/ \ No newline at end of file diff --git a/src/test/java/com/meetup/ApplicationTests.java b/src/test/java/com/meetup/ApplicationTests.java new file mode 100644 index 0000000..a7b7c71 --- /dev/null +++ b/src/test/java/com/meetup/ApplicationTests.java @@ -0,0 +1,37 @@ +package com.meetup; + +import com.meetup.web.RootController; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.http.MediaType; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +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; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = App.class) +@WebAppConfiguration +public class ApplicationTests { + + private MockMvc mockRootController; + + @Before + public void setUp(){ + mockRootController = MockMvcBuilders.standaloneSetup(new RootController()).build(); + } + + @Test + public void testHome() throws Exception{ + mockRootController.perform(MockMvcRequestBuilders.get("/"). + accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("Hello, World"))); + } + +}