@Test public void testValidateSecurityZoneWitoutResourcesForCreateThrowsError() throws Exception{ RangerSecurityZoneService rangerSecurityZoneService = new RangerSecurityZoneService(); RangerService rangerSvc = getRangerService(); RangerServiceDef rangerSvcDef = rangerServiceDef(); Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef); Map<String, RangerSecurityZone.RangerSecurityZoneService> map = new HashMap<String, RangerSecurityZone.RangerSecurityZoneService>(); map.put("hdfsSvc", rangerSecurityZoneService); RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone(); suppliedSecurityZone.setServices(map); Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null); Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc); try { rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE); } catch (Exception ex) { Assert.assertEquals( ex.getMessage(), "(0) Validation failure: error code[3039], reason[No resources specified for service [hdfsSvc]], field[security zone resources], subfield[null], type[missing] "); } }
public void validate(RangerSecurityZone securityZone, Action action) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } List<ValidationFailureDetails> failures = new ArrayList<>(); boolean valid = isValid(securityZone, action, failures); String message; try { if (!valid) { message = serializeFailures(failures); throw new Exception(message); } } finally { if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } } }
RangerSecurityZoneValidator extends RangerValidator { public void validate(RangerSecurityZone securityZone, Action action) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } List<ValidationFailureDetails> failures = new ArrayList<>(); boolean valid = isValid(securityZone, action, failures); String message; try { if (!valid) { message = serializeFailures(failures); throw new Exception(message); } } finally { if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } } } }
RangerSecurityZoneValidator extends RangerValidator { public void validate(RangerSecurityZone securityZone, Action action) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } List<ValidationFailureDetails> failures = new ArrayList<>(); boolean valid = isValid(securityZone, action, failures); String message; try { if (!valid) { message = serializeFailures(failures); throw new Exception(message); } } finally { if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } } } RangerSecurityZoneValidator(ServiceStore store, SecurityZoneStore securityZoneStore); }
RangerSecurityZoneValidator extends RangerValidator { public void validate(RangerSecurityZone securityZone, Action action) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } List<ValidationFailureDetails> failures = new ArrayList<>(); boolean valid = isValid(securityZone, action, failures); String message; try { if (!valid) { message = serializeFailures(failures); throw new Exception(message); } } finally { if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } } } RangerSecurityZoneValidator(ServiceStore store, SecurityZoneStore securityZoneStore); void validate(RangerSecurityZone securityZone, Action action); }
RangerSecurityZoneValidator extends RangerValidator { public void validate(RangerSecurityZone securityZone, Action action) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } List<ValidationFailureDetails> failures = new ArrayList<>(); boolean valid = isValid(securityZone, action, failures); String message; try { if (!valid) { message = serializeFailures(failures); throw new Exception(message); } } finally { if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.validate(%s, %s)", securityZone, action)); } } } RangerSecurityZoneValidator(ServiceStore store, SecurityZoneStore securityZoneStore); void validate(RangerSecurityZone securityZone, Action action);  }