From 5bef1690b9befe7dbe57b318b3c9e99b55988485 Mon Sep 17 00:00:00 2001
From: Martin Staehr <martin@mstaehr.net>
Date: Mon, 28 May 2018 16:44:26 +0200
Subject: [PATCH] adding example back to project

---
 gemeinsamforschen/pom.xml                     | 25 ++++++++++++++---
 .../gf/communication/model/SampleAnswer.java  | 25 +++++++++++++++++
 .../communication/service/SampleService.java  | 12 ++++++++
 .../gf/communication/view/SampleView.java     | 28 +++++++++++++++++++
 .../src/main/resources/log4j2.xml             | 13 +++++++++
 .../service/SampleServiceTest.java            | 19 +++++++++++++
 6 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java
 create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java
 create mode 100644 gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java
 create mode 100644 gemeinsamforschen/src/main/resources/log4j2.xml
 create mode 100644 gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java

diff --git a/gemeinsamforschen/pom.xml b/gemeinsamforschen/pom.xml
index 1fa9a005..118c0104 100644
--- a/gemeinsamforschen/pom.xml
+++ b/gemeinsamforschen/pom.xml
@@ -34,6 +34,17 @@
             <artifactId>log4j</artifactId>
             <version>1.2.16</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>2.11.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-all</artifactId>
+            <version>1.3</version>
+            <scope>test</scope>
+        </dependency>
 
         <dependency>
             <groupId>mysql</groupId>
@@ -113,10 +124,16 @@
             <version>3.0.1</version>
             <scope>provided</scope>
         </dependency>
-
-
-
-
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-grizzly2-servlet</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-json-provider</artifactId>
+            <version>2.9.5</version>
+        </dependency>
     </dependencies>
 
 </project>
\ No newline at end of file
diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java
new file mode 100644
index 00000000..06243fbd
--- /dev/null
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java
@@ -0,0 +1,25 @@
+package unipotsdam.gf.communication.model;
+
+
+public class SampleAnswer {
+
+    private String answer;
+
+    public SampleAnswer() {
+    }
+
+    public String getAnswer() {
+        return answer;
+    }
+
+    public void setAnswer(String answer) {
+        this.answer = answer;
+    }
+
+    @Override
+    public String toString() {
+        return "SampleAnswer{" +
+                "answer='" + answer + '\'' +
+                '}';
+    }
+}
diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java
new file mode 100644
index 00000000..ee150d86
--- /dev/null
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java
@@ -0,0 +1,12 @@
+package unipotsdam.gf.communication.service;
+
+import unipotsdam.gf.communication.model.SampleAnswer;
+
+public class SampleService {
+
+    public SampleAnswer provideSampleAnswer(String name) {
+        SampleAnswer sampleAnswer = new SampleAnswer();
+        sampleAnswer.setAnswer("Hello " + name);
+        return sampleAnswer;
+    }
+}
diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java
new file mode 100644
index 00000000..6c894443
--- /dev/null
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java
@@ -0,0 +1,28 @@
+package unipotsdam.gf.communication.view;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import unipotsdam.gf.communication.model.SampleAnswer;
+import unipotsdam.gf.communication.service.SampleService;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/example")
+public class SampleView {
+
+    Logger log = LoggerFactory.getLogger(SampleView.class);
+
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("{name}")
+    public SampleAnswer helloWorld(@PathParam("name") String name) {
+        SampleService sampleService = new SampleService();
+        SampleAnswer sampleAnswer = sampleService.provideSampleAnswer(name);
+        log.info("HelloWorldview helloWorld Method answered: {}",sampleAnswer);
+        return sampleAnswer;
+    }
+}
diff --git a/gemeinsamforschen/src/main/resources/log4j2.xml b/gemeinsamforschen/src/main/resources/log4j2.xml
new file mode 100644
index 00000000..fccc9f40
--- /dev/null
+++ b/gemeinsamforschen/src/main/resources/log4j2.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="WARN">
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT">
+            <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%level] %logger{35} - %msg%n"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Root level="info">
+            <AppenderRef ref="Console"/>
+        </Root>
+    </Loggers>
+</Configuration>
\ No newline at end of file
diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java
new file mode 100644
index 00000000..d19745c8
--- /dev/null
+++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java
@@ -0,0 +1,19 @@
+package unipotsdam.gf.communication.service;
+
+
+import org.junit.Test;
+import unipotsdam.gf.communication.model.SampleAnswer;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class SampleServiceTest {
+
+    @Test
+    public void returnCorrectMessage() {
+        SampleService sampleService = new SampleService();
+        SampleAnswer sampleAnswer = sampleService.provideSampleAnswer("test");
+
+        assertEquals(sampleAnswer.getAnswer(), "Hello test");
+    }
+}
-- 
GitLab