AbstractBundleHintProvider implements ComponentBundleHintProvider { @Override public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) { Map<Long, BundleHintsResponse> hintMap = new HashMap<>(); Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping( namespace.getId(), getServiceName()); for (NamespaceServiceClusterMap mapping : serviceMappings) { Long clusterId = mapping.getClusterId(); Cluster cluster = environmentService.getCluster(clusterId); if (cluster == null) { throw new RuntimeException(new ClusterNotFoundException(clusterId)); } BundleHintsResponse response = new BundleHintsResponse(cluster, getHintsOnCluster(cluster, securityContext, subject)); hintMap.put(clusterId, response); } return hintMap; }  @Override void init(EnvironmentService environmentService); @Override Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject); abstract Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject); abstract String getServiceName();  }
@Test public void testProvide() throws Exception { Cluster cluster1 = createDummyCluster(1L, "cluster1"); Cluster cluster2 = createDummyCluster(2L, "cluster2"); Cluster cluster3 = createDummyCluster(3L, "cluster3"); List<NamespaceServiceClusterMap> testServiceClusterMappings = createDummyServiceClusterMappings( Lists.newArrayList(cluster1, cluster2, cluster3)); new Expectations() {{ environmentService.getCluster(1L); result = cluster1; environmentService.getCluster(2L); result = cluster2; environmentService.getCluster(3L); result = cluster3; environmentService.listServiceClusterMapping(TEST_NAMESPACE_ID, TEST_SERVICE_NAME); result = testServiceClusterMappings; }}; Namespace namespace = new Namespace(); namespace.setId(TEST_NAMESPACE_ID); Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, null, null); Assert.assertEquals(3, hints.size()); Assert.assertEquals(cluster1, hints.get(cluster1.getId()).getCluster()); Assert.assertEquals(TEST_HINTS, hints.get(cluster1.getId()).getHints()); Assert.assertEquals(cluster2, hints.get(cluster2.getId()).getCluster()); Assert.assertEquals(TEST_HINTS, hints.get(cluster2.getId()).getHints()); Assert.assertEquals(cluster3, hints.get(cluster3.getId()).getCluster()); Assert.assertEquals(TEST_HINTS, hints.get(cluster3.getId()).getHints()); }