Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import ninja.siden.App;
public class Application {
public static void main(String[] args) {
App app = new App();
new HelloResource(app).defineRoute();
app.listen();
}
}
apply plugin: 'java'
apply plugin: 'groovy'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'ninja.siden:siden-core:0.2.0'
testCompile 'org.codehaus.groovy:groovy-all:2.3.8'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7+'
}
import ninja.siden.App;
public class HelloResource {
private App app;
public HelloResource(App app){
this.app = app;
}
public void defineRoute(){
app.get("/hello", (req,res)->"Hello World");
}
}
import groovyx.net.http.RESTClient
import ninja.siden.App
import ninja.siden.App.Stoppable
import spock.lang.Shared;
import spock.lang.Specification
class HelloResourceSpec extends Specification {
@Shared stop
def setupSpec(){
def app = new App()
new HelloResource(app).defineRoute()
stop = app.listen()
}
def "簡単な起動のテスト"(){
setup:
def endpoint = new RESTClient( 'http://localhost:8080/' )
when:
def resp = endpoint.get([ path: 'hello'])
then:
with(resp) {
status == 200
data.text == "Hello World"
}
}
def cleanupSpec(){
stop.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment