Package javax.validation

Examples of javax.validation.ConstraintViolation


    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



    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

        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

        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, "size must be between 0 and 30" );
    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 divison of RedHat" );

    constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
    constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getMessage(), "size must be between 0 and 20" );
    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

    Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
        Customer.class, "orders[0].orderNumber", null
    );
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );

    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getMessage(), "may not be null", "Wrong message" );
    assertEquals( constraintViolation.getRootBean(), null, "Wrong root entity" );
    assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
    assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "orders[0].orderNumber" );

    constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
    assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
  }
View Full Code Here

    customer.setLastName( "Doe" );
    Order order = new Order();
    customer.addOrder( order );

    Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
    ConstraintViolation constraintViolation = constraintViolations.iterator().next();
    assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
    assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
    assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
    assertCorrectPropertyPaths( constraintViolations, "orders[].orderNumber" );
  }
View Full Code Here

    clint.addPlayedWith( morgan );


    Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
    assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
    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

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.