File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ buildscript {
2+ repositories {
3+ jcenter()
4+ }
5+ dependencies {
6+ classpath " io.ratpack:ratpack-gradle:1.4.5"
7+ }
8+ }
9+
10+ if (! JavaVersion . current(). java8Compatible) {
11+ throw new IllegalStateException (" Must be built with Java 8 or higher" )
12+ }
13+
14+ apply plugin : " io.ratpack.ratpack-java"
15+ apply plugin : ' java'
16+
17+ repositories {
18+ jcenter()
19+ }
20+
21+ dependencies {
22+ testCompile ' junit:junit:4.11'
23+ runtime " org.slf4j:slf4j-simple:1.7.21"
24+ }
25+
26+ test {
27+ testLogging {
28+ events ' started' , ' passed'
29+ }
30+ }
31+
32+ mainClassName = " com.baeldung.Application"
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <groupId >com.baeldung</groupId >
5+ <artifactId >ratpack</artifactId >
6+ <packaging >jar</packaging >
7+ <version >1.0-SNAPSHOT</version >
8+ <name >ratpack</name >
9+ <url >http://maven.apache.org</url >
10+
11+ <properties >
12+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
13+ <maven .compiler.source>1.8</maven .compiler.source>
14+ <maven .compiler.target>1.8</maven .compiler.target>
15+ </properties >
16+
17+ <dependencies >
18+ <dependency >
19+ <groupId >io.ratpack</groupId >
20+ <artifactId >ratpack-core</artifactId >
21+ <version >1.4.5</version >
22+ </dependency >
23+ <dependency >
24+ <groupId >io.ratpack</groupId >
25+ <artifactId >ratpack-test</artifactId >
26+ <version >1.4.5</version >
27+ </dependency >
28+ <dependency >
29+ <groupId >junit</groupId >
30+ <artifactId >junit</artifactId >
31+ <version >4.12</version >
32+ <scope >test</scope >
33+ </dependency >
34+ </dependencies >
35+
36+ </project >
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import ratpack .http .MutableHeaders ;
4+ import ratpack .server .RatpackServer ;
5+
6+ public class Application {
7+
8+ public static void main (String ... args ) throws Exception {
9+ RatpackServer .start (server -> server .handlers (chain -> chain .all (ctx -> {
10+ MutableHeaders headers = ctx .getResponse ().getHeaders ();
11+ headers .set ("Access-Control-Allow-Origin" , "*" );
12+ headers .set ("Accept-Language" , "en-us" );
13+ headers .set ("Accept-Charset" , "UTF-8" );
14+ ctx .next ();
15+ })
16+ .get (ctx -> ctx .render ("Welcome to baeldung ratpack!!!" ))
17+ .get (":name" , ctx -> ctx .render ("Hello " + ctx .getPathTokens ().get ("name" ) + "!!!" ))
18+ .post (":amount" , ctx -> ctx .render (" Amount $" + ctx .getPathTokens ().get ("amount" ) + " added successfully !!!" ))
19+ ));
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .junit .After ;
4+ import org .junit .Test ;
5+ import org .junit .runner .RunWith ;
6+ import org .junit .runners .JUnit4 ;
7+ import ratpack .test .MainClassApplicationUnderTest ;
8+
9+ import static org .junit .Assert .assertEquals ;
10+
11+ @ RunWith (JUnit4 .class )
12+ public class ApplicationTest {
13+
14+ MainClassApplicationUnderTest appUnderTest = new MainClassApplicationUnderTest (Application .class );
15+
16+ @ Test
17+ public void givenDefaultUrl_getStaticText () {
18+ assertEquals ("Welcome to baeldung ratpack!!!" , appUnderTest .getHttpClient ().getText ("/" ));
19+ }
20+
21+ @ Test
22+ public void givenDynamicUrl_getDynamicText () {
23+ assertEquals ("Hello dummybot!!!" , appUnderTest .getHttpClient ().getText ("/dummybot" ));
24+ }
25+
26+ @ After
27+ public void shutdown () {
28+ appUnderTest .close ();
29+ }
30+
31+ }
You can’t perform that action at this time.
0 commit comments