Skip to content

Instantly share code, notes, and snippets.

@deffence1776
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deffence1776/54ca2b245c9a474abc53 to your computer and use it in GitHub Desktop.
Save deffence1776/54ca2b245c9a474abc53 to your computer and use it in GitHub Desktop.
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