List of usage examples for org.springframework.restdocs.constraints Constraint getName
public String getName()
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. j a v a 2 s.c om*/ 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" })); }
From source file:capital.scalable.restdocs.constraints.SkippableConstraintResolver.java
private boolean isSkippable(Constraint constraint) { return skippableConstraints.contains(constraint.getName()); }
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()))); }/* ww w . jav a2 s.co m*/ 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. jav a2 s . c om*/ return result; }
From source file:capital.scalable.restdocs.constraints.ConstraintAndGroupDescriptionResolver.java
@Override public String resolveDescription(Constraint constraint) { String constraintDescription = trimToEmpty(resolvePlainDescription(constraint)); if (isBlank(constraintDescription)) { constraintDescription = constraint.getName(); }/* w ww .j a va2 s .com*/ List<Class> groups = getGroups(constraint); if (groups.isEmpty()) { return constraintDescription; } StringBuilder result = new StringBuilder(); for (Class group : groups) { result.append(", "); result.append(trimToEmpty(resolveGroupDescription(group, constraintDescription))); } result.replace(0, 2, ""); return result.toString(); }
From source file:capital.scalable.restdocs.constraints.ConstraintAndGroupDescriptionResolver.java
private String resolvePlainDescription(Constraint constraint) { try {//from w w w . j a va 2 s .co m return delegate.resolveDescription(constraint); } catch (MissingResourceException e) { log.warn("No description found for constraint {}: {}", constraint.getName(), e.getMessage()); return ""; } }