@Test
public void testIsValid_failures() throws Exception {

	RangerService service = mock(RangerService.class);
	// passing in a null service to the check itself is an error
	Assert.assertFalse(_validator.isValid((RangerService)null, _action, _failures));
	_utils.checkFailureForMissingValue(_failures, "service");
	// id is required for update
	when(service.getId()).thenReturn(null);
	// let's verify the failure and the sort of error information that is returned (for one of these)
	// Assert.assert that among the failure reason is one about id being missing.
	checkFailure_isValid(_validator, service, Action.UPDATE, _failures, "missing", "id");
	when(service.getId()).thenReturn(7L);
	for (Action action : cu) {
		// null, empty of blank name renders a service invalid
		for (String name : new String[] { null, "", " 	" }) { // spaces and tabs
			when(service.getName()).thenReturn(name);
			checkFailure_isValid(_validator, service, action, _failures, "missing", "name");
		}
		// same is true for the type
		for (String type : new String[] { null, "", "    " }) {
			when(service.getType()).thenReturn(type);
			checkFailure_isValid(_validator, service, action, _failures, "missing", "type");
		}
	}
	when(service.getName()).thenReturn("aName");
	// if non-empty, then the type should exist!
	when(_store.getServiceDefByName("null-type")).thenReturn(null);
	when(_store.getServiceDefByName("throwing-type")).thenThrow(new Exception());
	for (Action action : cu) {
		for (String type : new String[] { "null-type", "throwing-type" }) {
			when(service.getType()).thenReturn(type);
			checkFailure_isValid(_validator, service, action, _failures, "semantic", "type");
		}
	}
	when(service.getType()).thenReturn("aType");
	RangerServiceDef serviceDef = mock(RangerServiceDef.class);
	when(_store.getServiceDefByName("aType")).thenReturn(serviceDef);
	
	// Create: No service should exist matching its id and/or name
	RangerService anExistingService = mock(RangerService.class);
	when(_store.getServiceByName("aName")).thenReturn(anExistingService);
	checkFailure_isValid(_validator, service, Action.CREATE, _failures, "semantic", "name");
	// Update: service should exist matching its id and name specified should not belong to a different service
	when(_store.getService(7L)).thenReturn(null);
	when(_store.getServiceByName("aName")).thenReturn(anExistingService);
	checkFailure_isValid(_validator, service, Action.UPDATE, _failures, "semantic", "id");
	when(_store.getService(7L)).thenReturn(anExistingService);
	RangerService anotherExistingService = mock(RangerService.class);
	when(anotherExistingService.getId()).thenReturn(49L);
	when(_store.getServiceByName("aName")).thenReturn(anotherExistingService);
	checkFailure_isValid(_validator, service, Action.UPDATE, _failures, "semantic", "id/name");
}