@Test public void test_getValidationRegExes() { Map<String, String> regExMap = _validator.getValidationRegExes((RangerServiceDef)null); Assert.assertTrue(regExMap.isEmpty()); RangerServiceDef serviceDef = mock(RangerServiceDef.class); when(serviceDef.getResources()).thenReturn(null); regExMap = _validator.getValidationRegExes(serviceDef); Assert.assertTrue(regExMap.isEmpty()); List<RangerResourceDef> resourceDefs = new ArrayList<>(); when(serviceDef.getResources()).thenReturn(resourceDefs); regExMap = _validator.getValidationRegExes(serviceDef); Assert.assertTrue(regExMap.isEmpty()); resourceDefs.add(null); regExMap = _validator.getValidationRegExes(serviceDef); Assert.assertTrue(regExMap.isEmpty()); String[][] data = { { "a", null }, null, { "b", "regex1" }, { "c", "" }, { "d", "regex2" }, { "e", " " }, { "f", "regex3" }, }; resourceDefs.addAll(_utils.createResourceDefsWithRegEx(data)); regExMap = _validator.getValidationRegExes(serviceDef); Assert.assertEquals(3, regExMap.size()); Assert.assertEquals("regex1", regExMap.get("b")); Assert.assertEquals("regex2", regExMap.get("d")); Assert.assertEquals("regex3", regExMap.get("f")); }
Map<String, String> getValidationRegExes(RangerServiceDef serviceDef) { if (serviceDef == null || CollectionUtils.isEmpty(serviceDef.getResources())) { return new HashMap<>(); } else { Map<String, String> result = new HashMap<>(); for (RangerResourceDef resourceDef : serviceDef.getResources()) { if (resourceDef == null) { LOG.warn("A resource def in resource def collection is null"); } else { String name = resourceDef.getName(); String regEx = resourceDef.getValidationRegEx(); if (StringUtils.isBlank(name)) { LOG.warn("resource name is null/empty/blank"); } else if (StringUtils.isBlank(regEx)) { LOG.debug("validation regex is null/empty/blank"); } else { result.put(name, regEx); } } } return result; } }
RangerValidator { Map<String, String> getValidationRegExes(RangerServiceDef serviceDef) { if (serviceDef == null || CollectionUtils.isEmpty(serviceDef.getResources())) { return new HashMap<>(); } else { Map<String, String> result = new HashMap<>(); for (RangerResourceDef resourceDef : serviceDef.getResources()) { if (resourceDef == null) { LOG.warn("A resource def in resource def collection is null"); } else { String name = resourceDef.getName(); String regEx = resourceDef.getValidationRegEx(); if (StringUtils.isBlank(name)) { LOG.warn("resource name is null/empty/blank"); } else if (StringUtils.isBlank(regEx)) { LOG.debug("validation regex is null/empty/blank"); } else { result.put(name, regEx); } } } return result; } } }
RangerValidator { Map<String, String> getValidationRegExes(RangerServiceDef serviceDef) { if (serviceDef == null || CollectionUtils.isEmpty(serviceDef.getResources())) { return new HashMap<>(); } else { Map<String, String> result = new HashMap<>(); for (RangerResourceDef resourceDef : serviceDef.getResources()) { if (resourceDef == null) { LOG.warn("A resource def in resource def collection is null"); } else { String name = resourceDef.getName(); String regEx = resourceDef.getValidationRegEx(); if (StringUtils.isBlank(name)) { LOG.warn("resource name is null/empty/blank"); } else if (StringUtils.isBlank(regEx)) { LOG.debug("validation regex is null/empty/blank"); } else { result.put(name, regEx); } } } return result; } } protected  RangerValidator(ServiceStore store); protected  RangerValidator(RoleStore roleStore); }
RangerValidator { Map<String, String> getValidationRegExes(RangerServiceDef serviceDef) { if (serviceDef == null || CollectionUtils.isEmpty(serviceDef.getResources())) { return new HashMap<>(); } else { Map<String, String> result = new HashMap<>(); for (RangerResourceDef resourceDef : serviceDef.getResources()) { if (resourceDef == null) { LOG.warn("A resource def in resource def collection is null"); } else { String name = resourceDef.getName(); String regEx = resourceDef.getValidationRegEx(); if (StringUtils.isBlank(name)) { LOG.warn("resource name is null/empty/blank"); } else if (StringUtils.isBlank(regEx)) { LOG.debug("validation regex is null/empty/blank"); } else { result.put(name, regEx); } } } return result; } } protected  RangerValidator(ServiceStore store); protected  RangerValidator(RoleStore roleStore); void validate(Long id, Action action); void validate(String name, Action action); static String serializeFailures(List<ValidationFailureDetails> failures); }
RangerValidator { Map<String, String> getValidationRegExes(RangerServiceDef serviceDef) { if (serviceDef == null || CollectionUtils.isEmpty(serviceDef.getResources())) { return new HashMap<>(); } else { Map<String, String> result = new HashMap<>(); for (RangerResourceDef resourceDef : serviceDef.getResources()) { if (resourceDef == null) { LOG.warn("A resource def in resource def collection is null"); } else { String name = resourceDef.getName(); String regEx = resourceDef.getValidationRegEx(); if (StringUtils.isBlank(name)) { LOG.warn("resource name is null/empty/blank"); } else if (StringUtils.isBlank(regEx)) { LOG.debug("validation regex is null/empty/blank"); } else { result.put(name, regEx); } } } return result; } } protected  RangerValidator(ServiceStore store); protected  RangerValidator(RoleStore roleStore); void validate(Long id, Action action); void validate(String name, Action action); static String serializeFailures(List<ValidationFailureDetails> failures);  }