Adding ratpack module (#1374)

* adding ratpack module

* adding pom.xml
This commit is contained in:
Abhinab Kanrar 2017-03-12 15:19:13 +05:30 committed by maibin
parent dda35bc510
commit 2f3f490453
4 changed files with 121 additions and 0 deletions

32
ratpack/build.gradle Normal file
View File

@ -0,0 +1,32 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.ratpack:ratpack-gradle:1.4.5"
}
}
if (!JavaVersion.current().java8Compatible) {
throw new IllegalStateException("Must be built with Java 8 or higher")
}
apply plugin: "io.ratpack.ratpack-java"
apply plugin: 'java'
repositories {
jcenter()
}
dependencies {
testCompile 'junit:junit:4.11'
runtime "org.slf4j:slf4j-simple:1.7.21"
}
test {
testLogging {
events 'started', 'passed'
}
}
mainClassName = "com.baeldung.Application"

36
ratpack/pom.xml Normal file
View File

@ -0,0 +1,36 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>ratpack</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ratpack</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.ratpack</groupId>
<artifactId>ratpack-core</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>io.ratpack</groupId>
<artifactId>ratpack-test</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,22 @@
package com.baeldung;
import ratpack.http.MutableHeaders;
import ratpack.server.RatpackServer;
public class Application {
public static void main(String... args) throws Exception {
RatpackServer.start(server -> server.handlers(chain -> chain.all(ctx -> {
MutableHeaders headers = ctx.getResponse().getHeaders();
headers.set("Access-Control-Allow-Origin", "*");
headers.set("Accept-Language", "en-us");
headers.set("Accept-Charset", "UTF-8");
ctx.next();
})
.get(ctx -> ctx.render("Welcome to baeldung ratpack!!!"))
.get(":name", ctx -> ctx.render("Hello " + ctx.getPathTokens().get("name") + "!!!"))
.post(":amount", ctx -> ctx.render(" Amount $" + ctx.getPathTokens().get("amount") + " added successfully !!!"))
));
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import ratpack.test.MainClassApplicationUnderTest;
import static org.junit.Assert.assertEquals;
@RunWith(JUnit4.class)
public class ApplicationTest {
MainClassApplicationUnderTest appUnderTest = new MainClassApplicationUnderTest(Application.class);
@Test
public void givenDefaultUrl_getStaticText() {
assertEquals("Welcome to baeldung ratpack!!!", appUnderTest.getHttpClient().getText("/"));
}
@Test
public void givenDynamicUrl_getDynamicText() {
assertEquals("Hello dummybot!!!", appUnderTest.getHttpClient().getText("/dummybot"));
}
@After
public void shutdown() {
appUnderTest.close();
}
}