Search in sources :

Example 1 with RouterService

use of org.webpieces.router.api.RouterService in project webpieces by deanhiller.

the class ErrorTest method testNoMethod.

@Test
public void testNoMethod() {
    log.info("starting");
    String moduleFileContents = NoMethodRouterModules.class.getName();
    RouterService server = ErrorCommonTest.createServer(true, moduleFileContents);
    try {
        server.start();
        Assert.fail("Should have thrown exception on start since this is prod");
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getMessage().contains("Cannot find 'public' method='thisMethodNotExist' on class="));
    }
    RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
    MockResponseStream mockResponseStream = new MockResponseStream();
    server.incomingCompleteRequest(req, mockResponseStream);
    Exception e = mockResponseStream.getOnlyException();
    Assert.assertEquals(IllegalStateException.class, e.getClass());
    Assert.assertTrue(e.getMessage().contains("start was not called by client or start threw"));
}
Also used : RouterService(org.webpieces.router.api.RouterService) RouterRequest(org.webpieces.ctx.api.RouterRequest) MockResponseStream(org.webpieces.router.api.mocks.MockResponseStream) ErrorCommonTest(org.webpieces.router.api.error.ErrorCommonTest) Test(org.junit.Test)

Example 2 with RouterService

use of org.webpieces.router.api.RouterService in project webpieces by deanhiller.

the class ErrorTest method testNoMethod.

@Test
public void testNoMethod() {
    log.info("starting");
    String moduleFileContents = NoMethodRouterModules.class.getName();
    RouterService server = ErrorCommonTest.createServer(false, moduleFileContents);
    //this should definitely not throw since we lazy load everything in dev...
    server.start();
    RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
    MockResponseStream mockResponseStream = new MockResponseStream();
    server.incomingCompleteRequest(req, mockResponseStream);
    List<RenderResponse> renders = mockResponseStream.getSendRenderHtmlList();
    Assert.assertEquals(1, renders.size());
    RenderResponse renderResponse = renders.get(0);
    Assert.assertEquals(RouteType.INTERNAL_SERVER_ERROR, renderResponse.routeType);
}
Also used : RouterService(org.webpieces.router.api.RouterService) RenderResponse(org.webpieces.router.api.dto.RenderResponse) RouterRequest(org.webpieces.ctx.api.RouterRequest) MockResponseStream(org.webpieces.router.api.mocks.MockResponseStream) Test(org.junit.Test) ErrorCommonTest(org.webpieces.router.api.error.ErrorCommonTest)

Example 3 with RouterService

use of org.webpieces.router.api.RouterService in project webpieces by deanhiller.

the class TestProdRouter method bothServers.

@SuppressWarnings("rawtypes")
@Parameterized.Parameters
public static Collection bothServers() {
    String moduleFileContents = AppModules.class.getName();
    VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
    TestModule module = new TestModule();
    RouterConfig config = new RouterConfig().setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
    RouterService prodSvc = RouterSvcFactory.create(config);
    return Arrays.asList(new Object[][] { { prodSvc, module } });
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) RouterConfig(org.webpieces.router.api.RouterConfig)

Example 4 with RouterService

use of org.webpieces.router.api.RouterService 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 5 with RouterService

use of org.webpieces.router.api.RouterService 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)

Aggregations

RouterService (org.webpieces.router.api.RouterService)9 Test (org.junit.Test)5 RouterRequest (org.webpieces.ctx.api.RouterRequest)5 MockResponseStream (org.webpieces.router.api.mocks.MockResponseStream)5 RequestContext (org.webpieces.ctx.api.RequestContext)3 VirtualFileInputStream (org.webpieces.router.api.mocks.VirtualFileInputStream)3 FlashImpl (org.webpieces.router.impl.ctx.FlashImpl)3 SessionImpl (org.webpieces.router.impl.ctx.SessionImpl)3 ValidationImpl (org.webpieces.router.impl.ctx.ValidationImpl)3 VirtualFile (org.webpieces.util.file.VirtualFile)3 File (java.io.File)2 CompileConfig (org.webpieces.compiler.api.CompileConfig)2 RouterConfig (org.webpieces.router.api.RouterConfig)2 ErrorCommonTest (org.webpieces.router.api.error.ErrorCommonTest)2 VirtualFileImpl (org.webpieces.util.file.VirtualFileImpl)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 RenderResponse (org.webpieces.router.api.dto.RenderResponse)1