@Test public void givenPluginPackageWithDataModelButAttributeWithoutDataTypeWhenValidateThenShouldThrowException() { try { InputSource inputSource = new InputSource(Resources.getResource("plugin/sample-plugin-config-with-data-model-entity-attribute-without-datatype.xml").openStream()); PluginPackageDto pluginPackageDto = PluginPackageXmlParser.newInstance(inputSource).parsePluginPackage(); new PluginPackageDataModelDtoValidator().validate(pluginPackageDto.getPluginPackageDataModelDto()); fail("Validator should throw exception but succeed"); } catch (WecubeCoreException e) { assertThat(e.getMessage().contains("The DataType should not be empty or null")).isTrue(); } catch (SAXException | IOException | XPathExpressionException | ParserConfigurationException e) { fail("Xml should be correct without exception"); } }
public void validate(PluginPackageDataModelDto pluginPackageDataModelDto) { Set<PluginPackageEntityDto> pluginPackageEntities = pluginPackageDataModelDto.getPluginPackageEntities(); if (null != pluginPackageEntities && pluginPackageEntities.size() > 0) { pluginPackageEntities.forEach(inputEntityDto -> inputEntityDto.getAttributes().forEach(inputAttributeDto -> { if (StringUtils.isEmpty(inputAttributeDto.getDataType())) { String msg = String.format( "The DataType should not be empty or null while registering he package [%s] with version: [%s]", inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3279",msg, inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); } if ("ref" .equals(inputAttributeDto.getDataType()) && StringUtils.isEmpty(inputAttributeDto.getRefAttributeName())) { String msg = "Field [ref] should be specified when [dataType] is set to [\"ref\"]"; logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3280",msg); } })); } }
PluginPackageDataModelDtoValidator { public void validate(PluginPackageDataModelDto pluginPackageDataModelDto) { Set<PluginPackageEntityDto> pluginPackageEntities = pluginPackageDataModelDto.getPluginPackageEntities(); if (null != pluginPackageEntities && pluginPackageEntities.size() > 0) { pluginPackageEntities.forEach(inputEntityDto -> inputEntityDto.getAttributes().forEach(inputAttributeDto -> { if (StringUtils.isEmpty(inputAttributeDto.getDataType())) { String msg = String.format( "The DataType should not be empty or null while registering he package [%s] with version: [%s]", inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3279",msg, inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); } if ("ref" .equals(inputAttributeDto.getDataType()) && StringUtils.isEmpty(inputAttributeDto.getRefAttributeName())) { String msg = "Field [ref] should be specified when [dataType] is set to [\"ref\"]"; logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3280",msg); } })); } } }
PluginPackageDataModelDtoValidator { public void validate(PluginPackageDataModelDto pluginPackageDataModelDto) { Set<PluginPackageEntityDto> pluginPackageEntities = pluginPackageDataModelDto.getPluginPackageEntities(); if (null != pluginPackageEntities && pluginPackageEntities.size() > 0) { pluginPackageEntities.forEach(inputEntityDto -> inputEntityDto.getAttributes().forEach(inputAttributeDto -> { if (StringUtils.isEmpty(inputAttributeDto.getDataType())) { String msg = String.format( "The DataType should not be empty or null while registering he package [%s] with version: [%s]", inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3279",msg, inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); } if ("ref" .equals(inputAttributeDto.getDataType()) && StringUtils.isEmpty(inputAttributeDto.getRefAttributeName())) { String msg = "Field [ref] should be specified when [dataType] is set to [\"ref\"]"; logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3280",msg); } })); } }  }
PluginPackageDataModelDtoValidator { public void validate(PluginPackageDataModelDto pluginPackageDataModelDto) { Set<PluginPackageEntityDto> pluginPackageEntities = pluginPackageDataModelDto.getPluginPackageEntities(); if (null != pluginPackageEntities && pluginPackageEntities.size() > 0) { pluginPackageEntities.forEach(inputEntityDto -> inputEntityDto.getAttributes().forEach(inputAttributeDto -> { if (StringUtils.isEmpty(inputAttributeDto.getDataType())) { String msg = String.format( "The DataType should not be empty or null while registering he package [%s] with version: [%s]", inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3279",msg, inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); } if ("ref" .equals(inputAttributeDto.getDataType()) && StringUtils.isEmpty(inputAttributeDto.getRefAttributeName())) { String msg = "Field [ref] should be specified when [dataType] is set to [\"ref\"]"; logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3280",msg); } })); } }  void validate(PluginPackageDataModelDto pluginPackageDataModelDto); }
PluginPackageDataModelDtoValidator { public void validate(PluginPackageDataModelDto pluginPackageDataModelDto) { Set<PluginPackageEntityDto> pluginPackageEntities = pluginPackageDataModelDto.getPluginPackageEntities(); if (null != pluginPackageEntities && pluginPackageEntities.size() > 0) { pluginPackageEntities.forEach(inputEntityDto -> inputEntityDto.getAttributes().forEach(inputAttributeDto -> { if (StringUtils.isEmpty(inputAttributeDto.getDataType())) { String msg = String.format( "The DataType should not be empty or null while registering he package [%s] with version: [%s]", inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3279",msg, inputEntityDto.getPackageName(), inputEntityDto.getDataModelVersion()); } if ("ref" .equals(inputAttributeDto.getDataType()) && StringUtils.isEmpty(inputAttributeDto.getRefAttributeName())) { String msg = "Field [ref] should be specified when [dataType] is set to [\"ref\"]"; logger.error(msg); if (logger.isDebugEnabled()) { logger.debug(String.valueOf(inputAttributeDto)); } throw new WecubeCoreException("3280",msg); } })); } }  void validate(PluginPackageDataModelDto pluginPackageDataModelDto);  }