@Test public void testAuthorizeRequest() { UiNgResourceForwarding service = new UiNgResourceForwarding("/sample", "/sample-new"); AtomicBoolean completionCalled = new AtomicBoolean(); service.authorizeRequest(new Operation().setCompletion((o, e) -> { completionCalled.set(true); })); assertTrue(completionCalled.get()); }
@Override public void handleGet(Operation get) { if (redirectToLoginOrIndex(getHost(), get)) { return; operation.setUri(UriUtils.buildUri(getHost(), uriPath)) .setCompletion((o, e) -> { get.setBody(o.getBodyRaw()) sendRequest(operation);
public UiNgResourceForwarding(String sourcePath, String targetPath, boolean redirect) { this.sourcePath = sourcePath; this.targetPath = targetPath; this.redirect = redirect; setSelfLink(sourcePath); this.options.add(ServiceOption.URI_NAMESPACE_OWNER); }
@Test public void testForwardIndexHtml() { UiNgResourceForwarding service = new UiNgResourceForwarding("/sample/", "/sample-new/") { @Override public void sendRequest(Operation op) { if (op.getUri().getPath().equals("/sample-new/index.html")) { op.setBody("OK"); op.complete(); } } }; service.setHost(VerificationHost.create()); AtomicBoolean completionCalled = new AtomicBoolean(); service.handleGet(new Operation().setUri(UriUtils.buildUri("http://localhost/sample/")) .setCompletion((o, e) -> { assertEquals("OK", o.getBodyRaw()); completionCalled.set(true); })); assertTrue(completionCalled.get()); }
@Test public void testForward() { UiNgResourceForwarding service = new UiNgResourceForwarding("/sample", "/sample-new") { @Override public void sendRequest(Operation op) { if (op.getUri().getPath().equals("/sample-new")) { op.setBody("OK"); op.complete(); } } }; service.setHost(VerificationHost.create()); AtomicBoolean completionCalled = new AtomicBoolean(); service.handleGet(new Operation().setUri(UriUtils.buildUri("http://localhost/sample")) .setCompletion((o, e) -> { assertEquals("OK", o.getBodyRaw()); completionCalled.set(true); })); assertTrue(completionCalled.get()); }
protected void startRedirectService(String sourcePath, String targetPath) { Operation post = Operation .createPost(UriUtils.buildUri(getHost(), sourcePath)); UiNgResourceForwarding rf = new UiNgResourceForwarding(sourcePath, targetPath, true); getHost().startService(post, rf); }
@Test public void testRedirect() { UiNgResourceForwarding service = new UiNgResourceForwarding("/sample", "/sample-new", true); service.setHost(VerificationHost.create()); AtomicBoolean completionCalled = new AtomicBoolean(); service.handleGet(new Operation().setUri(UriUtils.buildUri("http://localhost/sample")) .setCompletion((o, e) -> { assertEquals("/sample-new", o.getResponseHeader(Operation.LOCATION_HEADER)); completionCalled.set(true); })); assertTrue(completionCalled.get()); }
protected void startForwardingService(String sourcePath, String targetPath) { Operation post = Operation .createPost(UriUtils.buildUri(getHost(), sourcePath)); UiNgResourceForwarding rf = new UiNgResourceForwarding(sourcePath, targetPath); getHost().startService(post, rf); }