@Test public void testGetValidationResult() throws Exception { Properties properties = new Properties(); properties.put("p1", "v1"); Configuration ambariConfig = new Configuration(properties); ViewConfig config = ViewConfigTest.getConfig(xml_valid_instance); ViewEntity viewEntity = ViewRegistryTest.getViewEntity(config, ambariConfig, getClass().getClassLoader(), ""); ViewInstanceEntity viewInstanceEntity = ViewRegistryTest.getViewInstanceEntity(viewEntity, config.getInstances().get(0)); ViewEntityTest.TestValidator validator = new ViewEntityTest.TestValidator(); validator.result = new ValidationResultImpl(true, "detail"); viewEntity.setValidator(validator); InstanceValidationResultImpl result = viewInstanceEntity.getValidationResult(viewEntity, Validator.ValidationContext.PRE_CREATE); Map<String, ValidationResult> propertyResults = result.getPropertyResults(); junit.framework.Assert.assertEquals(2, propertyResults.size()); junit.framework.Assert.assertTrue(propertyResults.containsKey("p1")); junit.framework.Assert.assertTrue(propertyResults.containsKey("p2")); junit.framework.Assert.assertTrue(propertyResults.get("p1").isValid()); junit.framework.Assert.assertTrue(propertyResults.get("p2").isValid()); }
public InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context) throws IllegalStateException { Map<String, ValidationResult> propertyResults = new HashMap<String, ValidationResult>(); if (context.equals(Validator.ValidationContext.PRE_CREATE) || context.equals(Validator.ValidationContext.PRE_UPDATE)) { Set<String> requiredParameterNames = new HashSet<String>(); for (ViewParameterEntity parameter : viewEntity.getParameters()) { if (parameter.isRequired()) { if (parameter.getClusterConfig()== null) { requiredParameterNames.add(parameter.getName()); } } } Map<String, String> propertyMap = getPropertyMap(); for (Map.Entry<String, String> entry : propertyMap.entrySet()) { if (entry.getValue() != null) { requiredParameterNames.remove(entry.getKey()); } } for (String requiredParameterName : requiredParameterNames) { propertyResults.put(requiredParameterName, new ValidationResultImpl(false, "No property values exist for the required parameter " + requiredParameterName + ".")); } } ValidationResult instanceResult = null; Validator validator = viewEntity.getValidator(); if (validator != null) { instanceResult = validator.validateInstance(this, context); for ( String property : getPropertyMap().keySet()) { if (!propertyResults.containsKey(property)) { propertyResults.put(property, ValidationResultImpl.create(validator.validateProperty(property, this, context))); } } } return new InstanceValidationResultImpl(ValidationResultImpl.create(instanceResult), propertyResults); }
ViewInstanceEntity implements ViewInstanceDefinition { public InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context) throws IllegalStateException { Map<String, ValidationResult> propertyResults = new HashMap<String, ValidationResult>(); if (context.equals(Validator.ValidationContext.PRE_CREATE) || context.equals(Validator.ValidationContext.PRE_UPDATE)) { Set<String> requiredParameterNames = new HashSet<String>(); for (ViewParameterEntity parameter : viewEntity.getParameters()) { if (parameter.isRequired()) { if (parameter.getClusterConfig()== null) { requiredParameterNames.add(parameter.getName()); } } } Map<String, String> propertyMap = getPropertyMap(); for (Map.Entry<String, String> entry : propertyMap.entrySet()) { if (entry.getValue() != null) { requiredParameterNames.remove(entry.getKey()); } } for (String requiredParameterName : requiredParameterNames) { propertyResults.put(requiredParameterName, new ValidationResultImpl(false, "No property values exist for the required parameter " + requiredParameterName + ".")); } } ValidationResult instanceResult = null; Validator validator = viewEntity.getValidator(); if (validator != null) { instanceResult = validator.validateInstance(this, context); for ( String property : getPropertyMap().keySet()) { if (!propertyResults.containsKey(property)) { propertyResults.put(property, ValidationResultImpl.create(validator.validateProperty(property, this, context))); } } } return new InstanceValidationResultImpl(ValidationResultImpl.create(instanceResult), propertyResults); } }
ViewInstanceEntity implements ViewInstanceDefinition { public InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context) throws IllegalStateException { Map<String, ValidationResult> propertyResults = new HashMap<String, ValidationResult>(); if (context.equals(Validator.ValidationContext.PRE_CREATE) || context.equals(Validator.ValidationContext.PRE_UPDATE)) { Set<String> requiredParameterNames = new HashSet<String>(); for (ViewParameterEntity parameter : viewEntity.getParameters()) { if (parameter.isRequired()) { if (parameter.getClusterConfig()== null) { requiredParameterNames.add(parameter.getName()); } } } Map<String, String> propertyMap = getPropertyMap(); for (Map.Entry<String, String> entry : propertyMap.entrySet()) { if (entry.getValue() != null) { requiredParameterNames.remove(entry.getKey()); } } for (String requiredParameterName : requiredParameterNames) { propertyResults.put(requiredParameterName, new ValidationResultImpl(false, "No property values exist for the required parameter " + requiredParameterName + ".")); } } ValidationResult instanceResult = null; Validator validator = viewEntity.getValidator(); if (validator != null) { instanceResult = validator.validateInstance(this, context); for ( String property : getPropertyMap().keySet()) { if (!propertyResults.containsKey(property)) { propertyResults.put(property, ValidationResultImpl.create(validator.validateProperty(property, this, context))); } } } return new InstanceValidationResultImpl(ValidationResultImpl.create(instanceResult), propertyResults); } ViewInstanceEntity();  ViewInstanceEntity(ViewEntity view, InstanceConfig instanceConfig);  ViewInstanceEntity(ViewEntity view, String name);  ViewInstanceEntity(ViewEntity view, String name, String label); }
ViewInstanceEntity implements ViewInstanceDefinition { public InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context) throws IllegalStateException { Map<String, ValidationResult> propertyResults = new HashMap<String, ValidationResult>(); if (context.equals(Validator.ValidationContext.PRE_CREATE) || context.equals(Validator.ValidationContext.PRE_UPDATE)) { Set<String> requiredParameterNames = new HashSet<String>(); for (ViewParameterEntity parameter : viewEntity.getParameters()) { if (parameter.isRequired()) { if (parameter.getClusterConfig()== null) { requiredParameterNames.add(parameter.getName()); } } } Map<String, String> propertyMap = getPropertyMap(); for (Map.Entry<String, String> entry : propertyMap.entrySet()) { if (entry.getValue() != null) { requiredParameterNames.remove(entry.getKey()); } } for (String requiredParameterName : requiredParameterNames) { propertyResults.put(requiredParameterName, new ValidationResultImpl(false, "No property values exist for the required parameter " + requiredParameterName + ".")); } } ValidationResult instanceResult = null; Validator validator = viewEntity.getValidator(); if (validator != null) { instanceResult = validator.validateInstance(this, context); for ( String property : getPropertyMap().keySet()) { if (!propertyResults.containsKey(property)) { propertyResults.put(property, ValidationResultImpl.create(validator.validateProperty(property, this, context))); } } } return new InstanceValidationResultImpl(ValidationResultImpl.create(instanceResult), propertyResults); } ViewInstanceEntity();  ViewInstanceEntity(ViewEntity view, InstanceConfig instanceConfig);  ViewInstanceEntity(ViewEntity view, String name);  ViewInstanceEntity(ViewEntity view, String name, String label); @Override String getInstanceName(); @Override String getViewName(); @Override Map<String, String> getPropertyMap(); @Override Map<String, String> getInstanceDataMap(); @Override ViewDefinition getViewDefinition(); @Override String getLabel(); @Override String getDescription(); @Override Long getClusterHandle(); @Override boolean isVisible(); Long getViewInstanceId(); void setViewInstanceId(Long viewInstanceId); void setViewName(String viewName); String getName(); void setName(String name); void setLabel(String label); void setDescription(String description); void setClusterHandle(Long clusterHandle); @Override ClusterType getClusterType(); void setClusterType(ClusterType clusterType); void setVisible(boolean visible); String getIcon(); void setIcon(String icon); String getIcon64(); void setIcon64(String icon64); boolean isXmlDriven(); void setXmlDriven(boolean xmlDriven); boolean alterNames(); void setAlterNames(boolean alterNames); Collection<ViewInstancePropertyEntity> getProperties(); void putProperty(String key, String value); void removeProperty(String key); ViewInstancePropertyEntity getProperty(String key); void setProperties(Collection<ViewInstancePropertyEntity> properties); Collection<ViewInstanceDataEntity> getData(); void setData(Collection<ViewInstanceDataEntity> data); Collection<ViewEntityEntity> getEntities(); void setEntities(Collection<ViewEntityEntity> entities); void putInstanceData(String key, String value); void removeInstanceData(String key); ViewInstanceDataEntity getInstanceData(String key); ViewEntity getViewEntity(); void setViewEntity(ViewEntity view); InstanceConfig getConfiguration(); void addResourceProvider(Resource.Type type, ResourceProvider provider); ResourceProvider getResourceProvider(Resource.Type type); ResourceProvider getResourceProvider(String type); void addService(String pluralName, Object service); Object getService(String pluralName); String getContextPath(); static String getContextPath(String viewName, String version, String viewInstanceName); String getUsername(); ResourceEntity getResource(); void setResource(ResourceEntity resource); ViewDataMigrator getDataMigrator(ViewDataMigrationContext dataMigrationContext); void validate(ViewEntity viewEntity, Validator.ValidationContext context); InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context); String getCurrentUserName(); @Override boolean equals(Object o); @Override int hashCode(); ViewURLEntity getViewUrl(); void setViewUrl(ViewURLEntity viewUrl); void clearUrl(); }
ViewInstanceEntity implements ViewInstanceDefinition { public InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context) throws IllegalStateException { Map<String, ValidationResult> propertyResults = new HashMap<String, ValidationResult>(); if (context.equals(Validator.ValidationContext.PRE_CREATE) || context.equals(Validator.ValidationContext.PRE_UPDATE)) { Set<String> requiredParameterNames = new HashSet<String>(); for (ViewParameterEntity parameter : viewEntity.getParameters()) { if (parameter.isRequired()) { if (parameter.getClusterConfig()== null) { requiredParameterNames.add(parameter.getName()); } } } Map<String, String> propertyMap = getPropertyMap(); for (Map.Entry<String, String> entry : propertyMap.entrySet()) { if (entry.getValue() != null) { requiredParameterNames.remove(entry.getKey()); } } for (String requiredParameterName : requiredParameterNames) { propertyResults.put(requiredParameterName, new ValidationResultImpl(false, "No property values exist for the required parameter " + requiredParameterName + ".")); } } ValidationResult instanceResult = null; Validator validator = viewEntity.getValidator(); if (validator != null) { instanceResult = validator.validateInstance(this, context); for ( String property : getPropertyMap().keySet()) { if (!propertyResults.containsKey(property)) { propertyResults.put(property, ValidationResultImpl.create(validator.validateProperty(property, this, context))); } } } return new InstanceValidationResultImpl(ValidationResultImpl.create(instanceResult), propertyResults); } ViewInstanceEntity();  ViewInstanceEntity(ViewEntity view, InstanceConfig instanceConfig);  ViewInstanceEntity(ViewEntity view, String name);  ViewInstanceEntity(ViewEntity view, String name, String label); @Override String getInstanceName(); @Override String getViewName(); @Override Map<String, String> getPropertyMap(); @Override Map<String, String> getInstanceDataMap(); @Override ViewDefinition getViewDefinition(); @Override String getLabel(); @Override String getDescription(); @Override Long getClusterHandle(); @Override boolean isVisible(); Long getViewInstanceId(); void setViewInstanceId(Long viewInstanceId); void setViewName(String viewName); String getName(); void setName(String name); void setLabel(String label); void setDescription(String description); void setClusterHandle(Long clusterHandle); @Override ClusterType getClusterType(); void setClusterType(ClusterType clusterType); void setVisible(boolean visible); String getIcon(); void setIcon(String icon); String getIcon64(); void setIcon64(String icon64); boolean isXmlDriven(); void setXmlDriven(boolean xmlDriven); boolean alterNames(); void setAlterNames(boolean alterNames); Collection<ViewInstancePropertyEntity> getProperties(); void putProperty(String key, String value); void removeProperty(String key); ViewInstancePropertyEntity getProperty(String key); void setProperties(Collection<ViewInstancePropertyEntity> properties); Collection<ViewInstanceDataEntity> getData(); void setData(Collection<ViewInstanceDataEntity> data); Collection<ViewEntityEntity> getEntities(); void setEntities(Collection<ViewEntityEntity> entities); void putInstanceData(String key, String value); void removeInstanceData(String key); ViewInstanceDataEntity getInstanceData(String key); ViewEntity getViewEntity(); void setViewEntity(ViewEntity view); InstanceConfig getConfiguration(); void addResourceProvider(Resource.Type type, ResourceProvider provider); ResourceProvider getResourceProvider(Resource.Type type); ResourceProvider getResourceProvider(String type); void addService(String pluralName, Object service); Object getService(String pluralName); String getContextPath(); static String getContextPath(String viewName, String version, String viewInstanceName); String getUsername(); ResourceEntity getResource(); void setResource(ResourceEntity resource); ViewDataMigrator getDataMigrator(ViewDataMigrationContext dataMigrationContext); void validate(ViewEntity viewEntity, Validator.ValidationContext context); InstanceValidationResultImpl getValidationResult(ViewEntity viewEntity, Validator.ValidationContext context); String getCurrentUserName(); @Override boolean equals(Object o); @Override int hashCode(); ViewURLEntity getViewUrl(); void setViewUrl(ViewURLEntity viewUrl); void clearUrl();  }