Search in sources :

Example 1 with ValidationImpl

use of org.webpieces.router.impl.ctx.ValidationImpl in project webpieces by deanhiller.

the class TestSimpleRoutes method testOneParamRoute.

@Test
public void testOneParamRoute() {
    RouterRequest req = createHttpRequest(HttpMethod.POST, "/meeting");
    MockResponseStream mockResponseStream = new MockResponseStream();
    Current.setContext(new RequestContext(new ValidationImpl(null), new FlashImpl(null), new SessionImpl(null), req));
    server.incomingCompleteRequest(req, mockResponseStream);
    List<RedirectResponse> responses = mockResponseStream.getSendRedirectCalledList();
    Assert.assertEquals(1, responses.size());
    RedirectResponse response = responses.get(0);
    Assert.assertEquals(req.domain, response.domain);
    Assert.assertFalse(response.isHttps);
    Assert.assertEquals("/meeting/888", response.redirectToPath);
}
Also used : RedirectResponse(org.webpieces.router.api.dto.RedirectResponse) 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 2 with ValidationImpl

use of org.webpieces.router.impl.ctx.ValidationImpl in project webpieces by deanhiller.

the class TestSimpleRoutes method testBasicRoute.

@Test
public void testBasicRoute() {
    RouterRequest req = 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);
    List<RedirectResponse> responses = mockResponseStream.getSendRedirectCalledList();
    Assert.assertEquals(1, responses.size());
    RedirectResponse response = responses.get(0);
    Assert.assertEquals(req.domain, response.domain);
    Assert.assertFalse(response.isHttps);
    Assert.assertEquals("/something", response.redirectToPath);
}
Also used : RedirectResponse(org.webpieces.router.api.dto.RedirectResponse) 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 3 with ValidationImpl

use of org.webpieces.router.impl.ctx.ValidationImpl 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 4 with ValidationImpl

use of org.webpieces.router.impl.ctx.ValidationImpl 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 5 with ValidationImpl

use of org.webpieces.router.impl.ctx.ValidationImpl 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)

Aggregations

RequestContext (org.webpieces.ctx.api.RequestContext)6 FlashImpl (org.webpieces.router.impl.ctx.FlashImpl)6 SessionImpl (org.webpieces.router.impl.ctx.SessionImpl)6 ValidationImpl (org.webpieces.router.impl.ctx.ValidationImpl)6 Test (org.junit.Test)5 RouterRequest (org.webpieces.ctx.api.RouterRequest)5 MockResponseStream (org.webpieces.router.api.mocks.MockResponseStream)5 RouterService (org.webpieces.router.api.RouterService)3 RedirectResponse (org.webpieces.router.api.dto.RedirectResponse)2 FlashSub (org.webpieces.ctx.api.FlashSub)1 Session (org.webpieces.ctx.api.Session)1 Validation (org.webpieces.ctx.api.Validation)1 BadCookieException (org.webpieces.router.api.exceptions.BadCookieException)1