Skip to content

Commit

Permalink
PathParam tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Feb 5, 2019
1 parent 582c9a7 commit f32a7aa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ If the response object's `contentType` is not explicitly set, the `@Produces` an
For methods that should return a `String` or `ByteBuffer` to the client users can create responses like this:
```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/hello-world")
Expand All @@ -173,7 +173,7 @@ By default, passing a `String` to the static `ServerResponse.response` helper fu
For other types of responses the following demonstrates the preferred style:
```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/world")
Expand All @@ -189,7 +189,7 @@ The entity can be set separately as well:
```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/world")
Expand All @@ -205,7 +205,7 @@ public ServerResponse getWorld(Integer id, Integer randomNumber )

```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/future/user")
Expand All @@ -220,7 +220,7 @@ In this case a handler will be generated with the following source code:

```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
import static io.sinistral.proteus.server.ServerResponse.response;
...
public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws java.lang.Exception {
CompletableFuture<ServerResponse<User>> response = examplesController.futureUser();
Expand All @@ -243,7 +243,7 @@ Multipart/Form file uploads can be passed to the endpoint methods as a ```java.i
Optional parameters are also supported, here is a more complex endpoint demonstrating several parameter types:
```java
...
import static io.sinistral.proteus.server.ServerResponse.response;
import static io.sinistral.proteus.server.ServerResponse.response;
...
@GET
@Path("/response/parameters/complex/{pathLong}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.inject.Singleton;

import io.sinistral.proteus.annotations.Blocking;
import io.sinistral.proteus.annotations.Debug;
import io.sinistral.proteus.server.ServerRequest;
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.swagger.test.models.User;
Expand Down Expand Up @@ -334,7 +335,21 @@ public ServerResponse<ByteBuffer> responseUploadFile(ServerRequest request, @For


}







@GET
@Path("response/params/path/{param}")
@Produces(MediaType.TEXT_PLAIN)
public ServerResponse<ByteBuffer> pathParamEndpoint(ServerRequest request, @PathParam("param") String param) {

return response(param).textPlain();
}


@GET
@Path("response/debug")
public ServerResponse<Map<String,String>> debugEndpoint(ServerRequest request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,27 @@ public void testRedirectMovedPermanentlyCode()
given().when().redirects().follow(false).get("tests/redirect/permanent").then().statusCode(301);
}

@Test
public void pathParam()
{
given().accept(ContentType.TEXT).when().get("tests/response/params/path/foobar").then().statusCode(200).and().body(containsString("foobar"));

}

// @Test
// public void regexPathParam()
// {
// given().accept(ContentType.TEXT).when().get("tests/response/params/regexpath/fooBar").then().statusCode(200).and().body(containsString("fooBar"));
//
// }
//
// @Test
// public void invalidRegexPathParam()
// {
// given().accept(ContentType.TEXT).when().get("tests/response/params/regexpath/fooBar101").then().statusCode(400);
//
// }

@Test
public void responseUploadFilePathParameter()
{
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<logger name="io.netty.handler" level="ERROR" />
<logger name="io.sinistral.proteus.server.tools.openapi" level="ERROR" />
<logger name="io.sinistral.proteus.server.tools.swagger" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="DEBUG" />
<logger name="io.sinistral.proteus.services" level="ERROR" />
<logger name="io.sinistral.proteus.openapi" level="ERROR" />
<logger name="io.sinistral.proteus.swagger" level="ERROR" />
Expand Down Expand Up @@ -49,7 +49,7 @@
<logger name="com.google.inject.internal" level="ERROR" />
<logger name="com.google.inject" level="ERROR" />

<root level="INFO">
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>

Expand Down

0 comments on commit f32a7aa

Please sign in to comment.