public void testRegularExpressionField() throws Exception
{
Project project = projectHelper.createWebProject();
projectHelper.installJPA_2_0(project);
projectHelper.installValidation(project);
JavaResource jpaEntity = projectHelper.createJPAEntity(project, "Customer");
WizardCommandController wizard = testHarness.createWizardController(ValidationAddConstraintWizard.class,
project.getRoot());
wizard.initialize();
// Page 1
{
wizard.setValueFor("javaClass", jpaEntity);
Assert.assertTrue(wizard.canMoveToNextStep());
}
wizard.next().initialize();
// Page 2
{
wizard.setValueFor("onProperty", "id");
wizard.setValueFor("constraint", CoreConstraints.PATTERN);
Assert.assertTrue(wizard.canMoveToNextStep());
}
wizard.next().initialize();
// Page 3
{
Assert.assertFalse(wizard.isValid());
wizard.setValueFor("regexp", "^\\d{9}[\\d|X]$");
Assert.assertTrue(wizard.isValid());
}
wizard.execute();
JavaClassSource javaClass = jpaEntity.getJavaType();
FieldSource<JavaClassSource> field = javaClass.getField("id");
AnnotationSource<JavaClassSource> pattern = field.getAnnotation(Pattern.class);
Assert.assertNotNull(pattern);
Assert.assertEquals("^\\d{9}[\\d|X]$", pattern.getStringValue("regexp"));