@Override protected String internalVerifierRule(ConstraintConfiguration config, Map<String, Object> context) { List<String> constraints = new ArrayList<String>(); constraints.add("valueType != Field.INT"); return this.createVerifierRuleTemplate(config, context, "Integer_Field_Constraint", constraints, "The value must be an integer"); //I18N }
public Constraint buildConstraint(ConstraintConfiguration config) { if (NotNullConstraint.NAME.equals(config.getConstraintName())) { return new NotNullConstraint(); } else if (IntegerConstraint.NAME.equals(config.getConstraintName())) { return new IntegerConstraint(); } else if (RangeConstraint.NAME.equals(config.getConstraintName())) { return new RangeConstraint(); } else if (NotMatchesConstraint.NAME.equals(config.getConstraintName())) { return new NotMatchesConstraint(); }else if (MatchesConstraint.NAME.equals(config.getConstraintName())) { return new MatchesConstraint(); }else if (InvalidFieldConstraint.NAME.equals(config.getConstraintName())) { return new InvalidFieldConstraint(); }else if (MandatoryFieldConstraint.NAME.equals(config.getConstraintName())) { return new MandatoryFieldConstraint(); } else { throw new IllegalArgumentException("Constraint unknown: " + config.getConstraintName()); } }
public Constraint buildConstraint(ConstraintConfiguration config) { if (NotNullConstraint.NAME.equals(config.getConstraintName())) { return new NotNullConstraint(); } else if (IntegerConstraint.NAME.equals(config.getConstraintName())) { return new IntegerConstraint(); } else if (RangeConstraint.NAME.equals(config.getConstraintName())) { return new RangeConstraint(); } else if (NotMatchesConstraint.NAME.equals(config.getConstraintName())) { return new NotMatchesConstraint(); }else if (MatchesConstraint.NAME.equals(config.getConstraintName())) { return new MatchesConstraint(); }else if (InvalidFieldConstraint.NAME.equals(config.getConstraintName())) { return new InvalidFieldConstraint(); }else if (MandatoryFieldConstraint.NAME.equals(config.getConstraintName())) { return new MandatoryFieldConstraint(); } else { throw new IllegalArgumentException("Constraint unknown: " + config.getConstraintName()); } }
@Test public void testValidConstraint() { Constraint cons = new IntegerConstraint(); ValidationResult result = cons.validate(12, conf); assertTrue(result.isSuccess()); result = cons.validate(new Integer("12"), conf); assertTrue(result.isSuccess()); result = cons.validate("12", conf); assertTrue(result.isSuccess()); }
@Override protected String internalVerifierRule(ConstraintConfiguration config, Map<String, Object> context) { List<String> constraints = new ArrayList<String>(); constraints.add("valueType != Field.INT"); return this.createVerifierRuleTemplate(config, context, "Integer_Field_Constraint", constraints, "The value must be an integer"); //I18N }
@Test public void testInvalidConstraint() { Constraint cons = new IntegerConstraint(); ValidationResult result = cons.validate(new Object(), conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); result = cons.validate("", conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); result = cons.validate("ABC", conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); result = cons.validate(null, conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); result = cons.validate(new Long("12"), conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); result = cons.validate(12L, conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); result = cons.validate(12.8, conf); assertFalse(result.isSuccess()); System.out.println("Message: " + result.getMessage()); }
Constraint cons = new IntegerConstraint(); vconf.getVerifyingResources().put(ResourceFactory.newByteArrayResource(cons.getVerifierRule(conf).getBytes()), ResourceType.DRL);