RealNodeRepository implements NodeRepository { @Override public Optional<NodeSpec> getOptionalNode(String hostName) { try { NodeRepositoryNode nodeResponse = configServerApi.get("/nodes/v2/node/" + hostName, NodeRepositoryNode.class); return Optional.ofNullable(nodeResponse).map(RealNodeRepository::createNodeSpec); } catch (HttpException.NotFoundException | HttpException.ForbiddenException e) { return Optional.empty(); } } RealNodeRepository(ConfigServerApi configServerApi); @Override void addNodes(List<AddNode> nodes); @Override List<NodeSpec> getNodes(String baseHostName); @Override Optional<NodeSpec> getOptionalNode(String hostName); @Override Map<String, Acl> getAcls(String hostName); @Override void updateNodeAttributes(String hostName, NodeAttributes nodeAttributes); @Override void setNodeState(String hostName, NodeState nodeState); static NodeRepositoryNode nodeRepositoryNodeFromNodeAttributes(NodeAttributes nodeAttributes);  }
@Test public void testGetContainer() { String hostname = "host4.yahoo.com"; Optional<NodeSpec> node = nodeRepositoryApi.getOptionalNode(hostname); assertTrue(node.isPresent()); assertEquals(hostname, node.get().hostname()); }
@Test public void testGetContainerForNonExistingNode() { String hostname = "host-that-does-not-exist"; Optional<NodeSpec> node = nodeRepositoryApi.getOptionalNode(hostname); assertFalse(node.isPresent()); }