Skip to content
Snippets Groups Projects
Commit 5bef1690 authored by Martin Staehr's avatar Martin Staehr
Browse files

adding example back to project

parent 0be97dbc
No related branches found
No related tags found
No related merge requests found
......@@ -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
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 + '\'' +
'}';
}
}
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;
}
}
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;
}
}
<?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
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");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment