use of org.apache.ranger.plugin.contextenricher.TestTagEnricher.TagEnricherTestCase.TestData in project ranger by apache.
the class TestTagEnricher method runTests.
private void runTests(InputStreamReader reader, String testName) {
TagEnricherTestCase testCase = gsonBuilder.fromJson(reader, TagEnricherTestCase.class);
assertTrue("invalid input: " + testName, testCase != null && testCase.serviceDef != null && testCase.serviceResources != null && testCase.tests != null);
ServiceTags serviceTags = new ServiceTags();
serviceTags.setServiceName(testCase.serviceName);
serviceTags.setTagDefinitions(testCase.tagDefinitions);
serviceTags.setTags(testCase.tags);
serviceTags.setServiceResources(testCase.serviceResources);
serviceTags.setResourceToTagIds(testCase.resourceToTagIds);
RangerTagEnricher tagEnricher = new RangerTagEnricher();
tagEnricher.setServiceName(testCase.serviceName);
tagEnricher.setServiceDef(testCase.serviceDef);
tagEnricher.setServiceTags(serviceTags);
List<String> expectedTags = new ArrayList<>();
List<String> resultTags = new ArrayList<>();
for (TestData test : testCase.tests) {
RangerAccessRequestImpl request = new RangerAccessRequestImpl(test.resource, test.accessType, "testUser", null);
tagEnricher.enrich(request);
List<RangerTag> expected = test.result;
Set<RangerTagForEval> result = RangerAccessRequestUtil.getRequestTagsFromContext(request.getContext());
expectedTags.clear();
if (expected != null) {
for (RangerTag tag : expected) {
expectedTags.add(tag.getType());
}
Collections.sort(expectedTags);
}
resultTags.clear();
if (result != null) {
for (RangerTagForEval tag : result) {
resultTags.add(tag.getType());
}
Collections.sort(resultTags);
}
assertEquals(test.name, expectedTags, resultTags);
}
}
Aggregations