本文整理了Java中javax.validation.Configuration.addMapping()
方法的一些代码示例,展示了Configuration.addMapping()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.addMapping()
方法的具体详情如下:
包路径:javax.validation.Configuration
类名称:Configuration
方法名:addMapping
[英]Add a stream describing constraint mapping in the Bean Validation XML format.
The stream should be closed by the client API after the ValidatorFactory has been built. The Bean Validation provider must not close the stream.
[中]添加一个以Bean验证XML格式描述约束映射的流。
在构建ValidatorFactory之后,客户端API应该关闭流。Bean验证提供程序不能关闭流。
代码示例来源:origin: spring-projects/spring-framework
for (Resource location : this.mappingLocations) {
try {
configuration.addMapping(location.getInputStream());
代码示例来源:origin: org.springframework/spring-context
for (Resource location : this.mappingLocations) {
try {
configuration.addMapping(location.getInputStream());
代码示例来源:origin: hibernate/hibernate-validator
public StatisticalValidationState() {
ValidatorFactory factory = null;
final Configuration<?> configuration = Validation.byDefaultProvider().configure();
try ( InputStream mappingStream = StatisticalValidation.class.getResourceAsStream( "mapping.xml" ) ) {
configuration.addMapping( mappingStream );
factory = configuration.buildValidatorFactory();
assertThat( factory ).isNotNull();
}
catch (IOException e) {
throw new IllegalStateException( "Mappings cannot be read. Validation factory cannot be configured correctly.", e );
}
validator = factory.getValidator();
entitiesUnderTest = IntStream.rangeClosed( 0, NUMBER_OF_TEST_ENTITIES )
.mapToObj( index -> new TestEntity( index % 10 ) )
.collect( Collectors.toList() );
}
代码示例来源:origin: org.graniteds/granite-client-java-advanced
@SuppressWarnings("unchecked")
@Override
public T addMapping(InputStream stream) {
configuration = configuration.addMapping(stream);
return (T)this;
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
private Validator getValidator(String mappingFile) {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( getClass().getResourceAsStream( mappingFile ) );
return config.buildValidatorFactory().getValidator();
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
private Validator getValidator(String mappingFile) {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( getClass().getResourceAsStream( mappingFile ) );
return config.buildValidatorFactory().getValidator();
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
private Validator getValidator(String mappingFile) {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( getClass().getResourceAsStream( mappingFile ) );
return config.buildValidatorFactory().getValidator();
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
private Validator getValidator(String mappingFile) {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( getClass().getResourceAsStream( mappingFile ) );
return config.buildValidatorFactory().getValidator();
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
private Validator getValidator(String mappingFile) {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( getClass().getResourceAsStream( mappingFile ) );
return config.buildValidatorFactory().getValidator();
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.XML_MAPPING_XSD, id = "c")
public void testConstraintMappingWithUnknownSchemaVersion() {
TestUtil.getConfigurationUnderTest()
.addMapping( UnknownVersionInMappingXmlTest.class.getResourceAsStream( MAPPING_FILE ) )
.buildValidatorFactory()
.getValidator();
}
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.XML, id = "a")
public void testInvalidConstraintMappingXml() {
TestUtil.getConfigurationUnderTest()
.addMapping( InvalidMappingXmlTest.class.getResourceAsStream( MAPPING_FILE ) )
.buildValidatorFactory()
.getValidator();
}
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRAINTDECLARATION, id = "c")
public void testMessageIsNotAllowedAsElementName() {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile2 ) );
config.buildValidatorFactory().getValidator();
fail( "Validator creation should have failed since <element name=\"message\"> was used." );
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRAINTDECLARATION, id = "c")
public void testPayloadIsNotAllowedAsElementName() {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile1 ) );
config.buildValidatorFactory().getValidator();
fail( "Validator creation should have failed since <element name=\"groups\"> was used." );
}
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test
@SpecAssertion(section = Sections.XML_MAPPING_XSD, id = "a")
public void testValidBeanValidation11Mapping() {
Validator validator = TestUtil.getConfigurationUnderTest()
.addMapping( Version11InMappingXmlTest.class.getResourceAsStream( MAPPING_FILE ) )
.buildValidatorFactory()
.getValidator();
assertFalse( validator.getConstraintsForClass( TestEntity.class ).isBeanConstrained() );
}
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test
@SpecAssertion(section = Sections.XML_MAPPING_XSD, id = "a")
public void testValidBeanValidation20Mapping() {
Validator validator = TestUtil.getConfigurationUnderTest()
.addMapping( Version20InMappingXmlTest.class.getResourceAsStream( MAPPING_FILE ) )
.buildValidatorFactory()
.getValidator();
assertFalse( validator.getConstraintsForClass( TestEntity.class ).isBeanConstrained() );
}
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CONSTRAINTDECLARATION, id = "c")
public void testGroupIsNotAllowedAsElementName() {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile1 ) );
config.buildValidatorFactory().getValidator();
fail( "Validator creation should have failed since <element name=\"groups\"> was used." );
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test
@SpecAssertion(section = Sections.XML_MAPPING_XSD, id = "a")
public void testValidBeanValidation10Mapping() {
Validator validator = TestUtil.getConfigurationUnderTest()
.addMapping( Version10InMappingXmlTest.class.getResourceAsStream( MAPPING_FILE ) )
.buildValidatorFactory()
.getValidator();
assertFalse( validator.getConstraintsForClass( TestEntity.class ).isBeanConstrained() );
}
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test(expectedExceptions = ValidationException.class)
@SpecAssertion(section = Sections.XML_MAPPING_TYPECONVERSION, id = "l")
public void testIllegalAnnotationValueInXmlMappingCausesException() {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( getStream( "superuser-constraints.xml" ) );
Validator validator = config.buildValidatorFactory().getValidator();
validator.getConstraintsForClass( SuperUser.class );
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CLASSLEVELOVERRIDING, id = "b")
public void testIgnoreAnnotationsFromEnclosingBeanIsApplied() {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile2 ) );
Validator validator = config.buildValidatorFactory().getValidator();
Package p = new Package();
Set<ConstraintViolation<Package>> violations = validator.validate( p );
assertNumberOfViolations( violations, 1 );
assertCorrectConstraintViolationMessages( violations, "ValidPackage defined in XML" );
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
@Test
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CLASSLEVELOVERRIDING, id = "a")
@SpecAssertion(section = Sections.XML_MAPPING_CONSTRAINTDECLARATIONINXML_CLASSLEVELOVERRIDING, id = "c")
public void testIgnoreClassLevelAnnotations() {
Configuration<?> config = TestUtil.getConfigurationUnderTest();
config.addMapping( TestUtil.getInputStreamForPath( packageName + mappingFile1 ) );
Validator validator = config.buildValidatorFactory().getValidator();
Package p = new Package();
Set<ConstraintViolation<Package>> violations = validator.validate( p );
assertNumberOfViolations( violations, 1 );
assertCorrectConstraintViolationMessages( violations, "ValidPackage defined in XML" );
}
内容来源于网络,如有侵权,请联系作者删除!