Search in sources :

Example 16 with RouterRequest

use of org.webpieces.ctx.api.RouterRequest in project webpieces by deanhiller.

the class ErrorCommonTest method testGetNotMatchPostRoute.

@Test
public void testGetNotMatchPostRoute() {
    log.info("starting");
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.GET, "/postroute");
    MockResponseStream mockResponseStream = new MockResponseStream();
    Current.setContext(new RequestContext(new ValidationImpl(null), new FlashImpl(null), new SessionImpl(null), req));
    server.incomingCompleteRequest(req, mockResponseStream);
    verifyNotFoundRendered(mockResponseStream);
}
Also used : RouterService(org.webpieces.router.api.RouterService) RequestContext(org.webpieces.ctx.api.RequestContext) FlashImpl(org.webpieces.router.impl.ctx.FlashImpl) SessionImpl(org.webpieces.router.impl.ctx.SessionImpl) RouterRequest(org.webpieces.ctx.api.RouterRequest) MockResponseStream(org.webpieces.router.api.mocks.MockResponseStream) ValidationImpl(org.webpieces.router.impl.ctx.ValidationImpl) Test(org.junit.Test)

Example 17 with RouterRequest

use of org.webpieces.ctx.api.RouterRequest in project webpieces by deanhiller.

the class ErrorCommonTest method testRedirectRouteNotEnoughArguments.

@Test
public void testRedirectRouteNotEnoughArguments() {
    //say method is something(int arg, String this)
    //we verify redirects MUST match type and number of method arguments every time
    //then when we form url, we put the stuff in the path OR put it as query params so it works on the way back in again too
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.GET, "/user/5553");
    MockResponseStream mockResponseStream = new MockResponseStream();
    Current.setContext(new RequestContext(new ValidationImpl(null), new FlashImpl(null), new SessionImpl(null), req));
    server.incomingCompleteRequest(req, mockResponseStream);
    Throwable e = mockResponseStream.getOnlyException();
    while (e.getCause() != null) {
        e = e.getCause();
    }
    Assert.assertEquals(IllegalStateException.class, e.getClass());
}
Also used : RouterService(org.webpieces.router.api.RouterService) RequestContext(org.webpieces.ctx.api.RequestContext) FlashImpl(org.webpieces.router.impl.ctx.FlashImpl) SessionImpl(org.webpieces.router.impl.ctx.SessionImpl) RouterRequest(org.webpieces.ctx.api.RouterRequest) MockResponseStream(org.webpieces.router.api.mocks.MockResponseStream) ValidationImpl(org.webpieces.router.impl.ctx.ValidationImpl) Test(org.junit.Test)

Example 18 with RouterRequest

use of org.webpieces.ctx.api.RouterRequest in project webpieces by deanhiller.

the class ErrorCommonTest method testArgsTypeMismatch.

@Test
public void testArgsTypeMismatch() {
    log.info("starting");
    String moduleFileContents = CommonRoutesModules.class.getName();
    RouterService server = createServer(isProdTest, moduleFileContents);
    server.start();
    RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
    MockResponseStream mockResponseStream = new MockResponseStream();
    Current.setContext(new RequestContext(new ValidationImpl(null), new FlashImpl(null), new SessionImpl(null), req));
    server.incomingCompleteRequest(req, mockResponseStream);
    verifyNotFoundRendered(mockResponseStream);
}
Also used : RouterService(org.webpieces.router.api.RouterService) RequestContext(org.webpieces.ctx.api.RequestContext) FlashImpl(org.webpieces.router.impl.ctx.FlashImpl) SessionImpl(org.webpieces.router.impl.ctx.SessionImpl) RouterRequest(org.webpieces.ctx.api.RouterRequest) MockResponseStream(org.webpieces.router.api.mocks.MockResponseStream) ValidationImpl(org.webpieces.router.impl.ctx.ValidationImpl) Test(org.junit.Test)

Example 19 with RouterRequest

use of org.webpieces.ctx.api.RouterRequest in project webpieces by deanhiller.

the class RequestCreation method createHttpRequest.

public static RouterRequest createHttpRequest(HttpMethod method, String path) {
    RouterRequest r = new RouterRequest();
    r.method = method;
    r.relativePath = path;
    return r;
}
Also used : RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 20 with RouterRequest

use of org.webpieces.ctx.api.RouterRequest in project webpieces by deanhiller.

the class RouteInvoker method processNotFound.

public CompletableFuture<Void> processNotFound(ResponseStreamer responseCb, RequestContext requestCtx, NotFoundException e, ErrorRoutes errorRoutes, Object meta) {
    NotFoundException exc = (NotFoundException) e;
    NotFoundInfo notFoundInfo = errorRoutes.fetchNotfoundRoute(exc);
    RouteMeta notFoundResult = notFoundInfo.getResult();
    RouterRequest overridenRequest = notFoundInfo.getReq();
    RequestContext overridenCtx = new RequestContext(requestCtx.getValidation(), (FlashSub) requestCtx.getFlash(), requestCtx.getSession(), overridenRequest);
    //http 404...(unless an exception happens in calling this code and that then goes to 500)
    return notFound(notFoundResult, notFoundInfo.getService(), exc, overridenCtx, responseCb);
}
Also used : NotFoundException(org.webpieces.router.api.exceptions.NotFoundException) RequestContext(org.webpieces.ctx.api.RequestContext) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Aggregations

RouterRequest (org.webpieces.ctx.api.RouterRequest)23 Test (org.junit.Test)8 RequestContext (org.webpieces.ctx.api.RequestContext)8 MockResponseStream (org.webpieces.router.api.mocks.MockResponseStream)8 RouterService (org.webpieces.router.api.RouterService)5 RedirectResponse (org.webpieces.router.api.dto.RedirectResponse)5 FlashImpl (org.webpieces.router.impl.ctx.FlashImpl)5 SessionImpl (org.webpieces.router.impl.ctx.SessionImpl)5 ValidationImpl (org.webpieces.router.impl.ctx.ValidationImpl)5 HttpMethod (org.webpieces.ctx.api.HttpMethod)4 Method (java.lang.reflect.Method)3 Annotation (java.lang.annotation.Annotation)2 Parameter (java.lang.reflect.Parameter)2 ArrayList (java.util.ArrayList)2 RenderResponse (org.webpieces.router.api.dto.RenderResponse)2 ErrorCommonTest (org.webpieces.router.api.error.ErrorCommonTest)2 IllegalReturnValueException (org.webpieces.router.api.exceptions.IllegalReturnValueException)2 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1