use of io.helidon.webserver.RoutingTest.RoutingChecker in project helidon by oracle.
the class RequestPredicateTest method containsExactCookie.
@Test
public void containsExactCookie() {
final RoutingChecker checker = new RoutingChecker();
Routing routing = Routing.builder().get("/equals", RequestPredicate.create().containsCookie("my-cookie", "abc").thenApply((req, resp) -> {
checker.handlerInvoked("cookieIsEqual");
}).otherwise((req, res) -> {
checker.handlerInvoked("cookieIsNotEqual");
})).build();
assertThrows(NullPointerException.class, () -> {
RequestPredicate.create().containsCookie("my-cookie", (String) null);
});
assertThrows(NullPointerException.class, () -> {
RequestPredicate.create().containsCookie(null, "abc");
});
routing.route(mockRequest("/equals", Map.of("cookie", List.of("my-cookie=abc"))), mockResponse());
assertThat(checker.handlersInvoked(), is("cookieIsEqual"));
checker.reset();
routing.route(mockRequest("/equals", Map.of("cookie", List.of("my-cookie=def"))), mockResponse());
assertThat(checker.handlersInvoked(), is("cookieIsNotEqual"));
}
use of io.helidon.webserver.RoutingTest.RoutingChecker in project helidon by oracle.
the class RequestPredicateTest method multipleConditions.
@Test
public void multipleConditions() {
final RoutingChecker checker = new RoutingChecker();
Routing routing = Routing.builder().any("/multiple", RequestPredicate.create().accepts(MediaType.TEXT_PLAIN).hasContentType(MediaType.TEXT_PLAIN).containsQueryParameter("my-param").containsCookie("my-cookie").isOfMethod(Http.Method.GET).thenApply((req, resp) -> {
checker.handlerInvoked("hasAllConditions");
}).otherwise((req, res) -> {
checker.handlerInvoked("doesNotHaveAllConditions");
})).build();
routing.route(mockRequest("/multiple?my-param=abc", Map.of("Content-Type", List.of("text/plain"), "Accept", List.of("text/plain"), "Cookie", List.of("my-cookie=abc"))), mockResponse());
assertThat(checker.handlersInvoked(), is("hasAllConditions"));
checker.reset();
routing.route(mockRequest("/multiple?my-param=abc", Map.of("Accept", List.of("text/plain"), "Cookie", List.of("my-cookie=abc"))), mockResponse());
assertThat(checker.handlersInvoked(), is("doesNotHaveAllConditions"));
}
use of io.helidon.webserver.RoutingTest.RoutingChecker in project helidon by oracle.
the class RequestPredicateTest method accepts1.
@Test
public void accepts1() {
final RoutingChecker checker = new RoutingChecker();
Routing routing = Routing.builder().get("/accepts1", RequestPredicate.create().accepts("text/plain", "application/json").thenApply((req, resp) -> {
checker.handlerInvoked("acceptsMediaType");
}).otherwise((req, res) -> {
checker.handlerInvoked("doesNotAcceptMediaType");
})).build();
assertThrows(NullPointerException.class, () -> {
RequestPredicate.create().accepts((String[]) null);
});
routing.route(mockRequest("/accepts1", Map.of("Accept", List.of("application/json"))), mockResponse());
assertThat(checker.handlersInvoked(), is("acceptsMediaType"));
checker.reset();
routing.route(mockRequest("/accepts1", Map.of("Accept", List.of("text/plain"))), mockResponse());
assertThat(checker.handlersInvoked(), is("acceptsMediaType"));
checker.reset();
routing.route(mockRequest("/accepts1", Map.of("Accept", List.of("text/plain", "application/xml"))), mockResponse());
assertThat(checker.handlersInvoked(), is("acceptsMediaType"));
checker.reset();
routing.route(mockRequest("/accepts1", Map.of("Accept", List.of())), mockResponse());
assertThat(checker.handlersInvoked(), is("acceptsMediaType"));
checker.reset();
routing.route(mockRequest("/accepts1", Map.of()), mockResponse());
assertThat(checker.handlersInvoked(), is("acceptsMediaType"));
checker.reset();
routing.route(mockRequest("/accepts1", Map.of("Accept", List.of("application/xml"))), mockResponse());
assertThat(checker.handlersInvoked(), is("doesNotAcceptMediaType"));
}
use of io.helidon.webserver.RoutingTest.RoutingChecker in project helidon by oracle.
the class RequestPredicateTest method containsExactHeader.
@Test
public void containsExactHeader() {
final RoutingChecker checker = new RoutingChecker();
Routing routing = Routing.builder().get("/equals", RequestPredicate.create().containsHeader("my-header", "abc").thenApply((req, resp) -> {
checker.handlerInvoked("headerIsEqual");
}).otherwise((req, res) -> {
checker.handlerInvoked("headerIsNotEqual");
})).build();
assertThrows(NullPointerException.class, () -> {
RequestPredicate.create().containsHeader("my-header", (String) null);
});
assertThrows(NullPointerException.class, () -> {
RequestPredicate.create().containsHeader(null, "abc");
});
routing.route(mockRequest("/equals", Map.of("my-header", List.of("abc"))), mockResponse());
assertThat(checker.handlersInvoked(), is("headerIsEqual"));
checker.reset();
routing.route(mockRequest("/equals", Map.of("my-header", List.of("def"))), mockResponse());
assertThat(checker.handlersInvoked(), is("headerIsNotEqual"));
}
use of io.helidon.webserver.RoutingTest.RoutingChecker in project helidon by oracle.
the class RequestPredicateTest method isOfMethod1.
@Test
public void isOfMethod1() {
final RoutingChecker checker = new RoutingChecker();
Routing routing = Routing.builder().any("/getOrPost", RequestPredicate.create().isOfMethod("GET", "POST").thenApply((req, resp) -> {
checker.handlerInvoked("methodFound");
}).otherwise((req, res) -> {
checker.handlerInvoked("methodNotFound");
})).build();
assertThrows(NullPointerException.class, () -> {
RequestPredicate.create().isOfMethod((String[]) null);
});
routing.route(mockRequest("/getOrPost"), mockResponse());
assertThat(checker.handlersInvoked(), is("methodFound"));
checker.reset();
routing.route(mockRequest("/getOrPost", Http.Method.PUT), mockResponse());
assertThat(checker.handlersInvoked(), is("methodNotFound"));
}
Aggregations