Package javax.validation

Examples of javax.validation.ConstraintViolation



    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertCorrectNumberOfViolations( constraintViolations, 2 );

    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
    assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
    assertCorrectPropertyPaths(
        constraintViolations,
        "playedWith[0].playedWith[1].lastName",
        "playedWith[1].lastName"
    );
View Full Code Here


    morgan.addPlayedWith( clint );
    clint.addPlayedWith( morgan );

    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertCorrectNumberOfViolations( constraintViolations, 2 );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
    assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
    assertCorrectPropertyPaths(
        constraintViolations,
        "playedWith[0].playedWith[1].lastName",
        "playedWith[1].lastName"
    );
View Full Code Here


    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertCorrectNumberOfViolations( constraintViolations, 2 );

    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getMessage(), "Everyone has a last name.", "Wrong message" );
    assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
    assertCorrectPropertyPaths(
        constraintViolations,
        "playedWith[0].playedWith[1].lastName",
        "playedWith[1].lastName"
    );
View Full Code Here

    morgan.addPlayedWith( clint );
    clint.addPlayedWith( morgan );

    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertCorrectNumberOfViolations( constraintViolations, 2 );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getMessage(), "Everyone has a last name.", "Wrong message" );
    assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
    assertCorrectPropertyPaths(
        constraintViolations,
        "playedWith[0].playedWith[1].lastName",
        "playedWith[1].lastName"
    );
View Full Code Here

    author.setFirstName( "Gavin" );
    author.setLastName( "King" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "title" );

    book.setTitle( "Hibernate Persistence with JPA" );
    book.setSubtitle( "Revised Edition of Hibernate in Action" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages(
        constraintViolations, "The book's subtitle can only have 30 characters"
    );
    constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "subtitle" );

    book.setSubtitle( "Revised Edition" );
    author.setCompany( "JBoss a division of RedHat" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    constraintViolation = constraintViolations.iterator().next();
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages(
        constraintViolations, "The company name can only have 20 characters"
    );
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "author.company" );

    author.setCompany( "JBoss" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
View Full Code Here

    author.setLastName( "King" );

    constraintViolations = validator.validate( book, Book.All.class );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages( constraintViolations, "The book title cannot be null" );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "title" );

    book.setTitle( "Hibernate Persistence with JPA" );
    book.setSubtitle( "Revised Edition of Hibernate in Action" );
View Full Code Here

            }

            if (violations != null && !violations.isEmpty()) {
                ValidatorException toThrow;
                if (1 == violations.size()) {
                    ConstraintViolation violation = violations.iterator().next();
                    toThrow = new ValidatorException(MessageFactory.getMessage(
                          context,
                          MESSAGE_ID,
                          violation.getMessage(),
                          MessageFactory.getLabel(context, component)));
                } else {
                    Set<FacesMessage> messages = new LinkedHashSet<FacesMessage>(
                          violations.size());
                    for (ConstraintViolation violation : violations) {
                        messages.add(MessageFactory.getMessage(context,
                                                               MESSAGE_ID,
                                                               violation.getMessage(),
                                                               MessageFactory.getLabel(
                                                                     context,
                                                                     component)));
                    }
                    toThrow = new ValidatorException(messages);
View Full Code Here

        constraintsBox.setAlignment(Pos.CENTER_LEFT);
        controller.getConstraintViolations().addListener(new ListChangeListener() {
            public void onChanged(Change change) {
                constraintsBox.getChildren().clear();
                for (Object o : controller.getConstraintViolations()) {
                    ConstraintViolation constraintViolation = (ConstraintViolation) o;
                    Label errorLabel = new Label(constraintViolation.getMessage());
                    ImageView warningView = new ImageView(WARNING);
                    warningView.setFitHeight(15);
                    warningView.setPreserveRatio(true);
                    warningView.setSmooth(true);
                    errorLabel.setGraphic(warningView);
View Full Code Here

    StringBuffer message = new StringBuffer();

    if (!violations.isEmpty()) {
      for (Iterator iter = violations.iterator(); iter.hasNext();) {
        ConstraintViolation violation = (ConstraintViolation) iter.next();
        message.append(field.toGenericString() + " " + violation.getMessage() + "\n");
      }

      throw new ConfigurationException(message.toString(), new ConstraintViolationException(violations));
    }
  }
View Full Code Here

    author.setFirstName( "Gavin" );
    author.setLastName( "King" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "title" );

    book.setTitle( "Hibernate Persistence with JPA" );
    book.setSubtitle( "Revised Edition of Hibernate in Action" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages(
        constraintViolations, "The book's subtitle can only have 30 characters"
    );
    constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "subtitle" );

    book.setSubtitle( "Revised Edition" );
    author.setCompany( "JBoss a division of RedHat" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    constraintViolation = constraintViolations.iterator().next();
    assertCorrectNumberOfViolations( constraintViolations, 1 );
    assertCorrectConstraintViolationMessages(
        constraintViolations, "The company name can only have 20 characters"
    );
    assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "author.company" );

    author.setCompany( "JBoss" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
View Full Code Here

TOP

Related Classes of javax.validation.ConstraintViolation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.