diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c588e92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target +.classpath +.project +.settings +.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..280b82a --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Welcome to SI-SE Zurich 2018 demo repo +## This repo contains basic Maven project with Hello-World WAR file +
Ready for Tomcat deployment +
now also support jetty + diff --git a/build-war/pom.xml b/build-war/pom.xml new file mode 100644 index 0000000..0e5d61a --- /dev/null +++ b/build-war/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + + helloworld-build + BUILD hello world WAR + war + + + org.nirkoren.maven.demo + helloworld-reactor + 1.0.0-SNAPSHOT + + + + helloworld + 1.8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${javaVersion} + ${javaVersion} + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.0 + + ${finalWarName} + + + + + + + junit + junit + + + diff --git a/build-war/src/main/java/org/nirkoren/maven/demo/HelloHandler.java b/build-war/src/main/java/org/nirkoren/maven/demo/HelloHandler.java new file mode 100644 index 0000000..eab76f9 --- /dev/null +++ b/build-war/src/main/java/org/nirkoren/maven/demo/HelloHandler.java @@ -0,0 +1,10 @@ +package org.nirkoren.maven.demo; + +public class HelloHandler { + + public String sayHello() { + String hello = "Hello SI-SE members, What do you think about this conference?"; + return hello; + } + +} diff --git a/build-war/src/main/webapp/WEB-INF/web.xml b/build-war/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/build-war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/build-war/src/main/webapp/index.jsp b/build-war/src/main/webapp/index.jsp new file mode 100644 index 0000000..5a3cca5 --- /dev/null +++ b/build-war/src/main/webapp/index.jsp @@ -0,0 +1,12 @@ +<%@page import="org.nirkoren.maven.demo.HelloHandler"%> + + +

Welcome to SI-SE Zurich Demo project

+ SI-SE Zurich Demo, Maven WAR example

+ <% + String prefix = "Read info from Java class: "; + HelloHandler handler = new HelloHandler(); + out.print(prefix + handler.sayHello()); + %> + + diff --git a/build-war/src/test/java/org/nirkoren/maven/demo/HelloHandlerTest.java b/build-war/src/test/java/org/nirkoren/maven/demo/HelloHandlerTest.java new file mode 100644 index 0000000..a24285b --- /dev/null +++ b/build-war/src/test/java/org/nirkoren/maven/demo/HelloHandlerTest.java @@ -0,0 +1,17 @@ +package org.nirkoren.maven.demo; + +import org.junit.Assert; +import org.junit.Test; +import org.nirkoren.maven.demo.HelloHandler; + +public class HelloHandlerTest { + + @Test + public void validateNameNotNull() { + HelloHandler handler = new HelloHandler(); + String response = handler.sayHello(); + // Due to the code: This test will never fail :) + Assert.assertNotNull("String got null value",response); + } + +} diff --git a/deploy-war/pom.xml b/deploy-war/pom.xml new file mode 100644 index 0000000..ea5319b --- /dev/null +++ b/deploy-war/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + helloworld-deploy + DEPLOY hello world WAR + pom + + org.nirkoren.maven.demo + helloworld-reactor + 1.0.0-SNAPSHOT + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..dca0f01 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + org.nirkoren.maven.demo + helloworld-reactor + 1.0.0-SNAPSHOT + pom + + UTF-8 + + + build-war + deploy-war + tests-war + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.21.0 + + + + + + + + junit + junit + 4.12 + test + + + + \ No newline at end of file diff --git a/tests-war/pom.xml b/tests-war/pom.xml new file mode 100644 index 0000000..8e4cca4 --- /dev/null +++ b/tests-war/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + helloworld-tests + TESTS hello world WAR + jar + + org.nirkoren.maven.demo + helloworld-reactor + 1.0.0-SNAPSHOT + + + http://localhost:8080/helloworld + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + + + ci_profile + + + + org.apache.maven.plugins + maven-surefire-plugin + + + runTest + validate + + + + false + + ${appurl} + + + + + + + + + + junit + junit + + + \ No newline at end of file diff --git a/tests-war/src/main/java/org/nirkoren/maven/demo/TomcatPropsHandler.java b/tests-war/src/main/java/org/nirkoren/maven/demo/TomcatPropsHandler.java new file mode 100644 index 0000000..fb8b288 --- /dev/null +++ b/tests-war/src/main/java/org/nirkoren/maven/demo/TomcatPropsHandler.java @@ -0,0 +1,11 @@ +package org.nirkoren.maven.demo; + +public class TomcatPropsHandler { + + private static String appurl = System.getProperty("appurl"); + + public static String getAppurl() { + return appurl; + } + +} \ No newline at end of file diff --git a/tests-war/src/test/java/org/nirkoren/maven/demo/HealthTest.java b/tests-war/src/test/java/org/nirkoren/maven/demo/HealthTest.java new file mode 100644 index 0000000..1817d95 --- /dev/null +++ b/tests-war/src/test/java/org/nirkoren/maven/demo/HealthTest.java @@ -0,0 +1,40 @@ +package org.nirkoren.maven.demo; + +import static org.junit.Assert.fail; + +import java.net.HttpURLConnection; +import java.net.URL; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nirkoren.maven.demo.TomcatPropsHandler; + +public class HealthTest { + + private static String appurl; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + appurl = TomcatPropsHandler.getAppurl(); + } + + + @Test + public void testResponseCode() { + URL url; + try { + System.out.println("Pinging: " + appurl); + url = new URL(appurl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + int code = connection.getResponseCode(); + Assert.assertEquals(200, code); + } catch (Exception e) { + fail(); + } + + } + +}