JmxConnectionFactory { public Optional<JmxCredentials> getJmxCredentialsForCluster(Optional<Cluster> cluster) { JmxCredentials credentials = cluster.flatMap(Cluster::getJmxCredentials).orElse(null); String clusterName = cluster.map(Cluster::getName).orElse(""); if (credentials == null && jmxCredentials != null) { if (jmxCredentials.containsKey(clusterName)) { credentials = jmxCredentials.get(clusterName); } else if (jmxCredentials.containsKey(Cluster.toSymbolicName(clusterName))) { credentials = jmxCredentials.get(Cluster.toSymbolicName(clusterName)); } } if (credentials == null && jmxAuth != null) { credentials = jmxAuth; } return Optional.ofNullable(credentials); } JmxConnectionFactory(AppContext context, Cryptograph cryptograph); @VisibleForTesting final JmxProxy connectAny(Collection<Node> nodes); final void setJmxAuth(JmxCredentials jmxAuth); final void setJmxCredentials(Map<String, JmxCredentials> jmxCredentials); final void setJmxPorts(Map<String, Integer> jmxPorts); final void setAddressTranslator(AddressTranslator addressTranslator); Jmxmp getJmxmp(); void setJmxmp(Jmxmp jmxmp); final HostConnectionCounters getHostConnectionCounters(); final Set<String> getAccessibleDatacenters(); Optional<JmxCredentials> getJmxCredentialsForCluster(Optional<Cluster> cluster);  }
@Test public void fetchingJmxCredentialsIsntPresentWhenNotDefinedAnywhere() { Cluster cluster = Cluster.builder().withName("FooCluster") .withSeedHosts(ImmutableSet.of("127.0.0.1")).build(); JmxConnectionFactory connectionFactory = new JmxConnectionFactory(mock(AppContext.class), mock(Cryptograph.class)); Optional<JmxCredentials> jmxCredentials = connectionFactory.getJmxCredentialsForCluster(Optional.of(cluster)); assertFalse(jmxCredentials.isPresent()); }