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"));
}
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);
}
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 } });
}
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);
}
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());
}
Aggregations