Search in sources :

Example 6 with Extension1

use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.

the class ExtensionTest method testFormatUsingPropertyTranslator.

/*
    Commenting out until AOP interceptors are finished

        public void testInList() {
            log.debug("testInList");
            try {
                Extension1 obj = createExtension1();
                try {
                    obj.setField1("value5");
                    obj.validate();
                    fail("The invocation Extension1.setField1(value5) should have failed since it is not in the list of valid values");
                } catch (Exception e) {
                    PatternMismatchException appExp = (PatternMismatchException) ExceptionHelper.extractException(e, PatternMismatchException.class);
                    if (appExp == null)
                        throw e;
                }
                obj.setField1("value1");
                obj.validate();
                obj.setField1("value2");
                obj.validate();
                obj.setField1("value3");
                obj.validate();
                obj.setField1("value4");
                obj.validate();

                try {
                    obj.setField2("value5");
                    obj.validate();
                    fail("The invocation Extension1.setField2(value5) should have failed since it is not in the list of valid values");
                } catch (Exception e) {
                    PatternMismatchException appExp = (PatternMismatchException) ExceptionHelper.extractException(e, PatternMismatchException.class);
                    if (appExp == null)
                        throw e;
                }
                obj.setField2("value1");
                obj.validate();
                obj.setField2("value2");
                obj.validate();
                obj.setField2("value3");
                obj.validate();
                obj.setField2("value4");
                obj.validate();
            } catch (Exception e) {
                e.printStackTrace(System.err);
                fail();
            }
        }
        */
public void testFormatUsingPropertyTranslator() {
    log.debug("testFormatUsingPropertyTranslator");
    try {
        Extension1 obj = new Extension1();
        IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(obj.getClass().getName(), "field1", obj);
        // This should utilize the PropertyTranslator for translating a value as per the layout "[label.module.prop.{0}]"
        assertEquals("[label.module.prop.xyz]", w.format("xyz"));
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail();
    }
}
Also used : Extension1(org.jaffa.rules.testmodels.Extension1) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 7 with Extension1

use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.

the class ExtensionTest method testMinLengthOverride.

/*
    Commenting out until AOP interceptors are finished

    public void testDuplicateInDifferentMetaData() {
        log.debug("testDuplicateInDifferentMetaData");
        try {
            Extension1 obj = new Extension1();
            assertEquals("value2", obj.getField2());
        } catch (Exception e) {
            e.printStackTrace(System.err);
            fail();
        }
    }
*/
/*
    Commenting out until AOP interceptors are finished

    public void testDuplicateInDifferentFiles() {
        log.debug("testDuplicateInDifferentFiles");
        try {
            Extension1 obj = new Extension1();
            assertEquals("value2", obj.getField3());
        } catch (Exception e) {
            e.printStackTrace(System.err);
            fail();
        }
    }
    */
public void testMinLengthOverride() {
    log.debug("testMinLengthOverride");
    try {
        Extension1 obj = new Extension1();
        IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(obj.getClass().getName(), "field3", obj);
        assertEquals(new Integer(2), w.getMinLength());
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail();
    }
}
Also used : Extension1(org.jaffa.rules.testmodels.Extension1) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Example 8 with Extension1

use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.

the class ExtensionTest method testMinAndMaxValue.

/*
    Commenting out until AOP interceptors are finished

        public void testLabelAtObjectLevel() {
            log.debug("testLabelAtObjectLevel");
            try {
                // This will obtain the label for the condition 'field1 == null'
                Extension1 obj = new Extension1();
                obj.setField1(null);
                IObjectRuleIntrospector w = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(obj.getClass().getName(), obj);
                assertEquals("object label to use when field1 is null", w.getLabel());

                // This will obtain the label for the condition 'field1 != null'
                obj.setField1("value2");
                w = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(obj.getClass().getName(), obj);
                assertEquals("object label to use when field1 is not null", w.getLabel());
            } catch (Exception e) {
                e.printStackTrace(System.err);
                fail();
            }
        }
*/
public void testMinAndMaxValue() {
    log.debug("testMinAndMaxValue");
    try {
        IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field4", null);
        assertEquals(1d, w.getMinValue());
        assertEquals(100d, w.getMaxValue());
        w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field5", null);
        assertEquals(1L, w.getMinValue());
        assertEquals(100L, w.getMaxValue());
        // Note: This test may fail if it is executed on the stroke of midnight
        w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field6", null);
        assertEquals(DateOnly.addDay(new DateOnly(), -10), w.getMinValue());
        assertEquals(new DateOnly(), w.getMaxValue());
        w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(Extension1.class.getName(), "field7", null);
        assertEquals(1, w.getMinValue());
        assertEquals(100, w.getMaxValue());
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail();
    }
}
Also used : DateOnly(org.jaffa.datatypes.DateOnly) Extension1(org.jaffa.rules.testmodels.Extension1) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException)

Aggregations

Extension1 (org.jaffa.rules.testmodels.Extension1)8 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)7 DateOnly (org.jaffa.datatypes.DateOnly)1