private void assertBean(MockClient client, String name, Object expected) throws Exception { MockViewBridge render = client.render(name); String url = render.assertStringResponse(); MockViewBridge m = (MockViewBridge)client.invoke(url); assertEquals(expected, m.assertStringResponse()); render = client.render(name + "Action"); url = render.assertStringResponse(); MockActionBridge action = (MockActionBridge)client.invoke(url); MockViewBridge m2 = (MockViewBridge)client.invoke(action.assertUpdate()); assertEquals(expected, m2.assertStringResponse()); }
public MockClient client() { return new MockClient(this); }
private void assertPermitAll(String packageName) throws Exception { MockApplication<?> application = application(InjectorProvider.GUICE, packageName); application.init(); MockClient client = application.client(); MockViewBridge view1 = client.render(); view1.assertOk(); client.addRole("foo"); MockViewBridge view2 = client.render(); view2.assertOk(); }
public ScopedContext getScopedContext(Scope scope, boolean create) { ScopedContext context; switch (scope) { case REQUEST: context = attributes; break; case FLASH: context = client.getFlashContext(create); break; case SESSION: context = client.getSession(); break; default: throw new UnsupportedOperationException("Unsupported scope " + scope); } return context; }
@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()); }
client.render(); long id1 = Registry.<Long>unset("car"); int status = Registry.<Integer>unset("status"); assertEquals(Identifiable.MANAGED, status); assertEquals(1, client.getFlashHistory(1).size()); Identifiable car1 = (Identifiable)client.getFlashHistory(1).iterator().next().get(); assertEquals(car1.getIdentityHashCode(), id1); assertEquals(Identifiable.DESTROYED, car1.getStatus()); client.invoke(Registry.<String>unset("action")); long id2 = Registry.<Long>unset("car"); status = Registry.<Integer>unset("status"); assertEquals(Identifiable.MANAGED, status); assertNotSame(id1, id2); assertEquals(1, client.getFlashHistory(0).size()); Identifiable car2 = (Identifiable)client.getFlashHistory(0).iterator().next().get(); assertNotSame(car1, car2); assertEquals(Identifiable.MANAGED, car2.getStatus()); client.render(); long id3 = Registry.<Long>unset("car"); status = Registry.<Integer>unset("status"); assertEquals(Identifiable.MANAGED, status); assertEquals(id2, id3); assertEquals(1, client.getFlashHistory(1).size()); Identifiable car3 = (Identifiable)client.getFlashHistory(1).iterator().next().get(); assertSame(car2, car3); assertEquals(Identifiable.DESTROYED, car2.getStatus());
@Test public void testRequest() throws Exception { MockApplication<?> application = application(InjectorProvider.GUICE, "plugin.controller.contextual.request"); application.init(); MockClient client = application.client(); MockViewBridge request = client.render(); Assert.assertEquals("pass", request.assertStringResponse()); } }
client.render(); long id1 = Registry.<Long>unset("car"); int status = Registry.<Integer>unset("status"); assertEquals(Identifiable.MANAGED, status); assertEquals(1, client.getFlashHistory(1).size()); Identifiable car1 = (Identifiable)client.getFlashHistory(1).iterator().next().get(); assertEquals(car1.getIdentityHashCode(), id1); assertEquals(Identifiable.DESTROYED, car1.getStatus()); client.invoke(Registry.<String>unset("action")); long id2 = Registry.<Long>unset("car"); status = Registry.<Integer>unset("status"); assertEquals(Identifiable.MANAGED, status); assertNotSame(id1, id2); assertEquals(1, client.getFlashHistory(0).size()); Identifiable car2 = (Identifiable)client.getFlashHistory(0).iterator().next().get(); assertNotSame(car1, car2); assertEquals(Identifiable.MANAGED, car2.getStatus()); client.render(); long id3 = Registry.<Long>unset("car"); status = Registry.<Integer>unset("status"); assertEquals(Identifiable.MANAGED, status); assertEquals(id2, id3); assertEquals(1, client.getFlashHistory(1).size()); Identifiable car3 = (Identifiable)client.getFlashHistory(1).iterator().next().get(); assertSame(car2, car3); assertEquals(Identifiable.DESTROYED, car2.getStatus());
public ScopedContext getScopedContext(Scope scope, boolean create) { ScopedContext context; switch (scope) { case REQUEST: context = attributes; break; case FLASH: context = client.getFlashContext(create); break; case SESSION: context = client.getSession(); break; default: throw new UnsupportedOperationException("Unsupported scope " + scope); } return context; }
@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()); }
private <T extends Throwable> T runParseError(String pkg, Class<T> expected) throws Exception { MockApplication<File> application = application(InjectorProvider.GUICE, pkg); MockApplication<?> app = application.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); MockViewBridge action = (MockViewBridge)client.invoke(render.assertStringResponse()); return action.assertFailure(expected); }
private void assertRolesAllowed(String packageName) throws Exception { MockApplication<?> application = application(InjectorProvider.GUICE, packageName); application.init(); MockClient client = application.client(); MockViewBridge view1 = client.render(); assertInstanceOf(Response.Error.Forbidden.class, view1.assertError()); client.addRole("foo"); MockViewBridge view2 = client.render(); view2.assertOk(); }
public MockClient client() { return new MockClient(this); }
@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); }
@Test public void testRender() throws Exception { MockApplication<?> app = application("plugin.controller.action.render").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); MockActionBridge action = (MockActionBridge)client.invoke(render.assertStringResponse()); action.assertRender("render", Collections.singletonMap("arg", "arg_value")); } }
private void assertDenyAll(String packageName) throws Exception { MockApplication<?> application = application(InjectorProvider.GUICE, packageName); application.init(); MockClient client = application.client(); MockViewBridge view1 = client.render(); assertInstanceOf(Response.Error.Forbidden.class, view1.assertError()); client.addRole("foo"); MockViewBridge view2 = client.render(); assertInstanceOf(Response.Error.Forbidden.class, view2.assertError()); } }
@Test public void testConstructorChecked() throws Exception { MockApplication<?> app = application("plugin.controller.constructor.throwable.checked").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); render.assertFailure(AuthenticationException.class); }
@Test public void testUpdate() throws Exception { MockApplication<?> app = application("plugin.controller.view.update").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String result = render.assertStringResponse(); MockActionBridge action = (MockActionBridge)client.invoke(result); action.assertRender("A.done", Collections.<String, String>emptyMap()); } }