@Test public void validate_stopValidationIfNoUsernameIsPassed() { usernameExValidator.validate(null, null, ""); assertTrue(true); }
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String desiredUsername = (String) value; if (desiredUsername == null || desiredUsername.length() == 0) { return; } Long userUsingUsername = (Long) em .createQuery("SELECT COUNT(u) FROM IdpUser u WHERE u.username = :desiredUsername") .setParameter("desiredUsername", desiredUsername).getSingleResult(); if (userUsingUsername > 0) { throw new ValidatorException(new FacesMessage("The username is already taken. Please choose another one.")); } }
UsernameExistsValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String desiredUsername = (String) value; if (desiredUsername == null || desiredUsername.length() == 0) { return; } Long userUsingUsername = (Long) em .createQuery("SELECT COUNT(u) FROM IdpUser u WHERE u.username = :desiredUsername") .setParameter("desiredUsername", desiredUsername).getSingleResult(); if (userUsingUsername > 0) { throw new ValidatorException(new FacesMessage("The username is already taken. Please choose another one.")); } } }
UsernameExistsValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String desiredUsername = (String) value; if (desiredUsername == null || desiredUsername.length() == 0) { return; } Long userUsingUsername = (Long) em .createQuery("SELECT COUNT(u) FROM IdpUser u WHERE u.username = :desiredUsername") .setParameter("desiredUsername", desiredUsername).getSingleResult(); if (userUsingUsername > 0) { throw new ValidatorException(new FacesMessage("The username is already taken. Please choose another one.")); } }  }
UsernameExistsValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String desiredUsername = (String) value; if (desiredUsername == null || desiredUsername.length() == 0) { return; } Long userUsingUsername = (Long) em .createQuery("SELECT COUNT(u) FROM IdpUser u WHERE u.username = :desiredUsername") .setParameter("desiredUsername", desiredUsername).getSingleResult(); if (userUsingUsername > 0) { throw new ValidatorException(new FacesMessage("The username is already taken. Please choose another one.")); } }  @Override void validate(FacesContext context, UIComponent component, Object value); void setEntityManager(EntityManager em); }
UsernameExistsValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String desiredUsername = (String) value; if (desiredUsername == null || desiredUsername.length() == 0) { return; } Long userUsingUsername = (Long) em .createQuery("SELECT COUNT(u) FROM IdpUser u WHERE u.username = :desiredUsername") .setParameter("desiredUsername", desiredUsername).getSingleResult(); if (userUsingUsername > 0) { throw new ValidatorException(new FacesMessage("The username is already taken. Please choose another one.")); } }  @Override void validate(FacesContext context, UIComponent component, Object value); void setEntityManager(EntityManager em);  }