This week, at Elsa Development, weve been implementing some customized validators using Bean Validation API. Everything was going fine, until the shadows of Murphy appear. OK, putting aside the drama, a few validators have been implemented successfully, passing all tests, all of them but one...The ProblemTwo constraints were created and for each one, a validator was implemented (which executes the validation logic). Both constraints were used at field-level on JPA entities, the Username and FloatRange constraints were annotated on fields of type string and float, respectively. However, just the Username constraint worked.. Hereunder you can take a look at the implemented code, or part of it :)@Documented@Retention(RetentionPolicy.RUNTIME)@Constraint(validatedBy = UsernameValidator.class)@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE})public @interface Username { String message() default "{constraint.username.invalid}"; Class<? extends Payload>[] payload() default {}; Class<?>[] groups() default {};}Code 1. The working constraint.public class UsernameValidator implements ConstraintValidator<Username, String> { @Override public void initialize(Username annotation) {} @Override public boolean isValid(String value, ConstraintValidatorContext context) { // validation logic ommited }}Code 2. The validation for @Username constraint.@Documented@Retention(RetentionPolicy.RUNTIME)@Constraint(validatedBy = FloatRangeValidator.class)@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE})public @interface FloatRange { String message() default "{constraint.range}"; Class<? extends Payload>[] payload() default {}; Class<?>[] groups() default {}; float min(); float max();}Code 3. The murphyfied constraint (i.e. did not work).public class FloatRangeValidator implements ConstraintValidator<FloatRange, Float> { private float min; private float max; @Override public void initialize(FloatRange annotation) { this.min = annotation.min(); this.max = annotation.max(); } @Override public boolean isValid(Float value, ConstraintValidatorContext context) { // validation logic ommited }}Code 4. The murphyfied constraint.The SolutionAfter a lot of googling and force brute tests... A co worker (Marcelo Yamashita) came with the solution. He tried to use the @FloatRange constraint at property-level, man... that worked! Then, reading more carefully the Hibernate Validator documentation, more specifically the item 2.1.1. Field-level constraints, i noticed the note that says:Static fields and properties cannot be validated. Well, if i've got it right, by properties it means POJO fields which have getter/setter, or not? If so, then houston, we have a problem... both target annotated fields, belong to JPA entities thus, they have getters and setters! It doesnt make them properties? Anyway, the workaround rocks, but if you have any idea about the why this happens, please, feel free to share it with the world :) O Selenium WebDriver ea uniao de duas ferramentas e visa facilitar a criacao de testes automatizadospara interfaces de aplicacoes web. A intencao das novas versoes do Selenium (apartir da 2.0) e focar no desenvolvedor para que ele gere tambem os codigos dostestes. Neste post vamos explicar em alguns passos como comecar a fazer seusproprios testes.No nosso exemplo vamos utilizar comolinguagem de programacao o Java e como ambiente de desenvolvimento o Eclipse. Para executar os testes utilizaremos o JUnit.O primeiro passo e adicionar os JARspara que consigamos utilizar o WebDriver. Para fazer o download da ultimaversao va ate http://code.google.com/p/selenium/downloads/list. Descompacte o arquivo e adicione os JARs ao seuprojeto no Eclipse clicando com o botao direito do mouse em cima da raiz do seuprojeto e depois em "Properties".No menu esquerdo clique em "JavaBuild Path", selecione a aba "Libraries" e clique em "AddExternal JARs...". Navegue ate a pasta onde