Java Code Examples for org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#destroy()

The following examples show how to use org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#destroy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidatorFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSimpleValidation() {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}

	Validator nativeValidator = validator.unwrap(Validator.class);
	assertTrue(nativeValidator.getClass().getName().startsWith("org.hibernate"));
	assertTrue(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory);
	assertTrue(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory);

	validator.destroy();
}
 
Example 2
Source File: ValidatorFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSimpleValidationWithCustomProvider() {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}

	Validator nativeValidator = validator.unwrap(Validator.class);
	assertTrue(nativeValidator.getClass().getName().startsWith("org.hibernate"));
	assertTrue(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory);
	assertTrue(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory);

	validator.destroy();
}
 
Example 3
Source File: ValidatorFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSimpleValidation() {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}

	Validator nativeValidator = validator.unwrap(Validator.class);
	assertTrue(nativeValidator.getClass().getName().startsWith("org.hibernate"));
	assertTrue(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory);
	assertTrue(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory);

	validator.destroy();
}
 
Example 4
Source File: ValidatorFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSimpleValidationWithCustomProvider() {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}

	Validator nativeValidator = validator.unwrap(Validator.class);
	assertTrue(nativeValidator.getClass().getName().startsWith("org.hibernate"));
	assertTrue(validator.unwrap(ValidatorFactory.class) instanceof HibernateValidatorFactory);
	assertTrue(validator.unwrap(HibernateValidatorFactory.class) instanceof HibernateValidatorFactory);

	validator.destroy();
}
 
Example 5
Source File: ValidatorFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleValidation() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}
 
Example 6
Source File: ValidatorFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}