IdentityController implements InstantaneousRequest { @Override public Response handleAsOf(Request request, DateTime instantTime) { Optional<String> optIdentity = identityFinder.find(request, instantTime); if (!optIdentity.isPresent()) { String continueTo = queryParams(request); return new RsRedirect(loginPageUrl + continueTo); } return identityActivity.execute(optIdentity.get(), request); } IdentityController(ResourceOwnerIdentityFinder identityFinder, IdentityActivity identityActivity, String loginPageUrl); @Override Response handleAsOf(Request request, DateTime instantTime);  }
@Test public void happyPath() throws IOException { IdentityController identityController = new IdentityController(identityFinder, identityActivity, ""); final Request request = new ParamRequest(ImmutableMap.of( "client_id", "::client_id::" )); final DateTime anyInstantTime = new DateTime(); context.checking(new Expectations() {{ oneOf(identityFinder).find(request, anyInstantTime); will(returnValue(Optional.of("::identity_id::"))); oneOf(identityActivity).execute("::identity_id::", request); will(returnValue(new RsText("test response"))); }}); Response response = identityController.handleAsOf(request, anyInstantTime); assertThat(new RsPrint(response).printBody(), is(equalTo("test response"))); }
@Test public void userWasNotAuthorized() throws IOException { IdentityController identityController = new IdentityController(identityFinder, identityActivity, "/r/oauth/login?continue="); final Request request = new ParamRequest(ImmutableMap.of("client_id", "::client1::")); final DateTime anyInstantTime = new DateTime(); context.checking(new Expectations() {{ oneOf(identityFinder).find(request, anyInstantTime); will(returnValue(Optional.absent())); }}); Response response = identityController.handleAsOf(request, anyInstantTime); Status status = response.status(); assertThat(status.code, is(equalTo(HttpURLConnection.HTTP_MOVED_TEMP))); assertThat(status.redirectUrl, is(equalTo("/r/oauth/login?continue=%2F%3Fclient_id%3D%3A%3Aclient1%3A%3A"))); }