DefaultNodeIdCreator implements INodeIdCreator, IBuiltInExtensionPoint { public String selectNodeId(Node node, String remoteHost, String remoteAddress) { String nodeId = node.getNodeId(); if (StringUtils.isBlank(nodeId)) { nodeId = evaluateScript(node, remoteHost, remoteAddress); } if (StringUtils.isBlank(nodeId)) { String defaultNodeId = buildNodeId(nodeService, node); if (parameterService.is(ParameterConstants.EXTERNAL_ID_IS_UNIQUE)) { nodeId = defaultNodeId; } else { final int maxTries = parameterService.getInt(ParameterConstants.NODE_ID_CREATOR_MAX_NODES, 100); String checkNodeId = defaultNodeId; for (int sequence = 0; sequence < maxTries; sequence++) { NodeSecurity security = nodeService.findNodeSecurity(checkNodeId); if (security != null && security.isRegistrationEnabled()) { nodeId = checkNodeId; break; } checkNodeId = defaultNodeId + "-" + sequence; } } } return nodeId; } DefaultNodeIdCreator(IParameterService parameterService, INodeService nodeService, ISecurityService securityService); String selectNodeId(Node node, String remoteHost, String remoteAddress); String generateNodeId(Node node, String remoteHost, String remoteAddress); String generatePassword(Node node);  }
@Test public void testSelectNodeId() throws Exception { final String EXPECTED_NODE_ID = "100-2"; DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(), new MockNodeService() { @Override public NodeSecurity findNodeSecurity(String nodeId) { if (nodeId.equals(EXPECTED_NODE_ID)) { NodeSecurity security = new NodeSecurity(); security.setNodeId(EXPECTED_NODE_ID); security.setRegistrationEnabled(true); return security; } else { return null; } } }, SecurityServiceFactory.create()); Node node = new Node(); node.setExternalId("100"); String selectedNodeId = generator.selectNodeId(node, null, null); assertEquals(EXPECTED_NODE_ID, selectedNodeId); }
@Test public void testSelectNodeIdWithNodeIdSet() throws Exception { DefaultNodeIdCreator generator = new DefaultNodeIdCreator(new MockParameterService(), new MockNodeService(), SecurityServiceFactory.create()); Node node = new Node(); final String EXPECTED_NODE_ID = "10001"; node.setExternalId(EXPECTED_NODE_ID); node.setNodeId(EXPECTED_NODE_ID); String selectedNodeId = generator.selectNodeId(node, null, null); assertEquals(EXPECTED_NODE_ID, selectedNodeId); }