### Question:
ClusterConfigTypeValidator implements TopologyValidator { @Override public void validate(ClusterTopology topology) throws InvalidTopologyException { Set<String> topologyClusterConfigTypes = new HashSet(topology.getConfiguration().getAllConfigTypes()); LOGGER.debug("Cluster config types: {}", topologyClusterConfigTypes); if (topologyClusterConfigTypes.isEmpty()) { LOGGER.debug("No config types to be checked."); return; } Set<String> stackServiceConfigTypes = new HashSet<>(); for (String serviceName : topology.getBlueprint().getServices()) { stackServiceConfigTypes.addAll(topology.getBlueprint().getStack().getConfigurationTypes(serviceName)); } Set<String> configTypeIntersection = new HashSet<>(topologyClusterConfigTypes); if (configTypeIntersection.retainAll(stackServiceConfigTypes)) { Set<String> invalidConfigTypes = new HashSet<>(topologyClusterConfigTypes); invalidConfigTypes.removeAll(configTypeIntersection); LOGGER.error("The following config typess are wrong: {}", invalidConfigTypes); throw new InvalidTopologyException("The following configuration types are invalid: " + invalidConfigTypes); } }  @Override void validate(ClusterTopology topology);  }### Answer:
@Test public void testShouldValidationPassWhenNoConfigTypesSpecifiedInCCTemplate() throws Exception { clusterRequestConfigTypes = Collections.emptySet(); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); replayAll(); clusterConfigTypeValidator.validate(clusterTopologyMock); }
@Test public void testShouldValidationPassWhenAllConfigTypesAreValid() throws Exception { clusterRequestConfigTypes = new HashSet<>(Arrays.asList("core-site", "yarn-site")); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<>(Arrays.asList("YARN", "HDFS"))); EasyMock.expect(stackMock.getConfigurationTypes("HDFS")).andReturn( Collections.singletonList("core-site")); EasyMock.expect(stackMock.getConfigurationTypes("YARN")).andReturn( Collections.singletonList("yarn-site")); replayAll(); clusterConfigTypeValidator.validate(clusterTopologyMock); }
@Test(expected = InvalidTopologyException.class) public void testShouldValidationFailWhenInvalidConfigGroupsSpecifiedInCCTemplate() throws Exception { clusterRequestConfigTypes = new HashSet<>(Collections.singletonList("oozie-site")); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<>(Arrays.asList("YARN", "HDFS"))); EasyMock.expect(stackMock.getConfigurationTypes("HDFS")).andReturn( Collections.singletonList("core-site")); EasyMock.expect(stackMock.getConfigurationTypes("YARN")).andReturn( Collections.singletonList("yarn-site")); replayAll(); clusterConfigTypeValidator.validate(clusterTopologyMock); }
@Test(expected = InvalidTopologyException.class) public void testShouldValidationFailWhenThereIsAnInvalidConfigGroupProvided() throws Exception { clusterRequestConfigTypes = new HashSet<>(Arrays.asList("core-site", "yarn-site", "oozie-site")); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<>(Arrays.asList("YARN", "HDFS"))); EasyMock.expect(stackMock.getConfigurationTypes("HDFS")).andReturn( Collections.singletonList("core-site")); EasyMock.expect(stackMock.getConfigurationTypes("YARN")).andReturn( Collections.singletonList("yarn-site")); replayAll(); clusterConfigTypeValidator.validate(clusterTopologyMock); }