NameValidator extends DefaultValidator { @Override public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException { if (!NodeStateUtils.isHidden(name)) { checkValidName(name); } return this; } NameValidator(NodeState namespaces, boolean initPhase); @Override void propertyAdded(PropertyState after); @Override void propertyChanged(PropertyState before, PropertyState after); @Override void propertyDeleted(PropertyState before); @Override Validator childNodeAdded(String name, NodeState after); @Override Validator childNodeChanged(
            String name, NodeState before, NodeState after); @Override Validator childNodeDeleted(String name, NodeState before);  }
@Test(expected = CommitFailedException.class) public void testCurrentPath() throws CommitFailedException { validator.childNodeAdded(".", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testParentPath() throws CommitFailedException { validator.childNodeAdded("..", EMPTY_NODE); }
@Test public void testEmptyPrefix() throws CommitFailedException { validator.childNodeAdded(":name", EMPTY_NODE); }
@Test public void testInvalidPrefixInitial() throws CommitFailedException { Validator validator = new NameValidator(newNamespaceNode("valid"), true); validator.childNodeAdded("invalid:name", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testInvalidPrefix() throws CommitFailedException { Validator validator = new NameValidator(newNamespaceNode("valid"), false); validator.childNodeAdded("invalid:name", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testTrailingWhitespace() throws CommitFailedException { validator.childNodeAdded("name ", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testLeadingWhitespace() throws CommitFailedException { validator.childNodeAdded(" name", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testOnlyWhitespace() throws CommitFailedException { validator.childNodeAdded(" ", EMPTY_NODE); }
@Test public void testValidPrefix() throws CommitFailedException { validator.childNodeAdded("valid:name", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testSlashName() throws CommitFailedException { validator.childNodeAdded("invalid/name", EMPTY_NODE); }
@Test public void testValidIndexInName() throws CommitFailedException { validator.childNodeAdded("name[1]", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testInvalidIndexInName() throws CommitFailedException { validator.childNodeAdded("name[x]", EMPTY_NODE); }
@Test public void testValidName() throws CommitFailedException { validator.childNodeAdded("name", EMPTY_NODE); }
@Test(expected = CommitFailedException.class) public void testNameWithLineBreaks() throws Exception{ validator.childNodeAdded("name\tx", EMPTY_NODE); }
@Test public void testTransientNs() throws CommitFailedException { NodeBuilder builder = newNamespaceNode("valid").builder(); builder.setProperty("testNVT", "testuri"); Validator validator = new NameValidator(builder.getNodeState(), false); validator.childNodeAdded("testNVT:test", EMPTY_NODE); }