### Question:
StackConfigTypeValidator implements TopologyValidator { @Override public void validate(ClusterTopology topology) throws InvalidTopologyException { Set<String> incomingConfigTypes = new HashSet<>(topology.getConfiguration().getAllConfigTypes()); if (incomingConfigTypes.isEmpty()) { LOGGER.debug("No config types to be checked."); return; } Set<String> stackConfigTypes = new HashSet<>(topology.getBlueprint().getStack().getConfiguration().getAllConfigTypes()); incomingConfigTypes.removeAll(stackConfigTypes); if (!incomingConfigTypes.isEmpty()) { String message = String.format("The following config types are not defined in the stack: %s ", incomingConfigTypes); LOGGER.error(message); throw new InvalidTopologyException(message); } } StackConfigTypeValidator(); @Override void validate(ClusterTopology topology);  }### Answer:
@Test(expected = InvalidTopologyException.class) public void testShouldValidationFailWhenUnknownConfigTypeComesIn() throws Exception { EasyMock.expect(stackMock.getConfiguration()).andReturn(stackConfigurationMock); EasyMock.expect(stackConfigurationMock.getAllConfigTypes()).andReturn(new HashSet<>(Arrays.asList("core-site", "yarn-site"))); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(new HashSet<>(Arrays.asList("invalid-site"))); replayAll(); stackConfigTypeValidator.validate(clusterTopologyMock); }
@Test public void testShouldValidationPassifNoConfigTypesomeIn() throws Exception { EasyMock.expect(stackMock.getConfiguration()).andReturn(stackConfigurationMock); EasyMock.expect(stackConfigurationMock.getAllConfigTypes()).andReturn(new HashSet<>(Arrays.asList("core-site", "yarn-site"))); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(new HashSet<>(Collections.emptyList())); replayAll(); stackConfigTypeValidator.validate(clusterTopologyMock); }
@Test(expected = InvalidTopologyException.class) public void testShouldValidationFailIfMultipleInvalidConfigTypesComeIn() throws Exception { EasyMock.expect(stackMock.getConfiguration()).andReturn(stackConfigurationMock); EasyMock.expect(stackConfigurationMock.getAllConfigTypes()).andReturn(new HashSet<>(Arrays.asList("core-site", "yarn-site"))); EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(new HashSet<>(Arrays.asList("invalid-site-1", "invalid-default"))); replayAll(); stackConfigTypeValidator.validate(clusterTopologyMock); }