test/org/ohmage/validator/SurveyResponseValidatorsTest.java
@Test
	public void testValidateColumnList() {
		try {
			for(String emptyValue : ParameterSets.getEmptyValues()) {
				Assert.assertNull(SurveyResponseValidators.validateColumnList(emptyValue));
			}
			
			try {
				SurveyResponseValidators.validateColumnList("Invalid value.");
				fail("The column list was invalid.");
			}
			catch(ValidationException e) {
				// Passed.
			}
			
			try {
				Set<SurveyResponse.ColumnKey> columnList = 
					SurveyResponseValidators.validateColumnList(InputKeys.LIST_ITEM_SEPARATOR);
				
				if(columnList.size() != 0) {
					fail("The column list was not empty: " + columnList);
				}
			}
			catch(ValidationException e) {
				fail("A list containing only a '" + InputKeys.LIST_ITEM_SEPARATOR + "' threw an exception: " + e.getMessage());
			}
			
			try {
				Set<SurveyResponse.ColumnKey> columnList = 
					SurveyResponseValidators.validateColumnList(InputKeys.LIST_ITEM_SEPARATOR + InputKeys.LIST_ITEM_SEPARATOR);
				
				if(columnList.size() != 0) {
					fail("The column list was not empty: " + columnList);
				}
			}
			catch(ValidationException e) {
				fail("A list containing two '" + InputKeys.LIST_ITEM_SEPARATOR + "'s threw an exception: " + e.getMessage());
			}
			
			try {
				Set<SurveyResponse.ColumnKey> columnList = 
					SurveyResponseValidators.validateColumnList(InputKeys.LIST_ITEM_SEPARATOR + InputKeys.LIST_ITEM_SEPARATOR + InputKeys.LIST_ITEM_SEPARATOR);
				
				if(columnList.size() != 0) {
					fail("The column list was not empty: " + columnList);
				}
			}
			catch(ValidationException e) {
				fail("A list containing three '" + InputKeys.LIST_ITEM_SEPARATOR + "'s threw an exception: " + e.getMessage());
			}

			int columnKeysAdded = 0;
			StringBuilder columnListBuilder = new StringBuilder();
			for(SurveyResponse.ColumnKey columnKey : SurveyResponse.ColumnKey.values()) {
				Set<SurveyResponse.ColumnKey> columnList =
					SurveyResponseValidators.validateColumnList(columnKey.toString());
				
				if(columnList.size() != 1) {
					fail("The column key was not returned: " + columnList.size());
				}
				else {
					if(! columnKey.equals(columnList.iterator().next())) {
						fail("The column key returned was not the one we gave: " + columnList.iterator().next().toString());
					}
				}
				
				columnListBuilder.append(columnKey + InputKeys.LIST_ITEM_SEPARATOR);
				columnKeysAdded++;
				columnList = SurveyResponseValidators.validateColumnList(columnListBuilder.toString());
				if(columnList.size() != columnKeysAdded) {
					fail("The list of column keys returned doesn't match the number we have added.");
				}
			}
		}
		catch(ValidationException e) {
			fail("A validation exception was thrown: " + e.getMessage());
		}
	}
/**
	 * Tests the column list validator.
	 */
Tests the column list validator.
Tests the column list validator .
@Test
	public void testValidateColumnList() {
		try {
			for(String emptyValue : ParameterSets.getEmptyValues()) {
				Assert.assertNull(SurveyResponseValidators.validateColumnList(emptyValue));
			}
			try {
				SurveyResponseValidators.validateColumnList("Invalid value.");
				fail("The column list was invalid.");
			}
			catch(ValidationException e) {
			}
			try {
				Set<SurveyResponse.ColumnKey> columnList = 
					SurveyResponseValidators.validateColumnList(InputKeys.LIST_ITEM_SEPARATOR);
				if(columnList.size() != 0) {
					fail("The column list was not empty: " + columnList);
				}
			}
			catch(ValidationException e) {
				fail("A list containing only a '" + InputKeys.LIST_ITEM_SEPARATOR + "' threw an exception: " + e.getMessage());
			}
			try {
				Set<SurveyResponse.ColumnKey> columnList = 
					SurveyResponseValidators.validateColumnList(InputKeys.LIST_ITEM_SEPARATOR + InputKeys.LIST_ITEM_SEPARATOR);
				if(columnList.size() != 0) {
					fail("The column list was not empty: " + columnList);
				}
			}
			catch(ValidationException e) {
				fail("A list containing two '" + InputKeys.LIST_ITEM_SEPARATOR + "'s threw an exception: " + e.getMessage());
			}
			try {
				Set<SurveyResponse.ColumnKey> columnList = 
					SurveyResponseValidators.validateColumnList(InputKeys.LIST_ITEM_SEPARATOR + InputKeys.LIST_ITEM_SEPARATOR + InputKeys.LIST_ITEM_SEPARATOR);
				if(columnList.size() != 0) {
					fail("The column list was not empty: " + columnList);
				}
			}
			catch(ValidationException e) {
				fail("A list containing three '" + InputKeys.LIST_ITEM_SEPARATOR + "'s threw an exception: " + e.getMessage());
			}
			int columnKeysAdded = 0;
			StringBuilder columnListBuilder = new StringBuilder();
			for(SurveyResponse.ColumnKey columnKey : SurveyResponse.ColumnKey.values()) {
				Set<SurveyResponse.ColumnKey> columnList =
					SurveyResponseValidators.validateColumnList(columnKey.toString());
				if(columnList.size() != 1) {
					fail("The column key was not returned: " + columnList.size());
				}
				else {
					if(! columnKey.equals(columnList.iterator().next())) {
						fail("The column key returned was not the one we gave: " + columnList.iterator().next().toString());
					}
				}
				columnListBuilder.append(columnKey + InputKeys.LIST_ITEM_SEPARATOR);
				columnKeysAdded++;
				columnList = SurveyResponseValidators.validateColumnList(columnListBuilder.toString());
				if(columnList.size() != columnKeysAdded) {
					fail("The list of column keys returned doesn't match the number we have added.");
				}
			}
		}
		catch(ValidationException e) {
			fail("A validation exception was thrown: " + e.getMessage());
		}
	}
@ Test public void testValidateColumnList ( ) { try { for ( String emptyValue : ParameterSets . getEmptyValues ( ) ) { Assert . assertNull ( SurveyResponseValidators . validateColumnList ( emptyValue ) ) ; } try { SurveyResponseValidators . validateColumnList ( "Invalid value." ) ; fail ( "The column list was invalid." ) ; } catch ( ValidationException e ) { } try { Set < SurveyResponse . ColumnKey > columnList = SurveyResponseValidators . validateColumnList ( InputKeys . LIST_ITEM_SEPARATOR ) ; if ( columnList . size ( ) != 0 ) { fail ( "The column list was not empty: " + columnList ) ; } } catch ( ValidationException e ) { fail ( "A list containing only a '" + InputKeys . LIST_ITEM_SEPARATOR + "' threw an exception: " + e . getMessage ( ) ) ; } try { Set < SurveyResponse . ColumnKey > columnList = SurveyResponseValidators . validateColumnList ( InputKeys . LIST_ITEM_SEPARATOR + InputKeys . LIST_ITEM_SEPARATOR ) ; if ( columnList . size ( ) != 0 ) { fail ( "The column list was not empty: " + columnList ) ; } } catch ( ValidationException e ) { fail ( "A list containing two '" + InputKeys . LIST_ITEM_SEPARATOR + "'s threw an exception: " + e . getMessage ( ) ) ; } try { Set < SurveyResponse . ColumnKey > columnList = SurveyResponseValidators . validateColumnList ( InputKeys . LIST_ITEM_SEPARATOR + InputKeys . LIST_ITEM_SEPARATOR + InputKeys . LIST_ITEM_SEPARATOR ) ; if ( columnList . size ( ) != 0 ) { fail ( "The column list was not empty: " + columnList ) ; } } catch ( ValidationException e ) { fail ( "A list containing three '" + InputKeys . LIST_ITEM_SEPARATOR + "'s threw an exception: " + e . getMessage ( ) ) ; } int columnKeysAdded = 0 ; StringBuilder columnListBuilder = new StringBuilder ( ) ; for ( SurveyResponse . ColumnKey columnKey : SurveyResponse . ColumnKey . values ( ) ) { Set < SurveyResponse . ColumnKey > columnList = SurveyResponseValidators . validateColumnList ( columnKey . toString ( ) ) ; if ( columnList . size ( ) != 1 ) { fail ( "The column key was not returned: " + columnList . size ( ) ) ; } else { if ( ! columnKey . equals ( columnList . iterator ( ) . next ( ) ) ) { fail ( "The column key returned was not the one we gave: " + columnList . iterator ( ) . next ( ) . toString ( ) ) ; } } columnListBuilder . append ( columnKey + InputKeys . LIST_ITEM_SEPARATOR ) ; columnKeysAdded ++ ; columnList = SurveyResponseValidators . validateColumnList ( columnListBuilder . toString ( ) ) ; if ( columnList . size ( ) != columnKeysAdded ) { fail ( "The list of column keys returned doesn't match the number we have added." ) ; } } } catch ( ValidationException e ) { fail ( "A validation exception was thrown: " + e . getMessage ( ) ) ; } }
Tests the column list validator.
Tests the column list validator .
// Passed.