Package javax.validation

Examples of javax.validation.Validator.validate()


        Assert.assertEquals(1, result.size());
        Assert.assertEquals("The Car has to pass the fuel test and inspection test before being driven", result.iterator()
                .next().getMessage());
        car.setPassedVehicleInspection(true);

        result = validator.validate(car);
        // New group set in defaultsequence for Car as per CarGroupSequenceProvider should be implemented now
        Assert.assertEquals(2, result.size());

        car.setDriver(driver);
        // implementing validation for group associated with associated objects of Car(in this case Driver)
View Full Code Here


        // New group set in defaultsequence for Car as per CarGroupSequenceProvider should be implemented now
        Assert.assertEquals(2, result.size());

        car.setDriver(driver);
        // implementing validation for group associated with associated objects of Car(in this case Driver)
        Set<ConstraintViolation<Car>> driverResult = validator.validate(car, DriverChecks.class);
        Assert.assertEquals(1, driverResult.size());
        driver.setHasValidDrivingLicense(true);
        Assert.assertEquals(0, validator.validate(car, DriverChecks.class).size());

        car.setSeats(5);
View Full Code Here

        car.setDriver(driver);
        // implementing validation for group associated with associated objects of Car(in this case Driver)
        Set<ConstraintViolation<Car>> driverResult = validator.validate(car, DriverChecks.class);
        Assert.assertEquals(1, driverResult.size());
        driver.setHasValidDrivingLicense(true);
        Assert.assertEquals(0, validator.validate(car, DriverChecks.class).size());

        car.setSeats(5);
        car.setHasBeenPaid(true);

        Assert.assertEquals(0, validator.validate(car).size());
View Full Code Here

        Assert.assertEquals(0, validator.validate(car, DriverChecks.class).size());

        car.setSeats(5);
        car.setHasBeenPaid(true);

        Assert.assertEquals(0, validator.validate(car).size());

    }
}
View Full Code Here

        // create employee
        emp.setEmpId("M1234");
        emp.setFirstName("MADHUMITA");
        String email = "MADHUMITA";

        Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);

        Assert.assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
        Assert.assertEquals("Invalid Email!You have entered:--{" + email + "}", constraintViolations.iterator().next()
                .getMessage());
View Full Code Here

    public void testConstraintValidation() throws NamingException, SQLException {
        Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator");
        UserBean user1 = new UserBean("MADHUMITA", "");
        user1.setEmail("madhumita_gmail");
        user1.setAddress("");
        final Set<ConstraintViolation<UserBean>> result = validator.validate(user1);

        Object[] resultArray = result.toArray();
        Iterator it = result.iterator();
        String message = "";
View Full Code Here

        // Create a Car
        Car car = new Car("CET5678", passengers);
        car.setModel("SKODA Octavia");

        final Set<ConstraintViolation<Car>> errorresult = validator.validate(car);

        Object[] resultArray = errorresult.toArray();
        Iterator it1 = errorresult.iterator();
        String message = "";
View Full Code Here


    @Test
    public void testScriptAssert() throws NamingException, SQLException {
        Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator");
        final Set<ConstraintViolation<ScriptAssertBean>> result = validator.validate(new ScriptAssertBean());
        Assert.assertEquals(1, result.size());
    }
}
View Full Code Here

    DefaultViolationTranslator translator = new DefaultViolationTranslator();

    // test with a too short password
    BeanWithPassword bean = new BeanWithPassword("short");

    Set<ConstraintViolation<BeanWithPassword>> constraintViolations = validator.validate(bean);
    assertEquals(1, constraintViolations.size());

    @SuppressWarnings("unchecked")
    ConstraintViolation<BeanWithPassword> shortViolation = (ConstraintViolation<BeanWithPassword>)constraintViolations
      .toArray()[0];
View Full Code Here

    checkErrorBundleKeys(error, DEFAULT_BUNDLE_KEY + ".String", DEFAULT_BUNDLE_KEY);

    // test with a password containing non-word chars
    bean.setPassword("notWord&%$£");

    constraintViolations = validator.validate(bean);
    assertEquals(1, constraintViolations.size());

    @SuppressWarnings("unchecked")
    ConstraintViolation<BeanWithPassword> nonWordviolation = (ConstraintViolation<BeanWithPassword>)constraintViolations.toArray()[0];
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.