try { Class<?> beanClazz = violation.getRootBeanClass(); final Iterator<Path.Node> iter = violation.getPropertyPath().iterator(); while (iter.hasNext()) { Path.Node next = iter.next();
private Path.Node getLeafNode(ConstraintViolation<?> constraintViolation) { Iterator<Path.Node> nodes = constraintViolation.getPropertyPath().iterator(); Path.Node leafNode = null; while ( nodes.hasNext() ) { leafNode = nodes.next(); } return leafNode; } }
Iterator<Node> nodes = v.getPropertyPath().iterator(); Node firstNode = nodes.next(); if (firstNode.getKind() == ElementKind.METHOD)
private Path.Node getLeafNode(final ConstraintViolation<?> constraintViolation) { final Iterator<Path.Node> nodes = constraintViolation.getPropertyPath().iterator(); Path.Node leafNode = null; while (nodes.hasNext()) { leafNode = nodes.next(); } return leafNode; } }
private Path.Node getLeafNode(ConstraintViolation<?> constraintViolation) { Iterator<Path.Node> nodes = constraintViolation.getPropertyPath().iterator(); Path.Node leafNode = null; while ( nodes.hasNext() ) { leafNode = nodes.next(); } return leafNode; } }
private Path.Node getLeafNode(final ConstraintViolation<?> constraintViolation) { final Iterator<Path.Node> nodes = constraintViolation.getPropertyPath().iterator(); Path.Node leafNode = null; while (nodes.hasNext()) { leafNode = nodes.next(); } return leafNode; } }
static Node findLastNonEmptyPathNode(final Path path) { Node found = null; final List<Node> list = newArrayList(path.iterator()); Collections.reverse(list); for (final Node node : list) { if (!isEmpty(node.getName())) { found = node; break; } } return found; }
public static String getParameterName(Path path) { Iterator<Node> nodes = path.iterator(); assertTrue( nodes.hasNext() ); nodes.next(); assertTrue( nodes.hasNext() ); return nodes.next().getName(); }
private String getFieldNameFromConstraint(ConstraintViolation<Object> constraintViolation, boolean includeNested) { if (includeNested) { return constraintViolation.getPropertyPath().toString().replace(".", "_"); } return constraintViolation.getPropertyPath().iterator().next().getName(); } }
private List<String> extractNodeName(Path path) { LinkedList<String> names = new LinkedList<String>(); Iterator<Path.Node> iter = path.iterator(); while ( iter.hasNext() ) { names.add( iter.next().getName() ); } return names; } }
static Node findLastNonEmptyPathNode(final Path path) { Node found = null; final List<Node> list = newArrayList(path.iterator()); Collections.reverse(list); for (final Node node : list) { if (!isEmpty(node.getName())) { found = node; break; } } return found; }
private Node findLastNonEmptyPathNode(Path path) { List<Node> list = new ArrayList<>(); for (Iterator<Node> it = path.iterator(); it.hasNext(); ) { list.add(it.next()); } Collections.reverse(list); for (Node node : list) { if (!isEmpty(node.getName())) { return node; } } return null; }
private void checkActorViolations(Set<ConstraintViolation<Actor>> constraintViolations) { assertNumberOfViolations( constraintViolations, 1 ); ConstraintViolation<Actor> constraintViolation = constraintViolations.iterator().next(); Iterator<Path.Node> nodeIter = constraintViolation.getPropertyPath().iterator(); assertTrue( nodeIter.hasNext() ); assertNode( nodeIter.next(), "playedWith", ElementKind.PROPERTY, false, null, null ); assertTrue( nodeIter.hasNext() ); assertNode( nodeIter.next(), "playedWith", ElementKind.PROPERTY, true, 0, null ); assertTrue( nodeIter.hasNext() ); assertNode( nodeIter.next(), "lastName", ElementKind.PROPERTY, true, 1, null ); assertFalse( nodeIter.hasNext() ); }
@Test(expectedExceptions = ClassCastException.class) @SpecAssertion(section = Sections.VALIDATIONAPI_CONSTRAINTVIOLATION, id = "s") public void testPassingWrongTypeToAsOnBeanNodeCausesClassCastException() { Set<ConstraintViolation<VerySpecialClass>> constraintViolations = getValidator().validate( new VerySpecialClass() ); assertNumberOfViolations( constraintViolations, 1 ); ConstraintViolation<VerySpecialClass> constraintViolation = constraintViolations.iterator().next(); Iterator<Path.Node> nodeIter = constraintViolation.getPropertyPath().iterator(); assertTrue( nodeIter.hasNext() ); Node node = nodeIter.next(); assertNode( node, BEAN_NODE_NAME, ElementKind.BEAN, false, null, null ); node.as( PropertyNode.class ); }
@Test public void testBlankUsername() { final User blankUser = mock(User.class); when(blankUser.getIdentifier()).thenReturn(""); final Set<ConstraintViolation<User>> violations1 = new UserValidatorTestImpl().validate(blankUser); assertTrue(violations1.size() == 1); final ConstraintViolation<User> violation = violations1.iterator().next(); assertEquals(violation.getPropertyPath().iterator().next().getName(), "identifier"); assertEquals(violation.getMessage(), UserValidator.KEY_NAME_NOT_EMPTY); }
@Test public void testBlankUsername() { final User blankUser = mock(User.class); when(blankUser.getIdentifier()).thenReturn(""); final Set<ConstraintViolation<User>> violations1 = new UserValidatorTestImpl().validate(blankUser); assertTrue(violations1.size() == 1); final ConstraintViolation<User> violation = violations1.iterator().next(); assertEquals(violation.getPropertyPath().iterator().next().getName(), "identifier"); assertEquals(violation.getMessage(), UserValidator.KEY_NAME_NOT_EMPTY); }
@Test public void testBlankGroupName() { final Group blankGroup = mock(Group.class); when(blankGroup.getName()).thenReturn(""); final Set<ConstraintViolation<Group>> violations1 = new GroupValidatorTestImpl().validate(blankGroup); assertTrue(violations1.size() == 1); final ConstraintViolation<Group> violation = violations1.iterator().next(); assertEquals(violation.getPropertyPath().iterator().next().getName(), "name"); assertEquals(violation.getMessage(), GroupValidator.KEY_NAME_NOT_EMPTY); }
@Test public void testBlankGroupName() { final Group blankGroup = mock(Group.class); when(blankGroup.getName()).thenReturn(""); final Set<ConstraintViolation<Group>> violations1 = new GroupValidatorTestImpl().validate(blankGroup); assertTrue(violations1.size() == 1); final ConstraintViolation<Group> violation = violations1.iterator().next(); assertEquals(violation.getPropertyPath().iterator().next().getName(), "name"); assertEquals(violation.getMessage(), GroupValidator.KEY_NAME_NOT_EMPTY); }