use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefValidator method test_isValidServiceDefId_happyPath.
@Test
public final void test_isValidServiceDefId_happyPath() throws Exception {
// create: null id is ok
assertTrue(_validator.isValidServiceDefId(null, Action.CREATE, _failures));
assertTrue(_failures.isEmpty());
// update: a service with same id exist
long id = 7;
when(_serviceDef.getId()).thenReturn(id);
RangerServiceDef serviceDefFromDb = mock(RangerServiceDef.class);
when(serviceDefFromDb.getId()).thenReturn(id);
when(_store.getServiceDef(id)).thenReturn(serviceDefFromDb);
assertTrue(_validator.isValidServiceDefId(id, Action.UPDATE, _failures));
assertTrue(_failures.isEmpty());
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefValidator method testIsValid_failures.
@Test
public final void testIsValid_failures() throws Exception {
// null service def and bad service def name
for (Action action : cu) {
// passing in null service def is an error
assertFalse(_validator.isValid((RangerServiceDef) null, action, _failures));
_utils.checkFailureForMissingValue(_failures, "service def");
}
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefValidator method test_isValidName_create.
@Test
public final void test_isValidName_create() throws Exception {
// id should be irrelevant for name check for create.
Long id = null;
// for create a service shouldn't exist with the name
String name = "existing-service";
when(_serviceDef.getName()).thenReturn(name);
when(_store.getServiceDefByName(name)).thenReturn(null);
assertTrue(_validator.isValidServiceDefName(name, id, Action.CREATE, _failures));
assertTrue(_failures.isEmpty());
RangerServiceDef existingServiceDef = mock(RangerServiceDef.class);
when(_store.getServiceDefByName(name)).thenReturn(existingServiceDef);
_failures.clear();
assertFalse(_validator.isValidServiceDefName(name, id, Action.CREATE, _failures));
_utils.checkFailureForSemanticError(_failures, "name");
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefValidator method test_isValidName_update.
@Test
public final void test_isValidName_update() throws Exception {
// update: if service exists with the same name then it can't point to a different service
long id = 7;
when(_serviceDef.getId()).thenReturn(id);
String name = "aServiceDef";
when(_serviceDef.getName()).thenReturn(name);
// no service with the new name (we are updating the name to a unique value)
when(_store.getServiceDefByName(name)).thenReturn(null);
assertTrue(_validator.isValidServiceDefName(name, id, Action.UPDATE, _failures));
assertTrue(_failures.isEmpty());
RangerServiceDef existingServiceDef = mock(RangerServiceDef.class);
when(existingServiceDef.getId()).thenReturn(id);
when(existingServiceDef.getName()).thenReturn(name);
when(_store.getServiceDefByName(name)).thenReturn(existingServiceDef);
assertTrue(_validator.isValidServiceDefName(name, id, Action.UPDATE, _failures));
assertTrue(_failures.isEmpty());
long anotherId = 49;
when(existingServiceDef.getId()).thenReturn(anotherId);
assertFalse(_validator.isValidServiceDefName(name, id, Action.UPDATE, _failures));
_utils.checkFailureForSemanticError(_failures, "id/name");
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceValidator method test_isValid_happyPath.
@Test
public void test_isValid_happyPath() throws Exception {
// create a service def with some required parameters
Object[][] serviceDefInput = new Object[][] { { "param1", true }, { "param2", true }, { "param3", false }, { "param4", false }, { "param5", true } };
List<RangerServiceConfigDef> configDefs = _utils.createServiceConditionDefs(serviceDefInput);
RangerServiceDef serviceDef = mock(RangerServiceDef.class);
when(serviceDef.getConfigs()).thenReturn(configDefs);
// create a service with some parameters on it
RangerService service = mock(RangerService.class);
when(service.getName()).thenReturn("aName");
when(service.getType()).thenReturn("aType");
// contains an extra parameter (param6) and one optional is missing(param4)
String[] configs = new String[] { "param1", "param2", "param3", "param5", "param6" };
Map<String, String> configMap = _utils.createMap(configs);
when(service.getConfigs()).thenReturn(configMap);
// wire then into the store
// service does not exists
when(_store.getServiceByName("aName")).thenReturn(null);
// service def exists
when(_store.getServiceDefByName("aType")).thenReturn(serviceDef);
Assert.assertTrue(_validator.isValid(service, Action.CREATE, _failures));
// for update to work the only additional requirement is that id is required and service should exist
// if name is not null and it points to a service then it should match the id
when(service.getId()).thenReturn(7L);
RangerService existingService = mock(RangerService.class);
when(existingService.getId()).thenReturn(Long.valueOf(7L));
when(_store.getService(7L)).thenReturn(existingService);
when(_store.getServiceByName("aName")).thenReturn(existingService);
Assert.assertTrue(_validator.isValid(service, Action.UPDATE, _failures));
// name need not point to a service for update to work, of course.
when(_store.getServiceByName("aName")).thenReturn(null);
Assert.assertTrue(_validator.isValid(service, Action.UPDATE, _failures));
}
Aggregations