Package org.apache.bval.model

Examples of org.apache.bval.model.MetaBean


        return factory.getValidator();
    }


    public void testGroupSequence1() {
        MetaBean metaBean =
              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
                    .findForClass(GInterface1.class);
        List<Group> gseq = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
        Assert.assertNotNull(gseq);
        Assert.assertEquals(1, gseq.size());
        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
    }
View Full Code Here


        Assert.assertEquals(1, gseq.size());
        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
    }

    public void testGroupSequence2() {
        MetaBean metaBean =
              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
                    .findForClass(GClass1.class);
        List<Group> gseq = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
        Assert.assertNotNull(gseq);
        Assert.assertEquals(1, gseq.size());
        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
    }
View Full Code Here

        Assert.assertEquals(1, gseq.size());
        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
    }

    public void testGroupSequence3() {
        MetaBean metaBean =
              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
                    .findForClass(GClass2.class);
        List<Group> gseq = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
        Assert.assertNotNull(gseq);
        Assert.assertEquals(2, gseq.size());
        Assert.assertEquals(new Group(GClass1.class), gseq.get(0));
        Assert.assertEquals(Group.DEFAULT, gseq.get(1));
    }
View Full Code Here

        Assert.assertEquals(new Group(GClass1.class), gseq.get(0));
        Assert.assertEquals(Group.DEFAULT, gseq.get(1));
    }

    public void testGroupSequence4() {
        MetaBean metaBean =
              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
                    .findForClass(GClass3.class);
        List<Group> gseq = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
        Assert.assertNotNull(gseq);
        Assert.assertEquals(2, gseq.size());
        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
        Assert.assertEquals(new Group(GClass1.class), gseq.get(1));
    }
View Full Code Here

    public void testValidateMapAsBean() {
        XMLMetaBeanManagerFactory.getRegistry().addLoader(new XMLMetaBeanURLLoader(
              BusinessObject.class.getResource("test-beanInfos.xml")));

        MetaBean mb = XMLMetaBeanManagerFactory.getFinder()
              .findForId("org.apache.bval.example.Address");

        // 1. validate a bean
        BusinessObjectAddress adr = new BusinessObjectAddress();
        BeanValidator<ValidationResults> validator = new BeanValidator();
View Full Code Here

    public void testValidate() {
        MetaBeanFinder finder = XMLMetaBeanManagerFactory.getFinder();
        XMLMetaBeanManagerFactory.getRegistry().addLoader(new XMLMetaBeanURLLoader(
              BusinessObject.class.getResource("test-beanInfos.xml")));
        MetaBean info = finder.findForClass(BusinessObject.class);
        BusinessObject object = new BusinessObject();
        object.setAddress(new BusinessObjectAddress());
        object.getAddress().setOwner(object);
        BeanValidator<ValidationResults> validator = new BeanValidator();
        ValidationResults results = validator.validate(object, info);
        assertTrue(results.hasErrorForReason(Reasons.MANDATORY));
        assertTrue(results.hasError(object, null));
        assertTrue(results.hasError(object.getAddress(), null));

        assertTrue(
              validator.validateProperty(object, info.getProperty("firstName")).hasError(
                    object, "firstName"));

        object.setUserId(1L);
        object.setFirstName("Hans");
        object.setLastName("Tester");
View Full Code Here

        mbm = new XMLMetaBeanManager();
        mbm.addLoader(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos.xml")));
    }

    public void testBeanInfosCustomPatchGenerated() throws Exception {
        MetaBean mbean = mbm.findForClass(BusinessObject.class);
        MetaProperty mprop = mbean.getProperty("lastName");
        assertTrue(mprop.isMandatory());

        mbm.getCache().removeFromCache(mbean);
        mbm.addLoader(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos-custom.xml")));
        mbean = mbm.findForClass(BusinessObject.class);
        mprop = mbean.getProperty("lastName");
        assertTrue(!mprop.isMandatory());

        JSONGenerator converter = new JSONGenerator();

        List<MetaBean> metaBeans = new ArrayList(2);
        metaBeans.add(mbean);
        MetaBean mbean2 = mbm.findForId("UnknownObject");
        metaBeans.add(mbean2);
        String json = converter.toJSON(metaBeans);
        assertNotNull(json);
        // System.out.println(json);
    }
View Full Code Here

        assertNotNull(json);
        // System.out.println(json);
    }

    public void testJSON() throws Exception {
        MetaBean info = mbm.findForClass(BusinessObject.class);
        MetaBean info2 = info.getProperty("address").getMetaBean();

        // empty default bean without xml backup
        MetaBean info3 = mbm.findForClass(BusinessObjectAddress.class);
        JSONGenerator converter = new JSONGenerator();

        List<MetaBean> metaBeans = new ArrayList(2);
        metaBeans.add(info);
        metaBeans.add(info2);
View Full Code Here

        assertNotNull(json);
        // System.out.println(json);
    }

    public void testJSON_dynaTypeEnum() throws Exception {
        MetaBean info = mbm.findForClass(BusinessObject.class);
        MetaProperty choice = info.getProperty("choice");
        choice.setType(new DynaTypeEnum(BusinessEnum.class, "CUSTOM_1", "CUSTOM_2"));

        JSONGenerator converter = new JSONGenerator();

        List<MetaBean> metaBeans = new ArrayList(1);
View Full Code Here

    public void testEnrichCopies() throws Exception {
        Map<String, MetaBean> copies =
            mbm.enrichCopies(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos-custom.xml"))
                .load());
        assertNotNull(copies);
        MetaBean mb = copies.get(BusinessObject.class.getName());
        assertFalse(mb.getProperty("lastName").isMandatory());
        MetaBean mb2 = mbm.findForClass(BusinessObject.class);
        assertTrue(mb2.getProperty("lastName").isMandatory());
    }
View Full Code Here

TOP

Related Classes of org.apache.bval.model.MetaBean

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.