@Test public void testParsing() { String property = "orders[3].deliveryAddress.addressline[1]"; Path path = PathImpl.createPathFromString(property); Iterator<Path.Node> propIter = path.iterator(); assertTrue(propIter.hasNext()); Path.Node elem = propIter.next(); assertEquals(elem.getName(), "orders"); assertFalse(elem.isInIterable()); assertTrue(propIter.hasNext()); elem = propIter.next(); assertEquals(elem.getName(), "deliveryAddress"); assertTrue(elem.isInIterable()); assertEquals(elem.getIndex(), new Integer(3)); assertTrue(propIter.hasNext()); elem = propIter.next(); assertEquals(elem.getName(), "addressline"); assertFalse(elem.isInIterable()); assertTrue(propIter.hasNext()); elem = propIter.next(); assertEquals(elem.getName(), null); assertTrue(elem.isInIterable()); assertEquals(elem.getIndex(), new Integer(1)); assertFalse(propIter.hasNext()); assertEquals(path.toString(), property); }
@Test public void testParseMapBasedProperty() { String property = "order[foo].deliveryAddress"; Path path = PathImpl.createPathFromString(property); Iterator<Path.Node> propIter = path.iterator(); assertTrue(propIter.hasNext()); Path.Node elem = propIter.next(); assertEquals("order", elem.getName()); assertFalse(elem.isInIterable()); assertTrue(propIter.hasNext()); elem = propIter.next(); assertEquals("deliveryAddress", elem.getName()); assertTrue(elem.isInIterable()); assertEquals("foo", elem.getKey()); assertFalse(propIter.hasNext()); }
@Test public void testNonStringMapKey() { Validator validator = ValidatorUtil.getValidator(); Container container = new Container(); Key id = new Key(); container.addItem(id, new Item(null)); Set<ConstraintViolation<Container>> constraintViolations = validator.validate(container); assertNumberOfViolations(constraintViolations, 1); ConstraintViolation<Container> violation = constraintViolations.iterator().next(); Path path = violation.getPropertyPath(); Iterator<Path.Node> iter = path.iterator(); iter.next(); Path.Node node = iter.next(); assertNotNull(node); assertTrue(node.isInIterable()); assertEquals(node.getKey(), id); }