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()); }
private Object invokeErrorHandler(String pkg) throws Exception { MockApplication app = application(pkg).init(); MockClient client = app.client(); shared = null; MockViewBridge render = client.render(); render.assertOk(); render.assertStringResponse("hello"); assertNotNull(shared); return shared; }
@Test public void testMimeType() throws Exception { MockApplication app = application("plugin.controller.mimetype.html").init(); MockClient client = app.client(); MockViewBridge render = client.render(); render.assertStringResponse("HELLO"); Iterable<String> mimeType = render.getResponse().getProperties().getValues(PropertyType.MIME_TYPE); assertNotNull(mimeType); Iterator<String> iterator = mimeType.iterator(); assertTrue(iterator.hasNext()); assertEquals("text/html", iterator.next()); } }
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); }
@Test public void testTitle() throws Exception { MockApplication<?> app = application("plugin.template.tag.title").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String url = render.assertStringResponse(); assertEquals("the_title", render.getTitle()); render = (MockViewBridge)client.invoke(url); assertEquals("4", render.getTitle()); }
@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); }
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(); }
@Test public void testValidation() throws Exception { MockApplication app = application("juzu.simple").init(); MockClient client = app.client(); MockViewBridge render = client.render(); ValidationError va = assertInstanceOf(ValidationError.class, render.getResponse()); Set<ConstraintViolation<Object>> violations = va.getViolations(); assertEquals(1, violations.size()); ConstraintViolation<Object> violation = violations.iterator().next(); assertEquals("may not be null", violation.getMessage()); Iterator<Path.Node> path = violation.getPropertyPath().iterator(); Path.Node n1 = path.next(); assertEquals("index", n1.getName()); assertEquals(ElementKind.METHOD, n1.getKind()); Path.Node n2 = path.next(); assertEquals("mandatory", n2.getName()); assertEquals(ElementKind.PARAMETER, n2.getKind()); assertFalse(path.hasNext()); }
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 MockViewBridge render(String methodId) { MethodHandle handle = null; ControllerHandler handler = null; if (methodId != null) { handler = controllerPlugin.getDescriptor().getMethodById(methodId); } else { handler = controllerPlugin.getDescriptor().getResolver().resolve(Phase.VIEW, Collections.<String>emptySet()); } if (handler != null) { handle = handler.getHandle(); } MockViewBridge render = new MockViewBridge(application.getLifeCycle(), this, handle, new HashMap<String, String[]>()); invoke(render); return render; }
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 testTitle() throws Exception { MockApplication<?> app = application("plugin.template.tag.title").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String url = render.assertStringResponse(); assertEquals("the_title", render.getTitle()); render = (MockViewBridge)client.invoke(url); assertEquals("4", render.getTitle()); }
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); }
@Test public void testConstructorRuntime() throws Exception { MockApplication<?> app = application("plugin.controller.constructor.throwable.runtime").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); render.assertFailure(ConcurrentModificationException.class); }
@Test public void testValidation() throws Exception { MockApplication app = application("juzu.simple").init(); MockClient client = app.client(); MockViewBridge render = client.render(); ValidationError va = assertInstanceOf(ValidationError.class, render.getResponse()); Set<ConstraintViolation<Object>> violations = va.getViolations(); assertEquals(1, violations.size()); ConstraintViolation<Object> violation = violations.iterator().next(); assertEquals("may not be null", violation.getMessage()); Iterator<Path.Node> path = violation.getPropertyPath().iterator(); Path.Node n1 = path.next(); assertEquals("index", n1.getName()); assertEquals(ElementKind.METHOD, n1.getKind()); Path.Node n2 = path.next(); assertEquals("mandatory", n2.getName()); assertEquals(ElementKind.PARAMETER, n2.getKind()); assertFalse(path.hasNext()); }
public MockViewBridge render(String methodId) { MethodHandle handle = null; ControllerHandler handler = null; if (methodId != null) { handler = controllerPlugin.getDescriptor().getMethodById(methodId); } else { handler = controllerPlugin.getDescriptor().getResolver().resolve(Phase.VIEW, Collections.<String>emptySet()); } if (handler != null) { handle = handler.getHandle(); } MockViewBridge render = new MockViewBridge(application.getLifeCycle(), this, handle, new HashMap<String, String[]>()); invoke(render); return render; }
private void runSuccess(String pkg) 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()); String result = action.assertStringResponse(); assertEquals("pass", result); }
@Test public void testInjection() throws Exception { MockApplication<?> app = application("plugin.controller.context").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); assertEquals("render_phase", render.assertStringResponse()); // String url = render.getTitle(); MockActionBridge action = (MockActionBridge)client.invoke(url); // // client. // client.invoke(); // assertNull(Registry.get("car")); // // client.invoke(Registry.<String>unset("resource")); // assertNull(Registry.get("car")); } }
private Object invokeErrorHandler(String pkg) throws Exception { MockApplication app = application(pkg).init(); MockClient client = app.client(); shared = null; MockViewBridge render = client.render(); render.assertOk(); render.assertStringResponse("hello"); assertNotNull(shared); return shared; }
@Test public void testMimeType() throws Exception { MockApplication app = application("plugin.controller.mimetype.html").init(); MockClient client = app.client(); MockViewBridge render = client.render(); render.assertStringResponse("HELLO"); Iterable<String> mimeType = render.getResponse().getProperties().getValues(PropertyType.MIME_TYPE); assertNotNull(mimeType); Iterator<String> iterator = mimeType.iterator(); assertTrue(iterator.hasNext()); assertEquals("text/html", iterator.next()); } }