PropertyValidator implements Validator { @Override public ValidationResult validateProperty(String property, ViewInstanceDefinition viewInstanceDefinition, ValidationContext validationContext) { ClusterType clusterType = viewInstanceDefinition.getClusterType(); if (clusterType == ClusterType.LOCAL_AMBARI || clusterType == ClusterType.REMOTE_AMBARI) { return ValidationResult.SUCCESS; } if (property.equals(WEBHDFS_URL)) { String webhdfsUrl = viewInstanceDefinition.getPropertyMap().get(WEBHDFS_URL); if (!ValidatorUtils.validateHdfsURL(webhdfsUrl)) { LOG.error("Invalid webhdfs.url = {}", webhdfsUrl); return new InvalidPropertyValidationResult(false, "Must be valid URL"); } } return ValidationResult.SUCCESS; }  @Override ValidationResult validateInstance(ViewInstanceDefinition viewInstanceDefinition, ValidationContext validationContext); @Override ValidationResult validateProperty(String property, ViewInstanceDefinition viewInstanceDefinition, ValidationContext validationContext); static final String WEBHDFS_URL; }
@Test public void testValidatePropertyWithValidWebhdfsURI(){ Map<String,String> propertyMap = new HashMap<String, String>(); propertyMap.put(PropertyValidator.WEBHDFS_URL,"webhdfs: ViewInstanceDefinition instanceDefinition = getInstanceDef(propertyMap); ValidationResult result = new PropertyValidator().validateProperty(PropertyValidator.WEBHDFS_URL,instanceDefinition,null); assertEquals(result, ValidationResult.SUCCESS); assertEquals(result.isValid(),true); }
@Test public void testValidatePropertyWithValidHdfsURI(){ Map<String,String> propertyMap = new HashMap<String, String>(); propertyMap.put(PropertyValidator.WEBHDFS_URL,"hdfs: ViewInstanceDefinition instanceDefinition = getInstanceDef(propertyMap); ValidationResult result = new PropertyValidator().validateProperty(PropertyValidator.WEBHDFS_URL,instanceDefinition,null); assertEquals(result, ValidationResult.SUCCESS); assertEquals(result.isValid(),true); }
@Test public void testValidatePropertyWithLocalFileURI(){ Map<String,String> propertyMap = new HashMap<String, String>(); propertyMap.put(PropertyValidator.WEBHDFS_URL,"file: ViewInstanceDefinition instanceDefinition = getInstanceDef(propertyMap); ValidationResult result = new PropertyValidator().validateProperty(PropertyValidator.WEBHDFS_URL,instanceDefinition,null); assertEquals(result.getClass(), PropertyValidator.InvalidPropertyValidationResult.class); assertEquals(result.isValid(),false); assertEquals(result.getDetail(),"Must be valid URL"); }