### Question:
CmTemplateValidator implements BlueprintValidator { @Override public void validate(Blueprint blueprint, Set<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups, boolean validateServiceCardinality) { CmTemplateProcessor templateProcessor = processorFactory.get(blueprint.getBlueprintText()); Map<String, InstanceCount> blueprintHostGroupCardinality = templateProcessor.getCardinalityByHostGroup(); BlueprintValidatorUtil.validateHostGroupsMatch(hostGroups, blueprintHostGroupCardinality.keySet()); BlueprintValidatorUtil.validateInstanceGroups(hostGroups, instanceGroups); if (validateServiceCardinality) { BlueprintValidatorUtil.validateHostGroupCardinality(hostGroups, blueprintHostGroupCardinality); } }  @Override void validate(Blueprint blueprint, Set<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups,
        boolean validateServiceCardinality); @Override void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment);  }### Answer:
@Test public void validWithZeroComputeNodesWhenCardinalityUnspecified() { Blueprint blueprint = new Blueprint(); blueprint.setBlueprintText(FileReaderUtils.readFileFromClasspathQuietly("input/cdp-data-mart-no-cardinality.bp")); Set<HostGroup> hostGroups = Set.of( hostGroup("master", 1), hostGroup("worker", 3), hostGroup("compute", 0) ); Collection<InstanceGroup> instanceGroups = hostGroups.stream() .map(HostGroup::getInstanceGroup) .collect(toSet()); subject.validate(blueprint, hostGroups, instanceGroups, true); }
@Test public void validWithZeroComputeNodes() { Blueprint blueprint = new Blueprint(); blueprint.setBlueprintText(FileReaderUtils.readFileFromClasspathQuietly("input/cdp-data-mart.bp")); Set<HostGroup> hostGroups = Set.of( hostGroup("master", 1), hostGroup("worker", 3), hostGroup("compute", 0) ); Collection<InstanceGroup> instanceGroups = hostGroups.stream() .map(HostGroup::getInstanceGroup) .collect(toSet()); subject.validate(blueprint, hostGroups, instanceGroups, true); }
@Test public void invalidWithoutComputeHostGroup() { Blueprint blueprint = new Blueprint(); blueprint.setBlueprintText(FileReaderUtils.readFileFromClasspathQuietly("input/cdp-data-mart.bp")); Set<HostGroup> hostGroups = Set.of( hostGroup("master", 1), hostGroup("worker", 3) ); Collection<InstanceGroup> instanceGroups = hostGroups.stream() .map(HostGroup::getInstanceGroup) .collect(toSet()); assertThrows(BlueprintValidationException.class, () -> subject.validate(blueprint, hostGroups, instanceGroups, true)); }