test/org/ohmage/test/auth/AuthenticationApiTest.java
private void testAuthToken(final String username, final String password) 
			throws ApiException {
		
		// No username.
		try {
			api.getAuthenticationToken(null, password, Controller.CLIENT);
			throw new IllegalStateException("Failed: No username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		
		// Invalid username.
		try {
			api.getAuthenticationToken("blah", password, Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}

		// No password
		try {
			api.getAuthenticationToken(username, null, Controller.CLIENT);
			throw new IllegalStateException("Failed: No password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}

		// Invalid password
		try {
			api.getAuthenticationToken(username, "blah", Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}

		// No client.
		try {
			api.getAuthenticationToken(username, password, null);
			throw new IllegalStateException("Failed: No client.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.SERVER_INVALID_CLIENT.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No client: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}

		// This request should be valid.
		try {
			api.getAuthenticationToken(username, password, Controller.CLIENT);
		}
		catch(RequestErrorException e) {
			throw new IllegalStateException("Failed: Valid request.", e);
		}
	}
/**
	 * Tests the different possibilities for getting an authentication token.
	 * 
	 * @param username The username of the user to test.
	 * 
	 * @param password The password of the user to test.
	 * 
	 * @throws ApiException Thrown if an incorrect error code is returned or
	 * 						there is a bug in the library.
	 * 
	 * @throws IllegalStateException Thrown if the test fails.
	 */
Tests the different possibilities for getting an authentication token.

@param username The username of the user to test.

@param password The password of the user to test.

@throws ApiException Thrown if an incorrect error code is returned or
there is a bug in the library.

@throws IllegalStateException Thrown if the test fails.
Tests the different possibilities for getting an authentication token . @param username The username of the user to test . @param password The password of the user to test . @throws ApiException Thrown if an incorrect error code is returned or there is a bug in the library . @throws IllegalStateException Thrown if the test fails .
private void testAuthToken(final String username, final String password) 
			throws ApiException {
		try {
			api.getAuthenticationToken(null, password, Controller.CLIENT);
			throw new IllegalStateException("Failed: No username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getAuthenticationToken("blah", password, Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid username.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid username: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getAuthenticationToken(username, null, Controller.CLIENT);
			throw new IllegalStateException("Failed: No password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getAuthenticationToken(username, "blah", Controller.CLIENT);
			throw new IllegalStateException("Failed: Invalid password.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.AUTHENTICATION_FAILED.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: Invalid password: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getAuthenticationToken(username, password, null);
			throw new IllegalStateException("Failed: No client.");
		}
		catch(RequestErrorException e) {
			if(! ErrorCode.SERVER_INVALID_CLIENT.equals(e.getErrorCode())) {
				throw new IllegalStateException("Failed: No client: " + ErrorCode.AUTHENTICATION_FAILED, e);
			}
		}
		try {
			api.getAuthenticationToken(username, password, Controller.CLIENT);
		}
		catch(RequestErrorException e) {
			throw new IllegalStateException("Failed: Valid request.", e);
		}
	}
private void testAuthToken ( final String username , final String password ) throws ApiException { try { api . getAuthenticationToken ( null , password , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: No username." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: No username: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getAuthenticationToken ( "blah" , password , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: Invalid username." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: Invalid username: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getAuthenticationToken ( username , null , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: No password." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: No password: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getAuthenticationToken ( username , "blah" , Controller . CLIENT ) ; throw new IllegalStateException ( "Failed: Invalid password." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . AUTHENTICATION_FAILED . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: Invalid password: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getAuthenticationToken ( username , password , null ) ; throw new IllegalStateException ( "Failed: No client." ) ; } catch ( RequestErrorException e ) { if ( ! ErrorCode . SERVER_INVALID_CLIENT . equals ( e . getErrorCode ( ) ) ) { throw new IllegalStateException ( "Failed: No client: " + ErrorCode . AUTHENTICATION_FAILED , e ) ; } } try { api . getAuthenticationToken ( username , password , Controller . CLIENT ) ; } catch ( RequestErrorException e ) { throw new IllegalStateException ( "Failed: Valid request." , e ) ; } }
Tests the different possibilities for getting an authentication token.
Tests the different possibilities for getting an authentication token .
// No username. // Invalid username. // No password // Invalid password // No client. // This request should be valid.