@Test
public void testGenerateNodeIdExisting() throws Exception {

    final String EXPECTED_NODE_ID = "100";
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(
            ParameterConstants.EXTERNAL_ID_IS_UNIQUE, "true"), new MockNodeService() {
        @Override
        public Node findNode(String nodeId) {
            if (nodeId.equals("100")) {
                Node node = new Node();
                node.setNodeId("100");
                return node;
            } else {
                return null;
            }
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    String selectedNodeId = generator.generateNodeId(node, null, null);
    
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}