### Question:
BackupRestoreV4RequestValidator { public ValidationResult validate(Stack stack, String location, String backupId) { ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder(); String cloudPlatform = stack.cloudPlatform(); if (Strings.isNullOrEmpty(backupId)) { resultBuilder.error("Parameter backupId required"); } if (Strings.isNullOrEmpty(location)) { resultBuilder.error("Parameter backupLocation required"); } else { validateCloudLocationScheme(cloudPlatform, location, resultBuilder); } return resultBuilder.build(); }  ValidationResult validate(Stack stack, String location, String backupId);  }### Answer:
@Test public void testAWSSuccessfulValidation() { Stack stack = getStack(CloudPlatform.AWS.name()); ValidationResult validationResult = requestValidator.validate(stack, "s3: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "s3a: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "s3n: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "S3: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "S3a: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "S3n: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, '/' + LOCATION, BACKUP_ID); assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, LOCATION, BACKUP_ID); assertFalse(validationResult.hasError()); }
@Test public void testAzureSuccessfulValidation() { Stack stack = getStack(CloudPlatform.AZURE.name()); ValidationResult validationResult = requestValidator.validate(stack, "abfs: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "abfss: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "ABFS: assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, "ABFSS: assertFalse(validationResult.hasError()); assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, '/' + LOCATION, BACKUP_ID); assertFalse(validationResult.hasError()); validationResult = requestValidator.validate(stack, LOCATION, BACKUP_ID); assertFalse(validationResult.hasError()); }
@Test public void testAWSWrongScheme() { Stack stack = getStack(CloudPlatform.AWS.name()); String backupLocation = "abfs: ValidationResult validationResult = requestValidator.validate(stack, backupLocation, BACKUP_ID); assert validationResult.hasError(); assertEquals("1. Incorrect URL scheme for AWS cloud platform: " + backupLocation, validationResult.getFormattedErrors()); }
@Test public void testAzureWrongScheme() { Stack stack = getStack(CloudPlatform.AZURE.name()); String backupLocation = "s3: ValidationResult validationResult = requestValidator.validate(stack, backupLocation, BACKUP_ID); assert validationResult.hasError(); assertEquals("1. Incorrect URL scheme for Azure cloud platform: " + backupLocation, validationResult.getFormattedErrors()); }
@Test public void testUnsupportedCloudPlatform() { Stack stack = getStack(CloudPlatform.YARN.name()); ValidationResult validationResult = requestValidator.validate(stack, LOCATION, BACKUP_ID); assert validationResult.hasError(); assertEquals("1. Cloud platform YARN not supported for backup/restore", validationResult.getFormattedErrors()); }
@Test public void testMissingBackupId() { Stack stack = getStack(CloudPlatform.AWS.name()); ValidationResult validationResult = requestValidator.validate(stack, LOCATION, null); assert validationResult.hasError(); assertEquals("1. Parameter backupId required", validationResult.getFormattedErrors()); }
@Test public void testMissingBackupLocation() { Stack stack = getStack(CloudPlatform.AWS.name()); ValidationResult validationResult = requestValidator.validate(stack, null, BACKUP_ID); assert validationResult.hasError(); assertEquals("1. Parameter backupLocation required", validationResult.getFormattedErrors()); }