use of javax.validation.Validator in project wildfly by wildfly.
the class MessageInterpolationValidationTestCase method testCustomMessageInterpolation.
@Test
public void testCustomMessageInterpolation() {
HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure();
assertNotNull(configuration);
final MessageInterpolator messageInterpolator = new CustomMessageInterpolator();
configuration.messageInterpolator(messageInterpolator);
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
// create employee
Employee emp = new Employee();
emp.setEmail("MADHUMITA");
Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
assertEquals(CustomMessageInterpolator.MESSAGE, constraintViolations.iterator().next().getMessage());
}
use of javax.validation.Validator in project wildfly by wildfly.
the class ScriptAssertTestCase method testScriptAssert.
@Test
public void testScriptAssert() throws NamingException, SQLException {
Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator");
final Set<ConstraintViolation<ScriptAssertBean>> result = validator.validate(new ScriptAssertBean());
Assert.assertEquals(1, result.size());
}
use of javax.validation.Validator in project wildfly by wildfly.
the class ConstraintValidationTestCase method testConstraintValidation.
@Test
public void testConstraintValidation() throws NamingException {
Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator");
UserBean user1 = new UserBean("MADHUMITA", "");
user1.setEmail("madhumita_gmail");
user1.setAddress("");
final Set<ConstraintViolation<UserBean>> result = validator.validate(user1);
Iterator<ConstraintViolation<UserBean>> it = result.iterator();
String message = "";
while (it.hasNext()) {
ConstraintViolation<UserBean> cts = it.next();
String mess = cts.getMessage();
if (mess.contains("Please get a valid address")) {
message = mess;
}
}
assertEquals(3, result.size());
assertTrue(message.contains("Please get a valid address"));
}
use of javax.validation.Validator in project tomee by apache.
the class AppComposerAsJUnitRuleTest method lookupValidator.
@Test
public void lookupValidator() throws Exception {
final Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator");
assertNotNull(validator);
}
use of javax.validation.Validator in project tomee by apache.
the class BuiltInEnvironmentEntries method add.
private void add(final JndiConsumer jndi, final DeploymentModule module, final DeploymentModule app, final boolean defaults) {
// Standard names
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:module/ModuleName").value(module.getModuleId()).type(String.class));
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:app/AppName").value(app.getModuleId()).type(String.class));
// Standard References to built-in objects
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/BeanManager").type(BeanManager.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/Validator").type(Validator.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/ValidatorFactory").type(ValidatorFactory.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionManager").type(TransactionManager.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionSynchronizationRegistry").type(TransactionSynchronizationRegistry.class));
if (defaults) {
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedExecutorService").type(ManagedExecutorService.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedScheduledExecutorService").type(ManagedScheduledExecutorService.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedThreadFactory").type(ManagedThreadFactory.class));
try {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
contextClassLoader.loadClass("org.apache.activemq.ActiveMQSslConnectionFactory");
final ResourceEnvRef ref = new ResourceEnvRef().name("java:comp/DefaultJMSConnectionFactory").type(contextClassLoader.loadClass("javax.jms.ConnectionFactory"));
add(jndi.getResourceEnvRefMap(), ref);
} catch (final ClassNotFoundException | NoClassDefFoundError notThere) {
// no-op
}
}
// OpenEJB specific feature
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:comp/ComponentName").value(jndi.getJndiConsumerName()).type(String.class));
}
Aggregations