use of org.webpieces.router.api.mocks.MockResponseStream 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.mocks.MockResponseStream 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);
}
use of org.webpieces.router.api.mocks.MockResponseStream 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);
}
use of org.webpieces.router.api.mocks.MockResponseStream 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.mocks.MockResponseStream in project webpieces by deanhiller.
the class TestProdRouter method testAsyncRouteAndMocking.
/**
* This test won't work in DevRoute right now as we need to do the following
* 1. create CompileOnDemand very early on
* 2. do a Thread.current().setContextClassLoader(compileOnDemand.getLatestClassloader())
*
* and this all needs to be done BEFORE TestModule is created and more importantly before
* the bind(SomeService.class) as SomeService will be loaded from one classloader and then
* when DEVrouter creates the controller, the compileOnDemand classloader is used resulting
* in a mismatch.
*/
@Test
public void testAsyncRouteAndMocking() {
RouterRequest req = createHttpRequest(HttpMethod.GET, "/async");
//setup returning a response
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
overrides.mockService.addToReturn(future);
MockResponseStream mockResponseStream = new MockResponseStream();
server.incomingCompleteRequest(req, mockResponseStream);
//no response yet...
List<RedirectResponse> responses = mockResponseStream.getSendRedirectCalledList();
Assert.assertEquals(0, responses.size());
int id = 78888;
future.complete(id);
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/" + id, response.redirectToPath);
}
Aggregations