Search in sources :

Example 6 with RouterService

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

the class ErrorCommonTest method createServer.

/** 
	 * Need to live test with browser to see if PRG is better or just returning 404 is better!!!
	 * Current behavior is to return a 404
	 */
//TODO: Test this with browser and then fix for best user experience
//	@Test
//	public void testNotFoundPostRouteResultsInRedirectToNotFoundCatchAllController() {
//		log.info("starting");
//		String moduleFileContents = CommonRoutesModules.class.getName();
//		RoutingService server = createServer(isProdTest, moduleFileContents);
//		
//		server.start();
//		
//		RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.POST, "/notexistpostroute");
//		MockResponseStream mockResponseStream = new MockResponseStream();
//		
//		server.incomingCompleteRequest(req, mockResponseStream);
//
//		verifyNotFoundRendered(mockResponseStream);
//	}
public static RouterService createServer(boolean isProdTest, String moduleFileContents) {
    VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
    if (isProdTest)
        return RouterSvcFactory.create(f);
    //otherwise create the development server
    String filePath = System.getProperty("user.dir");
    File myCodePath = new File(filePath + "/src/test/java");
    CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath));
    log.info("bytecode dir=" + compileConfig.getByteCodeCacheDir());
    RouterService server = DevRouterFactory.create(f, compileConfig);
    return server;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) CompileConfig(org.webpieces.compiler.api.CompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

Example 7 with RouterService

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

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

the class DevRouterFactory method create.

public static RouterService create(RouterConfig config, CompileConfig compileConfig) {
    Module devModules = Modules.override(RouterSvcFactory.getModules(config)).with(new DevRouterModule(compileConfig));
    Injector injector = Guice.createInjector(devModules);
    RouterService svc = injector.getInstance(RouterService.class);
    return svc;
}
Also used : RouterService(org.webpieces.router.api.RouterService) Injector(com.google.inject.Injector) Module(com.google.inject.Module)

Example 9 with RouterService

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

the class TestSimpleRoutes 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);
    //for dev must be null
    config.setWebappOverrides(null);
    String filePath = System.getProperty("user.dir");
    File myCodePath = new File(filePath + "/src/test/java");
    CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath));
    RouterService devSvc = DevRouterFactory.create(config, compileConfig);
    return Arrays.asList(new Object[][] { { prodSvc, module }, { devSvc, module } });
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) CompileConfig(org.webpieces.compiler.api.CompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile) RouterConfig(org.webpieces.router.api.RouterConfig)

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