@Test public void testSimple() throws Exception { // We only use CDI for its capability to discover beans automatically MockApplication<?> application = application(InjectorProvider.WELD, "plugin.controller.contextual.simple"); application.init(); MockClient client = application.client(); MockViewBridge request = client.render(); Assert.assertEquals("__foo__", request.assertStringResponse()); }
@Test public void testMessage() throws Exception { MockApplication<?> app = application("plugin.template.message").init(); app.addMessage(Locale.ENGLISH, "the_key", "the_key_en"); MockClient client = app.client(); assertEquals("(the_key_en,)", client.render().assertStringResponse()); }
@Test public void testRuntime() throws Exception { MockApplication<?> app = application("plugin.asset.notfound.runtime"); File root = (File)app.getSourcePath().getPath("plugin", "asset", "notfound", "runtime"); File js = new File(root, "assets/notfound.js"); assertTrue(js.getParentFile().mkdirs()); assertTrue(js.createNewFile()); app.assertCompile(); root = (File)app.getClasses().getPath("plugin", "asset", "notfound", "runtime"); js = new File(root, "assets/notfound.js"); assertTrue(js.delete()); try { app.init(); fail(); } catch (Exception ignore) { } } }
@Test public void testClass() throws Exception { MockApplication<?> app = application("plugin.portlet.base").init(); Class<?> portletClass = app.getContext().getClassLoader().loadClass("plugin.portlet.base.BasePortlet"); }
@Test public void testLifeCycle() throws Exception { events.clear(); MockApplication<?> app = application("plugin.controller.executionfilter.lifecycle").init(); Tools.list(app.getLifeCycle().resolveBeans(RequestFilter.class)); MockClient client = app.client(); MockViewBridge render = client.render(); assertEquals((Object)Arrays.asList("execute", "onCommand", "beforeRun", "run", "afterRun", "hello"), events); }
helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.simple.reuse")); app.init(); MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse();
@Test public void testCreate() throws Exception { MockApplication<File> app = application("plugin.binding.provider.factory.create"); File root = app.getClasses().getRoot(); File services = new File(root, "META-INF/services"); assertTrue(services.mkdirs()); File providers = new File(services, ProviderFactory.class.getName()); FileWriter writer = new FileWriter(providers); writer.append("plugin.binding.provider.factory.create.ProviderFactoryImpl"); writer.close(); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); assertEquals("pass", render.assertStringResponse()); }
@Test public void testGetProviderThrowable() throws Exception { MockApplication<File> app = application("plugin.binding.provider.factory.throwable"); File root = app.getClasses().getRoot(); File services = new File(root, "META-INF/services"); assertTrue(services.mkdirs()); File providers = new File(services, ProviderFactory.class.getName()); FileWriter writer = new FileWriter(providers); writer.append("plugin.binding.provider.factory.throwable.ServiceProviderFactory"); writer.close(); // try { app.init(); fail(); } catch (SecurityException e) { } } }
public MockApplication<File> application(InjectorProvider injectorProvider, String packageName) { if (application != null) { throw failure("An application is already deployed"); } CompilerAssert<File, File> compiler = compiler(packageName); try { return application = new MockApplication<File>(compiler, injectorProvider, Name.parse(packageName)); } catch (Exception e) { throw AbstractTestCase.failure(e); } }
public MockApplication<P> init() throws Exception { if (lifeCycle == null) { assertCompile(); } if (lifeCycle != null) { Completion refresh = lifeCycle.refresh(); if (refresh.isFailed()) { throw refresh.getCause(); } else { return this; } } else { throw new IllegalStateException("Could not compile application"); } }
helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.simple.reuse")); app.init(); MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse();
@Test public void testCreate() throws Exception { MockApplication<File> app = application("plugin.binding.provider.factory.create"); File root = app.getClasses().getRoot(); File services = new File(root, "META-INF/services"); assertTrue(services.mkdirs()); File providers = new File(services, ProviderFactory.class.getName()); FileWriter writer = new FileWriter(providers); writer.append("plugin.binding.provider.factory.create.ProviderFactoryImpl"); writer.close(); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); assertEquals("pass", render.assertStringResponse()); }
@Test public void testLifeCycle() throws Exception { Registry.unset("request.filter.lifecycle"); MockApplication<?> app = application("plugin.controller.requestfilter.lifecycle").init(); Tools.list(app.getLifeCycle().resolveBeans(RequestFilter.class)); assertEquals("created", Registry.get("request.filter.lifecycle")); MockClient client = app.client(); MockViewBridge render = client.render(); assertEquals("after", Registry.get("request.filter.lifecycle")); }
@Test public void testGetProviderThrowable() throws Exception { MockApplication<File> app = application("plugin.binding.provider.factory.throwable"); File root = app.getClasses().getRoot(); File services = new File(root, "META-INF/services"); assertTrue(services.mkdirs()); File providers = new File(services, ProviderFactory.class.getName()); FileWriter writer = new FileWriter(providers); writer.append("plugin.binding.provider.factory.throwable.ServiceProviderFactory"); writer.close(); // try { app.init(); fail(); } catch (SecurityException e) { } } }
public MockApplication<File> application(InjectorProvider injectorProvider, String packageName) { if (application != null) { throw failure("An application is already deployed"); } CompilerAssert<File, File> compiler = compiler(packageName); try { return application = new MockApplication<File>(compiler, injectorProvider, Name.parse(packageName)); } catch (Exception e) { throw AbstractTestCase.failure(e); } }
public MockApplication<P> init() throws Exception { if (lifeCycle == null) { assertCompile(); } if (lifeCycle != null) { Completion refresh = lifeCycle.refresh(); if (refresh.isFailed()) { throw refresh.getCause(); } else { return this; } } else { throw new IllegalStateException("Could not compile application"); } }
@Test public void testSimple() throws Exception { // We only use CDI for its capability to discover beans automatically MockApplication<?> application = application(InjectorProvider.WELD, "plugin.controller.contextual.simple"); application.init(); MockClient client = application.client(); MockViewBridge request = client.render(); Assert.assertEquals("__foo__", request.assertStringResponse()); }
@Test public void testDecorateExternal() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.tag.decorate"); simpleHelper.assertCompile(); CompilerAssert<File, File> helper = compiler("plugin.template.tag.decorateexternal"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.decorateexternal")); app.init(); MockClient client = app.client(); assertEquals("<foo>bar</foo>", client.render().assertStringResponse()); }
@Test public void testPrecompileGroovy() throws Exception { MockApplication<File> app = application("plugin.template.simple").init(); ReadFileSystem<File> fs = app.getClasses(); File groovy = fs.getPath("plugin", "template", "simple", "templates", "index_.groovy"); assertNotNull(groovy); CompilerConfiguration config = new CompilerConfiguration(); config.setTargetDirectory(fs.getRoot()); CompilationUnit cu = new CompilationUnit(config); cu.addSource(groovy); cu.compile(); assertTrue(groovy.delete()); MockClient client = app.client(); assertEquals("hello", client.render().assertStringResponse()); } }
@Test public void testLifeCycle() throws Exception { Registry.unset("request.filter.lifecycle"); MockApplication<?> app = application("plugin.controller.requestfilter.lifecycle").init(); Tools.list(app.getLifeCycle().resolveBeans(RequestFilter.class)); assertEquals("created", Registry.get("request.filter.lifecycle")); MockClient client = app.client(); MockViewBridge render = client.render(); assertEquals("after", Registry.get("request.filter.lifecycle")); }