MapValueConstraint extends AbstractMapConstraint { public static ConstraintBuilder<Object[]> builderWith(final ConstraintFactory<?> cstFactory) { return new BasicConstraintBuilder<Object[]>(TypeTag, MapValueConstraint.class, Docs, VALUE_TYPE, CONSTRAINT_ID) { public Collection<Constraint<?>> constraintsFrom(Type type, boolean nullsAllowed, Map<String, String> values) { ConstraintBuilder<?> cb = builderFor(cstFactory, values, VALUE_TYPE); if (cb == null) return null; Collection<Constraint<?>> constraints = cb.constraintsFrom(null, nullsAllowed, values); if (constraints == null || constraints.isEmpty()) return null; return withExtras(new MapValueConstraint("", nullsAllowed, (ValueConstraint<?>)constraints.iterator().next()), values); } }; } MapValueConstraint(String theId, boolean nullAllowed, ValueConstraint<?> theConstraint); static ConstraintBuilder<Object[]> builderWith(final ConstraintFactory<?> cstFactory); @Override String typeTag(); static final String TypeTag; static final String Docs; static final StringParameter VALUE_TYPE; }
@Test public void testMapValueConstraintBuilder() { Map<String,String> paramsByKey = asParams( MapValueConstraint.VALUE_TYPE, "string", AbstractMapConstraint.CONSTRAINT_ID, StringLengthConstraint.TypeTag, StringLengthConstraint.MIN_LENGTH, 3); Collection<Constraint<?>> vcs = MapValueConstraint.builderWith(AvroConfiguration.ConstraintFactory).constraintsFrom(Type.MAP, false, paramsByKey); assertNotNull(vcs); assertEquals(vcs.size(), 1); }