### Question:
RangerServiceDefValidator extends RangerValidator { boolean isValidResourceGraph(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidResourceGraph(%s, %s)", serviceDef, failures)); } boolean valid = true; RangerServiceDefHelper defHelper = _factory.createServiceDefHelper(serviceDef, false); if (!defHelper.isResourceGraphValid()) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_RESOURCE_GRAPH_INVALID; failures.add(new ValidationFailureDetailsBuilder() .field("resource graph") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } Set<List<RangerResourceDef>> hierarchies = defHelper.getResourceHierarchies(); for (List<RangerResourceDef> aHierarchy : hierarchies) { Set<Integer> levels = new HashSet<Integer>(aHierarchy.size()); for (RangerResourceDef resourceDef : aHierarchy) { valid = isUnique(resourceDef.getLevel(), levels, "resource level", "resources", failures) && valid; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidResourceGraph(%s, %s): %s", serviceDef, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action);  }### Answer:
@Test public final void test_isValidResourceGraph() { Object[][] data_bad = new Object[][] { { "db", null, null, null, null, "" , 10 }, { "table", null, null, null, null, "db", 20 }, { "column-family", null, null, null, null, "table", null }, { "column", null, null, null, null, "column-family", 20 }, { "udf", null, null, null, null, "db", 10 }, }; List<RangerResourceDef> resourceDefs = _utils.createResourceDefs(data_bad); when(_serviceDef.getResources()).thenReturn(resourceDefs); when(_serviceDef.getName()).thenReturn("service-name"); when(_serviceDef.getUpdateTime()).thenReturn(new Date()); _failures.clear(); assertFalse(_validator.isValidResourceGraph(_serviceDef, _failures)); _utils.checkFailureForMissingValue(_failures, "resource level"); _utils.checkFailureForSemanticError(_failures, "resource level", "20"); _utils.checkFailureForSemanticError(_failures, "resource level", "10"); Object[][] data_good = new Object[][] { { "db", null, null, null, null, "" , -10 }, { "table", null, null, null, null, "db", 0 }, { "column", null, null, null, null, "table", 10 }, { "udf", null, null, null, null, "db", 0 }, }; resourceDefs = _utils.createResourceDefs(data_good); when(_serviceDef.getResources()).thenReturn(resourceDefs); _failures.clear(); assertTrue(_validator.isValidResourceGraph(_serviceDef, _failures)); assertTrue(_failures.isEmpty()); }