### Question:
RemoteAmbariCluster implements Cluster { @Override public String getConfigurationValue(String type, String key) { JsonElement config = null; try { String desiredTag = getDesiredConfig(type); if (desiredTag != null) { config = configurationCache.get(String.format("%s/configurations?(type=%s&tag=%s)",this.clusterPath, type, desiredTag)); } } catch (ExecutionException e) { throw new RemoteAmbariConfigurationReadException("Can't retrieve configuration from Remote Ambari", e); } if (config == null || !config.isJsonObject()) return null; JsonElement items = config.getAsJsonObject().get("items"); if (items == null || !items.isJsonArray()) return null; JsonElement item = items.getAsJsonArray().get(0); if (item == null || !item.isJsonObject()) return null; JsonElement properties = item.getAsJsonObject().get("properties"); if (properties == null || !properties.isJsonObject()) return null; JsonElement property = properties.getAsJsonObject().get(key); if (property == null || !property.isJsonPrimitive()) return null; return property.getAsJsonPrimitive().getAsString(); } RemoteAmbariCluster(RemoteAmbariClusterEntity remoteAmbariClusterEntity, Configuration config);  RemoteAmbariCluster(String name, String clusterPath, AmbariStreamProvider streamProvider); @Override String getName(); @Override String getConfigurationValue(String type, String key); @Override Map<String, String> getConfigByType(String type); @Override List<String> getHostsForServiceComponent(String serviceName, String componentName); Set<String> getServices(); boolean isAmbariOrClusterAdmin(); static final String AMBARI_OR_CLUSTER_ADMIN; }### Answer:
@Test public void testGetConfigurationValue() throws Exception { AmbariStreamProvider clusterStreamProvider = createNiceMock(AmbariStreamProvider.class); final String desiredConfigsString = "{\"Clusters\": {\"desired_configs\": {\"test-site\": {\"tag\": \"TAG\"}}}}"; final String configurationString = "{\"items\": [{\"properties\": {\"test.property.name\": \"test property value\"}}]}"; final int[] desiredConfigPolls = {0}; final int[] testConfigPolls = {0}; final String clusterPath = "/api/v1/clusters/Test"; expect(clusterStreamProvider.readFrom(eq( clusterPath + "?fields=services/ServiceInfo,hosts,Clusters"), eq("GET"), (String) isNull(), EasyMock.anyObject())).andAnswer(new IAnswer<InputStream>() { @Override public InputStream answer() throws Throwable { desiredConfigPolls[0] += 1; return new ByteArrayInputStream(desiredConfigsString.getBytes()); } }).anyTimes(); expect(clusterStreamProvider.readFrom(eq(clusterPath + "/configurations?(type=test-site&tag=TAG)"), eq("GET"), (String)isNull(), EasyMock.anyObject())).andAnswer(new IAnswer<InputStream>() { @Override public InputStream answer() throws Throwable { testConfigPolls[0] += 1; return new ByteArrayInputStream(configurationString.getBytes()); } }).anyTimes(); RemoteAmbariClusterEntity entity = createNiceMock(RemoteAmbariClusterEntity.class); replay(clusterStreamProvider,entity); RemoteAmbariCluster cluster = new RemoteAmbariCluster("Test", clusterPath, clusterStreamProvider); String value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 1); assertEquals(testConfigPolls[0], 1); value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 1); assertEquals(testConfigPolls[0], 1); }