test/org/ohmage/validator/CampaignValidatorsTest.java
@Test
	public void testValidateUploadedJson() {
		try {
			for(String emptyValue : ParameterSets.getEmptyValues()) {
				Assert.assertNull(CampaignValidators.validateUploadedJson(emptyValue));
			}

			try {
				CampaignValidators.validateUploadedJson("Invalid value.");
				fail("The uploaded JSON was invalid.");
			}
			catch(ValidationException e) {
				// Passed.
			}
			
			JSONArray jsonArray = new JSONArray();
			
			try {
				CampaignValidators.validateUploadedJson(jsonArray.toString());
			}
			catch(ValidationException e) {
				fail("The empty JSONArray was rejected: " + e.getMessage());
			}
			
			jsonArray.put(new JSONObject());
			
			try {
				CampaignValidators.validateUploadedJson(jsonArray.toString());
			}
			catch(ValidationException e) {
				fail("The JSONArray with one JSONObject was rejected: " + e.getMessage());
			}
			
			jsonArray.put(new JSONObject());
			
			try {
				CampaignValidators.validateUploadedJson(jsonArray.toString());
			}
			catch(ValidationException e) {
				fail("The JSONArray with two JSONObjects was rejected: " + e.getMessage());
			}
		}
		catch(ValidationException e) {
			fail("A validation exception was thrown: " + e.getMessage());
		}
	}
/**
	 * Test the uploaded JSON validator.
	 */
Test the uploaded JSON validator.
Test the uploaded JSON validator .
@Test
	public void testValidateUploadedJson() {
		try {
			for(String emptyValue : ParameterSets.getEmptyValues()) {
				Assert.assertNull(CampaignValidators.validateUploadedJson(emptyValue));
			}
			try {
				CampaignValidators.validateUploadedJson("Invalid value.");
				fail("The uploaded JSON was invalid.");
			}
			catch(ValidationException e) {
			}
			JSONArray jsonArray = new JSONArray();
			try {
				CampaignValidators.validateUploadedJson(jsonArray.toString());
			}
			catch(ValidationException e) {
				fail("The empty JSONArray was rejected: " + e.getMessage());
			}
			jsonArray.put(new JSONObject());
			try {
				CampaignValidators.validateUploadedJson(jsonArray.toString());
			}
			catch(ValidationException e) {
				fail("The JSONArray with one JSONObject was rejected: " + e.getMessage());
			}
			jsonArray.put(new JSONObject());
			try {
				CampaignValidators.validateUploadedJson(jsonArray.toString());
			}
			catch(ValidationException e) {
				fail("The JSONArray with two JSONObjects was rejected: " + e.getMessage());
			}
		}
		catch(ValidationException e) {
			fail("A validation exception was thrown: " + e.getMessage());
		}
	}
@ Test public void testValidateUploadedJson ( ) { try { for ( String emptyValue : ParameterSets . getEmptyValues ( ) ) { Assert . assertNull ( CampaignValidators . validateUploadedJson ( emptyValue ) ) ; } try { CampaignValidators . validateUploadedJson ( "Invalid value." ) ; fail ( "The uploaded JSON was invalid." ) ; } catch ( ValidationException e ) { } JSONArray jsonArray = new JSONArray ( ) ; try { CampaignValidators . validateUploadedJson ( jsonArray . toString ( ) ) ; } catch ( ValidationException e ) { fail ( "The empty JSONArray was rejected: " + e . getMessage ( ) ) ; } jsonArray . put ( new JSONObject ( ) ) ; try { CampaignValidators . validateUploadedJson ( jsonArray . toString ( ) ) ; } catch ( ValidationException e ) { fail ( "The JSONArray with one JSONObject was rejected: " + e . getMessage ( ) ) ; } jsonArray . put ( new JSONObject ( ) ) ; try { CampaignValidators . validateUploadedJson ( jsonArray . toString ( ) ) ; } catch ( ValidationException e ) { fail ( "The JSONArray with two JSONObjects was rejected: " + e . getMessage ( ) ) ; } } catch ( ValidationException e ) { fail ( "A validation exception was thrown: " + e . getMessage ( ) ) ; } }
Test the uploaded JSON validator.
Test the uploaded JSON validator .
// Passed.