Search in sources :

Example 1 with TemplateApi

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

the class TestCompressionCache method setUp.

@Before
public void setUp() throws IOException {
    FileUtils.deleteDirectory(cacheDir);
    log.info("deleting dir=" + cacheDir);
    File stagingDir = FileFactory.newBaseFile("output/staging");
    FileUtils.deleteDirectory(stagingDir);
    RouterConfig config = new RouterConfig(FileFactory.getBaseWorkingDir(), "TestCompressionCache");
    config.setSecretKey(SecretKeyInfo.generateForTest());
    config.setCachedCompressedDirectory(cacheDir);
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TemplateApi nullApi = new NullTemplateApi();
    List<Module> modules = RouterServiceFactory.getModules(metrics, config, nullApi);
    Module allMods = Modules.override(modules).with(new TestModule());
    Injector injector = Guice.createInjector(allMods);
    cache = injector.getInstance(CompressionCacheSetup.class);
}
Also used : TemplateApi(org.webpieces.router.api.TemplateApi) Injector(com.google.inject.Injector) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Module(com.google.inject.Module) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile) RouterConfig(org.webpieces.router.api.RouterConfig) Before(org.junit.Before)

Example 2 with TemplateApi

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

the class ErrorCommonTest method createServer.

public static RouterService createServer(boolean isProdTest, String moduleFileContents) {
    VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TemplateApi nullApi = new NullTemplateApi();
    if (isProdTest)
        return RouterServiceFactory.create("ErrorCommonTest", metrics, f, nullApi);
    // otherwise create the development server
    String filePath = System.getProperty("user.dir");
    File myCodePath = new File(filePath + "/src/test/java");
    VirtualFile cacheLocation = new VirtualFileImpl(FileFactory.newCacheLocation("webpieces/" + ErrorCommonTest.class.getSimpleName() + "/bytecode"));
    CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath), cacheLocation);
    log.info("bytecode dir=" + compileConfig.getByteCodeCacheDir());
    RouterService server = DevRouterFactory.create("ErrorCommonTest", metrics, f, compileConfig, nullApi);
    return server;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) TemplateApi(org.webpieces.router.api.TemplateApi) NullTemplateApi(org.webpieces.router.api.simplesvr.NullTemplateApi) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CompileConfig(org.webpieces.compiler.api.CompileConfig) NullTemplateApi(org.webpieces.router.api.simplesvr.NullTemplateApi) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

Example 3 with TemplateApi

use of org.webpieces.router.api.TemplateApi 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");
    File baseWorkingDir = FileFactory.getBaseWorkingDir();
    TestModule module = new TestModule();
    Arguments args = new CommandLineParser().parse();
    RouterConfig config = new RouterConfig(baseWorkingDir, "TestProdRouter").setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TemplateApi nullApi = new NullTemplateApi();
    RouterService prodSvc = RouterServiceFactory.create(metrics, config, nullApi);
    prodSvc.configure(args);
    args.checkConsumedCorrectly();
    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) TemplateApi(org.webpieces.router.api.TemplateApi) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Arguments(org.webpieces.util.cmdline2.Arguments) CommandLineParser(org.webpieces.util.cmdline2.CommandLineParser) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile) RouterConfig(org.webpieces.router.api.RouterConfig)

Example 4 with TemplateApi

use of org.webpieces.router.api.TemplateApi 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();
    File baseWorkingDir = FileFactory.getBaseWorkingDir();
    Arguments args = new CommandLineParser().parse();
    RouterConfig config = new RouterConfig(baseWorkingDir, "TestSimpleRoutes").setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TemplateApi nullApi = new NullTemplateApi();
    RouterService prodSvc = RouterServiceFactory.create(metrics, config, nullApi);
    prodSvc.configure(args);
    args.checkConsumedCorrectly();
    // for dev must be null
    config.setWebappOverrides(null);
    String filePath = System.getProperty("user.dir");
    File myCodePath = new File(filePath + "/src/test/java");
    VirtualFile cacheLocation = new VirtualFileImpl(FileFactory.newCacheLocation("webpieces/" + TestSimpleRoutes.class.getSimpleName() + "/bytecode"));
    CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath), cacheLocation);
    Arguments args2 = new CommandLineParser().parse();
    SimpleMeterRegistry metrics2 = new SimpleMeterRegistry();
    RouterService devSvc = DevRouterFactory.create(metrics2, config, compileConfig, nullApi);
    devSvc.configure(args2);
    args2.checkConsumedCorrectly();
    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) TemplateApi(org.webpieces.router.api.TemplateApi) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Arguments(org.webpieces.util.cmdline2.Arguments) CompileConfig(org.webpieces.compiler.api.CompileConfig) RouterConfig(org.webpieces.router.api.RouterConfig) CommandLineParser(org.webpieces.util.cmdline2.CommandLineParser) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

Example 5 with TemplateApi

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

the class PluginSetup method wireInPluginPoints.

/**
 * This is where we wire in all plugin points EXCEPT the Startup one
 * we can't inject them :(
 */
@SuppressWarnings("rawtypes")
public void wireInPluginPoints(Injector appInjector) {
    Key<Set<EntityLookup>> key = Key.get(new TypeLiteral<Set<EntityLookup>>() {
    });
    Set<EntityLookup> lookupHooks = appInjector.getInstance(key);
    translator.install(lookupHooks);
    Key<Set<ObjectStringConverter>> key3 = Key.get(new TypeLiteral<Set<ObjectStringConverter>>() {
    });
    Set<ObjectStringConverter> converters = appInjector.getInstance(key3);
    translation.install(converters);
    Key<Set<BodyContentBinder>> key2 = Key.get(new TypeLiteral<Set<BodyContentBinder>>() {
    });
    Set<BodyContentBinder> bodyBinders = appInjector.getInstance(key2);
    bodyContentChecker.install(bodyBinders);
    Key<Set<HtmlTagCreator>> key4 = Key.get(new TypeLiteral<Set<HtmlTagCreator>>() {
    });
    Set<HtmlTagCreator> htmlTagCreators = appInjector.getInstance(key4);
    // Guice circular dependency we could not work around quite yet.  figure out later maybe
    TemplateApi api = templateApi.get();
    api.installCustomTags(htmlTagCreators);
}
Also used : BodyContentBinder(org.webpieces.router.api.extensions.BodyContentBinder) Set(java.util.Set) TemplateApi(org.webpieces.router.api.TemplateApi) EntityLookup(org.webpieces.router.api.extensions.EntityLookup) HtmlTagCreator(org.webpieces.ctx.api.extension.HtmlTagCreator) ObjectStringConverter(org.webpieces.router.api.extensions.ObjectStringConverter)

Aggregations

TemplateApi (org.webpieces.router.api.TemplateApi)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 File (java.io.File)4 VirtualFile (org.webpieces.util.file.VirtualFile)4 RouterConfig (org.webpieces.router.api.RouterConfig)3 RouterService (org.webpieces.router.api.RouterService)3 VirtualFileInputStream (org.webpieces.router.api.mocks.VirtualFileInputStream)3 CompileConfig (org.webpieces.compiler.api.CompileConfig)2 Arguments (org.webpieces.util.cmdline2.Arguments)2 CommandLineParser (org.webpieces.util.cmdline2.CommandLineParser)2 VirtualFileImpl (org.webpieces.util.file.VirtualFileImpl)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 Set (java.util.Set)1 Before (org.junit.Before)1 HtmlTagCreator (org.webpieces.ctx.api.extension.HtmlTagCreator)1 BodyContentBinder (org.webpieces.router.api.extensions.BodyContentBinder)1 EntityLookup (org.webpieces.router.api.extensions.EntityLookup)1 ObjectStringConverter (org.webpieces.router.api.extensions.ObjectStringConverter)1 NullTemplateApi (org.webpieces.router.api.simplesvr.NullTemplateApi)1