Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test for NormaliseUri/BasePathHandler conflict #1

Merged
merged 2 commits into from
Dec 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/com/googlecode/utterlyidle/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,14 @@ public String call(final Request request) throws Exception {
}
};
}

public static Function1<Request, Uri> uri() {
return new Function1<Request, Uri>() {
@Override
public Uri call(final Request request) throws Exception {
return request.uri();
}
};
}
}
}
23 changes: 23 additions & 0 deletions test/com/googlecode/utterlyidle/RestApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.googlecode.totallylazy.Callables;
import com.googlecode.utterlyidle.annotations.GET;
import com.googlecode.utterlyidle.annotations.Path;
import com.googlecode.utterlyidle.modules.ResourcesModule;
import com.googlecode.utterlyidle.services.Service;
import com.googlecode.utterlyidle.services.Services;
import org.junit.Before;
Expand All @@ -14,7 +15,9 @@

import static com.googlecode.totallylazy.Sequences.sequence;
import static com.googlecode.utterlyidle.ApplicationBuilder.application;
import static com.googlecode.utterlyidle.BasePath.basePath;
import static com.googlecode.utterlyidle.RequestBuilder.get;
import static com.googlecode.utterlyidle.annotations.AnnotatedBindings.annotatedClass;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -91,6 +94,26 @@ public void startingApplicationStartsAndStopsServices() throws Exception {
assertThat(service.stops.get(), is(1));
}

@Test
public void basePathIsStrippedFromRequests() throws Exception {
final Response response = new RestApplication(basePath("foo")).add(new ResourcesModule() {
@Override
public Resources addResources(final Resources resources) throws Exception {
return resources.add(annotatedClass(Foo.class));
}
}).handle(get("/foo/").build());

assertThat(response.status(), is(Status.OK));
}

public static class Foo {
@GET
@Path("")
public String respond() {
return "foo";
}
}

private int runningInstances() {
return started[0] - stopped[0];
}
Expand Down