test/org/ohmage/validator/SurveyResponseValidatorsTest.java
@Test
	public void testValidateUsernames() {
		try {
			for(String emptyValue : ParameterSets.getEmptyValues()) {
				Assert.assertNull(SurveyResponseValidators.validateUsernames(emptyValue));
			}

			for(String validUsernameList : ParameterSets.getValidUsernameLists()) {
				try {
					SurveyResponseValidators.validateUsernames(validUsernameList);
				}
				catch(ValidationException e) {
					fail("A validation exception was thrown for a valid username list: " + validUsernameList);
				}
				
				String validUsernameListWithAll = validUsernameList + InputKeys.LIST_ITEM_SEPARATOR + SurveyResponseRequest.URN_SPECIAL_ALL;
				try {
					Set<String> usernameList = SurveyResponseValidators.validateUsernames(validUsernameListWithAll);
					if(usernameList.size() == 1) {
						if(! SurveyResponseRequest.URN_SPECIAL_ALL.equals(usernameList.iterator().next())) {
							fail("The username list contained '" + 
									SurveyResponseRequest.URN_SPECIAL_ALL +
									"', and the validator only returned one element, but it was not the expected element: " + 
									usernameList.iterator().next());
						}
					}
					else {
						fail("The username list contained '" + SurveyResponseRequest.URN_SPECIAL_ALL + "' but returned more than one result: " + usernameList);
					}
				}
				catch(ValidationException e) {
					fail("A validation exception was thrown for a valid username list: " + validUsernameListWithAll);
				}

				String allWithValidUsernameList = SurveyResponseRequest.URN_SPECIAL_ALL + InputKeys.LIST_ITEM_SEPARATOR + validUsernameList;
				try {
					Set<String> usernameList = SurveyResponseValidators.validateUsernames(allWithValidUsernameList);
					if(usernameList.size() == 1) {
						if(! SurveyResponseRequest.URN_SPECIAL_ALL.equals(usernameList.iterator().next())) {
							fail("The username list contained '" + 
									SurveyResponseRequest.URN_SPECIAL_ALL +
									"', and the validator only returned one element, but it was not the expected element: " + 
									usernameList.iterator().next());
						}
					}
					else {
						fail("The username list contained '" + SurveyResponseRequest.URN_SPECIAL_ALL + "' but returned more than one result: " + usernameList);
					}
				}
				catch(ValidationException e) {
					fail("A validation exception was thrown for a valid username list: " + allWithValidUsernameList);
				}
			}
			
			for(String invalidUsernameList : ParameterSets.getInvalidUsernameLists()) {
				try {
					SurveyResponseValidators.validateUsernames(invalidUsernameList);
					fail("An invalid username list passed validation: " + invalidUsernameList);
				}
				catch(ValidationException e) {
					// Passed.
				}
			}
		}
		catch(ValidationException e) {
			fail("A validation exception was thrown: " + e.getMessage());
		}
	}
/**
	 * Tests the username list validator.
	 */
Tests the username list validator.
Tests the username list validator .
@Test
	public void testValidateUsernames() {
		try {
			for(String emptyValue : ParameterSets.getEmptyValues()) {
				Assert.assertNull(SurveyResponseValidators.validateUsernames(emptyValue));
			}
			for(String validUsernameList : ParameterSets.getValidUsernameLists()) {
				try {
					SurveyResponseValidators.validateUsernames(validUsernameList);
				}
				catch(ValidationException e) {
					fail("A validation exception was thrown for a valid username list: " + validUsernameList);
				}
				String validUsernameListWithAll = validUsernameList + InputKeys.LIST_ITEM_SEPARATOR + SurveyResponseRequest.URN_SPECIAL_ALL;
				try {
					Set<String> usernameList = SurveyResponseValidators.validateUsernames(validUsernameListWithAll);
					if(usernameList.size() == 1) {
						if(! SurveyResponseRequest.URN_SPECIAL_ALL.equals(usernameList.iterator().next())) {
							fail("The username list contained '" + 
									SurveyResponseRequest.URN_SPECIAL_ALL +
									"', and the validator only returned one element, but it was not the expected element: " + 
									usernameList.iterator().next());
						}
					}
					else {
						fail("The username list contained '" + SurveyResponseRequest.URN_SPECIAL_ALL + "' but returned more than one result: " + usernameList);
					}
				}
				catch(ValidationException e) {
					fail("A validation exception was thrown for a valid username list: " + validUsernameListWithAll);
				}
				String allWithValidUsernameList = SurveyResponseRequest.URN_SPECIAL_ALL + InputKeys.LIST_ITEM_SEPARATOR + validUsernameList;
				try {
					Set<String> usernameList = SurveyResponseValidators.validateUsernames(allWithValidUsernameList);
					if(usernameList.size() == 1) {
						if(! SurveyResponseRequest.URN_SPECIAL_ALL.equals(usernameList.iterator().next())) {
							fail("The username list contained '" + 
									SurveyResponseRequest.URN_SPECIAL_ALL +
									"', and the validator only returned one element, but it was not the expected element: " + 
									usernameList.iterator().next());
						}
					}
					else {
						fail("The username list contained '" + SurveyResponseRequest.URN_SPECIAL_ALL + "' but returned more than one result: " + usernameList);
					}
				}
				catch(ValidationException e) {
					fail("A validation exception was thrown for a valid username list: " + allWithValidUsernameList);
				}
			}
			for(String invalidUsernameList : ParameterSets.getInvalidUsernameLists()) {
				try {
					SurveyResponseValidators.validateUsernames(invalidUsernameList);
					fail("An invalid username list passed validation: " + invalidUsernameList);
				}
				catch(ValidationException e) {
				}
			}
		}
		catch(ValidationException e) {
			fail("A validation exception was thrown: " + e.getMessage());
		}
	}
@ Test public void testValidateUsernames ( ) { try { for ( String emptyValue : ParameterSets . getEmptyValues ( ) ) { Assert . assertNull ( SurveyResponseValidators . validateUsernames ( emptyValue ) ) ; } for ( String validUsernameList : ParameterSets . getValidUsernameLists ( ) ) { try { SurveyResponseValidators . validateUsernames ( validUsernameList ) ; } catch ( ValidationException e ) { fail ( "A validation exception was thrown for a valid username list: " + validUsernameList ) ; } String validUsernameListWithAll = validUsernameList + InputKeys . LIST_ITEM_SEPARATOR + SurveyResponseRequest . URN_SPECIAL_ALL ; try { Set < String > usernameList = SurveyResponseValidators . validateUsernames ( validUsernameListWithAll ) ; if ( usernameList . size ( ) == 1 ) { if ( ! SurveyResponseRequest . URN_SPECIAL_ALL . equals ( usernameList . iterator ( ) . next ( ) ) ) { fail ( "The username list contained '" + SurveyResponseRequest . URN_SPECIAL_ALL + "', and the validator only returned one element, but it was not the expected element: " + usernameList . iterator ( ) . next ( ) ) ; } } else { fail ( "The username list contained '" + SurveyResponseRequest . URN_SPECIAL_ALL + "' but returned more than one result: " + usernameList ) ; } } catch ( ValidationException e ) { fail ( "A validation exception was thrown for a valid username list: " + validUsernameListWithAll ) ; } String allWithValidUsernameList = SurveyResponseRequest . URN_SPECIAL_ALL + InputKeys . LIST_ITEM_SEPARATOR + validUsernameList ; try { Set < String > usernameList = SurveyResponseValidators . validateUsernames ( allWithValidUsernameList ) ; if ( usernameList . size ( ) == 1 ) { if ( ! SurveyResponseRequest . URN_SPECIAL_ALL . equals ( usernameList . iterator ( ) . next ( ) ) ) { fail ( "The username list contained '" + SurveyResponseRequest . URN_SPECIAL_ALL + "', and the validator only returned one element, but it was not the expected element: " + usernameList . iterator ( ) . next ( ) ) ; } } else { fail ( "The username list contained '" + SurveyResponseRequest . URN_SPECIAL_ALL + "' but returned more than one result: " + usernameList ) ; } } catch ( ValidationException e ) { fail ( "A validation exception was thrown for a valid username list: " + allWithValidUsernameList ) ; } } for ( String invalidUsernameList : ParameterSets . getInvalidUsernameLists ( ) ) { try { SurveyResponseValidators . validateUsernames ( invalidUsernameList ) ; fail ( "An invalid username list passed validation: " + invalidUsernameList ) ; } catch ( ValidationException e ) { } } } catch ( ValidationException e ) { fail ( "A validation exception was thrown: " + e . getMessage ( ) ) ; } }
Tests the username list validator.
Tests the username list validator .
// Passed.