Package example

Examples of example.Author


    protected Validator createValidator() {
        return factory.getValidator();
    }

    public void testValidateList() {
        Author author = new Author();
        author.setFirstName("Peter");
        author.setLastName("Ford");
        author.setCompany("IBM");
        author.setAddresses(new ArrayList<Address>());

        Address adr1, adr2, adr3;
        adr1 = new Address();
        adr1.setCountry(new Country());
        adr1.getCountry().setName("Germany");
        adr1.setCity("Bonn");
        adr1.setAddressline1("Strasse 1");

        adr2 = new Address();
        adr2.setCountry(new Country());
        adr2.getCountry().setName("Cuba");
        adr2.setCity("Habana");
        adr2.setAddressline1("Calle 2");

        adr3 = new Address();
        adr3.setCountry(new Country());
        adr3.getCountry().setName("USA");
        adr3.setCity("San Francisco");
        adr3.setAddressline1("Street 3");

        author.getAddresses().add(adr1);
        author.getAddresses().add(adr2);
        author.getAddresses().add(adr3);

        Set<ConstraintViolation<Author>> violations;

        violations = validator.validate(author);
        assertEquals(0, violations.size());
View Full Code Here


        Book book1, book2, book3;

        book1 = new Book();
        book1.setTitle("History of time");
        book1.setSubtitle("How it really works");
        Author hawking = new Author();
        hawking.setFirstName("Stephen");
        hawking.setFirstName("Hawking");
        hawking.setAddresses(new ArrayList<Address>(1));
        Address adr = new Address();
        adr.setAddressline1("Street 1");
        adr.setCity("London");
        adr.setCountry(new Country());
        adr.getCountry().setName("England");
        hawking.getAddresses().add(adr);
        book1.setAuthor(hawking);

        book2 = new Book();
        Author castro = new Author();
        castro.setFirstName("Fidel");
        castro.setLastName("Castro Ruz");
        book2.setAuthor(castro);
        book2.setTitle("My life");

        book3 = new Book();
        book3.setTitle("World best jokes");
        Author someone = new Author();
        someone.setFirstName("John");
        someone.setLastName("Do");
        book3.setAuthor(someone);

        lib.getTaggedBooks().put("science", book1);
        lib.getTaggedBooks().put("politics", book2);
        lib.getTaggedBooks().put("humor", book3);
View Full Code Here

        errors = validator.validate(o1);
        assertEquals(1, errors.size());
    }

    public void testBook() {
        Author author = new Author();
        author.setLastName("Baudelaire");
        author.setFirstName("");
        Book book = new Book();
        book.setAuthor(author);
        book.setSubtitle("12345678900125678901234578901234567890");

        // NotEmpty failure on the title field
        Set<ConstraintViolation<Book>> errors = validator.validate(book, Book.All.class);
        Assert.assertTrue(!errors.isEmpty());

        book.setTitle("Les fleurs du mal");
        author.setCompany("Some random publisher with a very very very long name");

        // author.firstName fails to pass the NotEmpty constraint
        // author.company fails to pass the Size constraint
    }
View Full Code Here

    /**
     * test: - dynamic resolution of associated object types. - inheritance of validation constraints - complex
     * valiation, different groups, nested object net
     */
    public void testValidAnnotation() {
        Author a = new Author();
        a.setAddresses(new ArrayList<Address>());
        BusinessAddress adr = new BusinessAddress();
        adr.setCountry(new Country());
        adr.setAddressline1("line1");
        adr.setAddressline2("line2");

        adr.setZipCode("1234567890123456789");
        a.getAddresses().add(adr);

        a.setFirstName("Karl");
        a.setLastName("May");

        Set<ConstraintViolation<Author>> found = validator.validate(a, Default.class, First.class, Last.class);
        Assert.assertTrue(!found.isEmpty());
        Assert.assertEquals(4, found.size());

View Full Code Here

        ConstraintViolation<Author> ic = found.iterator().next();
        Assert.assertEquals("addresses[0].country.name", ic.getPropertyPath().toString());
    }

    public void testPropertyPathWithIndex() {
        Author a = new Author();
        a.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        adr.setAddressline1("adr1");
        adr.setCity("Santiago");
        a.getAddresses().add(adr);
        adr = new Address();
        adr.setAddressline1("adr2");
        adr.setCity("Havanna");
        a.getAddresses().add(adr);
        adr = new Address();
        adr.setAddressline1("adr3");
        adr.setCity("Trinidad");
        a.getAddresses().add(adr);

        Set<ConstraintViolation<Author>> constraints = validator.validate(a);
        Assert.assertTrue(!constraints.isEmpty());

        assertPropertyPath("addresses[0].country", constraints);
View Full Code Here

        Assert.assertTrue(!validator.validate(foo).isEmpty());
        // check that no nullpointer exception gets thrown
    }

    public void testGroups() {
        Author author = new Author();
        author.setCompany("ACME");
        Book book = new Book();
        book.setTitle("");
        book.setAuthor(author);
        boolean foundTitleConstraint = false;
        Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book, Book.All.class);
View Full Code Here

    public void testValidateNestedPropertyPath() throws InvocationTargetException, NoSuchMethodException,
        IllegalAccessException {
        final String propPath = "addresses[0].country.ISO2Code";

        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCountry(country);
        country.setISO2Code("too_long");

        Set<ConstraintViolation<Author>> iv = validator.validateProperty(author, propPath);
        Assert.assertEquals(1, iv.size());
        ConstraintViolation<Author> vio = iv.iterator().next();
        assertEquals(propPath, vio.getPropertyPath().toString());
        assertSame(author, vio.getRootBean());
        assertSame(author.getAddresses().get(0).getCountry(), vio.getLeafBean());

        country.setISO2Code("23");
        iv = validator.validateProperty(author, propPath);
        Assert.assertEquals(0, iv.size());
View Full Code Here

    public void testValidateCascadingNestedBean() throws InvocationTargetException, NoSuchMethodException,
        IllegalAccessException {
        final String propPath = "addresses[0]";

        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
View Full Code Here

    public void testValidateCascadingNestedProperty() throws InvocationTargetException, NoSuchMethodException,
        IllegalAccessException {
        final String propPath = "addresses[0].country";

        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
View Full Code Here

    public void testValidateCascadingNestedTipProperty() {
        final String propPath = "addresses[0].country.name";

        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
View Full Code Here

TOP

Related Classes of example.Author

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.