use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.
the class ExtensionTest method testFormat.
/*
Commenting out until AOP interceptors are finished
public void testForeignKey() {
try {
Extension1 obj = createExtension1();
try {
obj.setField10("ZZZ");
obj.validate();
fail("The invocation Extension1.setField10(ZZZ) should have failed since we passed an invalid foreign-key");
} catch (Exception e) {
InvalidForeignKeyException appExp = (InvalidForeignKeyException) ExceptionHelper.extractException(e, InvalidForeignKeyException.class);
if (appExp != null) {
Object[] arguments = appExp.getArguments();
assertNotNull("The InvalidForeignKeyException should have arguments", arguments);
assertTrue("The InvalidForeignKeyException should have arguments", arguments.length > 0);
assertEquals("The InvalidForeignKeyException should have been created for field10", "field10", arguments[0]);
} else {
throw e;
}
}
obj.setField10("KEY2");
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
public void testFormat() {
log.debug("testFormat");
try {
Extension1 obj = new Extension1();
IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(obj.getClass().getName(), "field4", obj);
// This should utilize the 'decimalOptional.format' layout specified in the rules file
assertEquals("101", w.format(101d));
w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(obj.getClass().getName(), "field9", obj);
// This should use the default layout, since no layout is specified in the rules file
assertEquals("101.00", w.format(101d));
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.
the class ExtensionTest method testMaxLengthOverride.
public void testMaxLengthOverride() {
log.debug("testMaxLengthOverride");
try {
Extension1 obj = new Extension1();
IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(obj.getClass().getName(), "field3", obj);
assertEquals(new Integer(20), w.getMaxLength());
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.
the class ExtensionTest method testLayout.
/*
Commenting out until AOP interceptors are finished
public void testMinValue() {
log.debug("testMinValue");
try {
Extension1 obj = createExtension1();
try {
obj.setField4(0.9);
obj.validate();
fail("The invocation Extension1.setField4(new Double(0.9)) should have failed since the minimum value is 1");
} catch (Exception e) {
BelowMinimumException appExp = (BelowMinimumException) ExceptionHelper.extractException(e, BelowMinimumException.class);
if (appExp == null)
throw e;
}
obj.setField4(1d);
obj.validate();
obj.setField4(1.1);
obj.validate();
try {
obj.setField5((long) -1);
obj.validate();
fail("The invocation Extension1.setField5(new Long(-1)) should have failed since the minimum value is 1");
} catch (Exception e) {
BelowMinimumException appExp = (BelowMinimumException) ExceptionHelper.extractException(e, BelowMinimumException.class);
if (appExp == null)
throw e;
}
obj.setField5(1L);
obj.validate();
obj.setField5(2L);
obj.validate();
try {
obj.setField6(Parser.parseDateOnly("t - 11"));
obj.validate();
fail("The invocation Extension1.setField6(new DateOnly(t - 11)) should have failed since the minimum value is 't-10'");
} catch (Exception e) {
// A custom ApplicationException is expected
ApplicationException appExp = (ApplicationException) ExceptionHelper.extractException(e, ApplicationException.class);
if (appExp == null)
throw e;
assertEquals("aCustomErrorMessageTokenForField6", appExp.getMessage());
// The cause for the custom ApplicationException should be a BelowMinimumException
assertTrue("The cause of the custom ApplicationException should be an instance of BelowMinimumException", appExp.getCause() != null && appExp.getCause() instanceof BelowMinimumException);
}
obj.setField6(Parser.parseDateOnly("t - 10"));
obj.validate();
obj.setField6(Parser.parseDateOnly("t - 9"));
obj.validate();
try {
obj.setField7(0);
obj.validate();
fail("The invocation Extension1.setField7(0) should have failed since the minimum value is 1");
} catch (Exception e) {
BelowMinimumException appExp = (BelowMinimumException) ExceptionHelper.extractException(e, BelowMinimumException.class);
if (appExp == null)
throw e;
}
obj.setField7(1);
obj.validate();
obj.setField7(2);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/*
Commenting out until AOP interceptors are finished
public void testMaxValue() {
log.debug("testMaxValue");
try {
Extension1 obj = createExtension1();
try {
obj.setField4(100.5);
obj.validate();
fail("The invocation Extension1.setField4(new Double(100.5)) should have failed since the maximum value is 100");
} catch (Exception e) {
ExceedsMaximumException appExp = (ExceedsMaximumException) ExceptionHelper.extractException(e, ExceedsMaximumException.class);
if (appExp == null)
throw e;
}
obj.setField4(100d);
obj.validate();
obj.setField4(99.5);
obj.validate();
try {
obj.setField5(101L);
obj.validate();
fail("The invocation Extension1.setField5(new Long(101)) should have failed since the maximum value is 100");
} catch (Exception e) {
ExceedsMaximumException appExp = (ExceedsMaximumException) ExceptionHelper.extractException(e, ExceedsMaximumException.class);
if (appExp == null)
throw e;
}
obj.setField5(100L);
obj.validate();
obj.setField5(99L);
obj.validate();
try {
obj.setField6(Parser.parseDateOnly("t + 1"));
obj.validate();
fail("The invocation Extension1.setField6(new DateOnly(t + 1)) should have failed since the maximum value is 't'");
} catch (Exception e) {
ExceedsMaximumException appExp = (ExceedsMaximumException) ExceptionHelper.extractException(e, ExceedsMaximumException.class);
if (appExp == null)
throw e;
}
obj.setField6(Parser.parseDateOnly("t"));
obj.validate();
obj.setField6(Parser.parseDateOnly("t - 1"));
obj.validate();
try {
obj.setField7(101);
obj.validate();
fail("The invocation Extension1.setField7(101) should have failed since the maximum value is 100");
} catch (Exception e) {
ExceedsMaximumException appExp = (ExceedsMaximumException) ExceptionHelper.extractException(e, ExceedsMaximumException.class);
if (appExp == null)
throw e;
}
obj.setField7(100);
obj.validate();
obj.setField7(99);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/*
Commenting out until AOP interceptors are finished
public void testInListDates() {
log.debug("testInListDates");
try {
Extension1 obj = createExtension1();
try {
obj.setField8(Parser.parseDateOnly("t+1"));
obj.validate();
fail("The invocation Extension1.setField8(t+1) 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.setField8(new DateOnly(2004, DateOnly.FEBRUARY, 15));
obj.validate();
obj.setField8(Parser.parseDateOnly("t"));
obj.validate();
obj.setField8(Parser.parseDateOnly("t-1"));
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/*
Commenting out until AOP interceptors are finished
public void testNumericalMinLength() {
log.debug("testNumericalMinLength");
try {
Extension1 obj = createExtension1();
try {
obj.setField9(1);
obj.validate();
fail("The invocation Extension1.setField9(1) should have failed since its less than the min-length");
} catch (Exception e) {
TooLittleDataException appExp = (TooLittleDataException) ExceptionHelper.extractException(e, TooLittleDataException.class);
if (appExp == null)
throw e;
}
try {
obj.setField9(10);
obj.validate();
fail("The invocation Extension1.setField9(10) should have failed since its less than the min-length");
} catch (Exception e) {
TooLittleDataException appExp = (TooLittleDataException) ExceptionHelper.extractException(e, TooLittleDataException.class);
if (appExp == null)
throw e;
}
obj.setField9(1000);
obj.validate();
obj.setField9(1001);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/*
Commenting out until AOP interceptors are finished
public void testNumericalMaxLength() {
log.debug("testNumericalMinLength");
try {
Extension1 obj = createExtension1();
try {
obj.setField9(100000);
obj.validate();
fail("The invocation Extension1.setField9(100000) should have failed since its greater than the max-length");
} catch (Exception e) {
TooMuchDataException appExp = (TooMuchDataException) ExceptionHelper.extractException(e, TooMuchDataException.class);
if (appExp == null)
throw e;
}
try {
obj.setField9(1000.001);
obj.validate();
fail("The invocation Extension1.setField9(1000.001) should have failed since its fractional part is greater than the max-length");
} catch (Exception e) {
TooMuchDataException appExp = (TooMuchDataException) ExceptionHelper.extractException(e, TooMuchDataException.class);
if (appExp == null)
throw e;
}
obj.setField9(10000);
obj.validate();
obj.setField9(1000.11);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/*
Commenting out until AOP interceptors are finished
public void testPattern() {
log.debug("testPattern");
try {
Extension1 obj = createExtension1();
try {
obj.setField3("xyz");
obj.validate();
fail("The invocation Extension1.setField3(xyz) should have failed since it does not match the pattern");
} catch (Exception e) {
PatternMismatchException appExp = (PatternMismatchException) ExceptionHelper.extractException(e, PatternMismatchException.class);
if (appExp == null)
throw e;
}
try {
obj.setField3("valuex");
obj.validate();
fail("The invocation Extension1.setField3(valuex) should have failed since it does not match the pattern");
} catch (Exception e) {
PatternMismatchException appExp = (PatternMismatchException) ExceptionHelper.extractException(e, PatternMismatchException.class);
if (appExp == null)
throw e;
}
try {
obj.setField3("value");
obj.validate();
fail("The invocation Extension1.setField3(value) should have failed since it does not match the pattern");
} catch (Exception e) {
PatternMismatchException appExp = (PatternMismatchException) ExceptionHelper.extractException(e, PatternMismatchException.class);
if (appExp == null)
throw e;
}
obj.setField3("value1");
obj.validate();
obj.setField3("value23");
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
public void testLayout() {
log.debug("testLayout");
try {
Extension1 obj = new Extension1();
IPropertyRuleIntrospector w = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(obj.getClass().getName(), "field4", obj);
assertEquals("[decimalOptional.format]", w.getLayout());
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.
the class ExtensionTest method createExtension1.
/*
Commenting out until AOP interceptors are finished
public void testGenericForeignKeyWithCondition() {
try {
Extension1 obj = createExtension1();
obj.setField1(null); // This will ensure that the generic-foreign-key validation is applied to Field10
try {
obj.setField10("ZZZ");
obj.validate();
fail("The invocation Extension1.setField10(ZZZ) should have failed since we passed an invalid generic-foreign-key");
} catch (Exception e) {
InvalidGenericForeignKeyException appExp = (InvalidGenericForeignKeyException) ExceptionHelper.extractException(e, InvalidGenericForeignKeyException.class);
if (appExp != null) {
Object[] arguments = appExp.getArguments();
assertNotNull("The InvalidGenericForeignKeyException should have arguments", arguments);
assertTrue("The InvalidGenericForeignKeyException should have arguments", arguments.length > 0);
assertEquals("The InvalidGenericForeignKeyException should have been created for field10", "field10", arguments[0]);
} else {
throw e;
}
}
obj.setField10("VALUEA11");
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/*
Commenting out until AOP interceptors are finished
public void testGenericForeignKey() {
try {
Extension1 obj = createExtension1();
try {
obj.setField11(10L);
obj.validate();
fail("The invocation Extension1.setField11(10) should have failed since we passed an invalid generic-foreign-key");
} catch (Exception e) {
InvalidGenericForeignKeyException appExp = (InvalidGenericForeignKeyException) ExceptionHelper.extractException(e, InvalidGenericForeignKeyException.class);
if (appExp != null) {
Object[] arguments = appExp.getArguments();
assertNotNull("The InvalidGenericForeignKeyException should have arguments", arguments);
assertTrue("The InvalidGenericForeignKeyException should have arguments", arguments.length > 0);
assertEquals("The InvalidGenericForeignKeyException should have been created for field11", "field11", arguments[0]);
} else {
throw e;
}
}
obj.setField11(1L);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
*/
/**
* Creates an Extension1 instance with valid data.
*/
private Extension1 createExtension1() {
Extension1 obj = new Extension1();
// set to at least 3 digits because of the min-length rule against this property
obj.setField9(123);
// set to at least 1 because of the min-value rule against this property
obj.setField7(1);
return obj;
}
use of org.jaffa.rules.testmodels.Extension1 in project jaffa-framework by jaffa-projects.
the class ExtensionTest method testCompositeForeignKey.
public void testCompositeForeignKey() {
try {
Extension1 obj = createExtension1();
try {
obj.setField10("KEY1");
obj.setField5(4L);
obj.validate();
} catch (Exception e) {
InvalidForeignKeyException appExp = (InvalidForeignKeyException) ExceptionHelper.extractException(e, InvalidForeignKeyException.class);
if (appExp != null) {
Object[] arguments = appExp.getArguments();
assertNotNull("The InvalidForeignKeyException should have arguments", arguments);
assertTrue("The InvalidForeignKeyException should have arguments", arguments.length > 0);
assertEquals("The InvalidForeignKeyException should have been created for field10,field5", "field10,field5", arguments[0]);
} else {
throw e;
}
}
// The following is a valid foreign-key and should work
obj.setField10("KEY1");
obj.setField5(3L);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
Aggregations