### Question:
LoginAuthenticator { public LoginProcess getLoginProcess(LoginConfiguration loginConfiguration) throws AuthException, AuthLoginException, SSOException, RestAuthException { verifyAuthenticationRealm(loginConfiguration.getHttpRequest()); SSOToken ssoToken = coreServicesWrapper.getExistingValidSSOToken(new SessionID(loginConfiguration.getSSOTokenId())); if (noMoreAuthenticationRequired(ssoToken, loginConfiguration)) { return new CompletedLoginProcess(this, loginConfiguration, coreServicesWrapper, ssoToken); } AuthContextLocalWrapper authContext = getAuthContext(loginConfiguration); LoginProcess loginProcess = new LoginProcess(this, loginConfiguration, authContext, coreServicesWrapper); if (coreServicesWrapper.isNewRequest(authContext)) { startLoginProcess(loginProcess); } return loginProcess; } @Inject  LoginAuthenticator(CoreServicesWrapper coreServicesWrapper); LoginProcess getLoginProcess(LoginConfiguration loginConfiguration);  }### Answer:
@Test public void shouldThrow400ExceptionWithOrgDNNotValidReturningEmptyString() throws SSOException, AuthException, AuthLoginException, IOException { LoginConfiguration loginConfiguration = new LoginConfiguration(); HttpServletRequest request = mock(HttpServletRequest.class); String sessionId = "SESSION_ID"; AuthIndexType authIndexType = AuthIndexType.COMPOSITE; String authIndexValue = "INDEX_VALUE"; String ssoTokenId = "SSO_TOKEN_ID"; loginConfiguration.httpRequest(request) .sessionId(sessionId) .indexType(authIndexType) .indexValue(authIndexValue) .sessionUpgrade(ssoTokenId); given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn(""); boolean exceptionCaught = false; RestAuthException exception = null; try { loginAuthenticator.getLoginProcess(loginConfiguration); } catch (RestAuthException e) { exceptionCaught = true; exception = e; } assertTrue(exceptionCaught); assertEquals(exception.getStatusCode(), 400); }
@Test public void shouldThrow400ExceptionWithOrgDNNotValid() throws SSOException, AuthException, AuthLoginException, IOException { LoginConfiguration loginConfiguration = new LoginConfiguration(); HttpServletRequest request = mock(HttpServletRequest.class); String sessionId = "SESSION_ID"; AuthIndexType authIndexType = AuthIndexType.COMPOSITE; String authIndexValue = "INDEX_VALUE"; String ssoTokenId = "SSO_TOKEN_ID"; loginConfiguration.httpRequest(request) .sessionId(sessionId) .indexType(authIndexType) .indexValue(authIndexValue) .sessionUpgrade(ssoTokenId); given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn(""); boolean exceptionCaught = false; RestAuthException exception = null; try { loginAuthenticator.getLoginProcess(loginConfiguration); } catch (RestAuthException e) { exceptionCaught = true; exception = e; } assertTrue(exceptionCaught); assertEquals(exception.getStatusCode(), 400); }
@Test public void shouldThrow400ExceptionWithOrgDNNotValidReturningNull() throws SSOException, AuthException, AuthLoginException, IOException { LoginConfiguration loginConfiguration = new LoginConfiguration(); HttpServletRequest request = mock(HttpServletRequest.class); String sessionId = "SESSION_ID"; AuthIndexType authIndexType = AuthIndexType.COMPOSITE; String authIndexValue = "INDEX_VALUE"; String ssoTokenId = "SSO_TOKEN_ID"; loginConfiguration.httpRequest(request) .sessionId(sessionId) .indexType(authIndexType) .indexValue(authIndexValue) .sessionUpgrade(ssoTokenId); given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn(null); boolean exceptionCaught = false; RestAuthException exception = null; try { loginAuthenticator.getLoginProcess(loginConfiguration); } catch (RestAuthException e) { exceptionCaught = true; exception = e; } assertTrue(exceptionCaught); assertEquals(exception.getStatusCode(), 400); }