List of usage examples for org.springframework.restdocs.constraints Constraint getConfiguration
public Map<String, Object> getConfiguration()
From source file:capital.scalable.restdocs.constraints.ConstraintAndGroupDescriptionResolver.java
@Override public List<Class> getGroups(Constraint constraint) { Object rawGroups = constraint.getConfiguration().get(GROUPS); if (!(rawGroups instanceof Class[])) { return emptyList(); }/* w ww . j av a 2 s. c o m*/ Class[] groups = (Class[]) rawGroups; List<Class> result = new ArrayList<>(); Collections.addAll(result, groups); return result; }
From source file:capital.scalable.restdocs.constraints.HumanReadableConstraintResolver.java
@Override public List<Constraint> resolveForParameter(MethodParameter param) { List<Constraint> result = new ArrayList<>(); for (Constraint constraint : delegate.resolveForParameter(param)) { result.add(new Constraint(constraint.getName(), extendConfiguration(constraint.getConfiguration()))); }/*w w w . j a v a 2s .c om*/ return result; }
From source file:capital.scalable.restdocs.constraints.HumanReadableConstraintResolver.java
@Override public List<Constraint> resolveForProperty(String property, Class<?> clazz) { List<Constraint> result = new ArrayList<>(); for (Constraint constraint : delegate.resolveForProperty(property, clazz)) { result.add(new Constraint(constraint.getName(), extendConfiguration(constraint.getConfiguration()))); }//from ww w .j av a 2 s .c om return result; }
From source file:capital.scalable.restdocs.constraints.MethodParameterValidatorConstraintResolverTest.java
@Test public void resolveConstraints() throws NoSuchMethodException { MethodParameterConstraintResolver resolver = new MethodParameterValidatorConstraintResolver(); Method method = ConstraintTest.class.getMethod("method", Long.class, String.class); List<Constraint> constraints = resolver.resolveForParameter(new MethodParameter(method, 0)); assertThat(constraints.size(), is(2)); Constraint constraint = constraints.get(0); assertThat(constraint.getName(), is(NotNull.class.getName())); Map<String, Object> config = constraint.getConfiguration(); assertThat(config.size(), is(3)); // default ones constraint = constraints.get(1);//from w w w . ja v a 2 s. c o m assertThat(constraint.getName(), is(Min.class.getName())); config = constraint.getConfiguration(); assertThat(config.size(), is(4)); // +value assertThat(config.get("value"), is((Object) 1L)); assertThat(config.get("groups"), is((Object) new Object[] { Create.class })); constraints = resolver.resolveForParameter(new MethodParameter(method, 1)); assertThat(constraints.size(), is(2)); constraint = constraints.get(0); assertThat(constraint.getName(), is(NotBlank.class.getName())); config = constraint.getConfiguration(); assertThat(config.size(), is(3)); // default ones constraint = constraints.get(1); assertThat(constraint.getName(), is(OneOf.class.getName())); config = constraint.getConfiguration(); assertThat(config.size(), is(4)); // +value assertThat(config.get("value"), is((Object) new Object[] { "one", "two", "three" })); }