Search in sources :

Example 1 with ProjectManager

use of org.apache.kylin.metadata.project.ProjectManager in project ranger by apache.

the class RangerKylinAuthorizerTest method mockKylinProjects.

/**
 * Help function: mock kylin projects, to match projectUuid and projectName
 */
private static void mockKylinProjects() {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    ProjectManager projectManager = mock(ProjectManager.class);
    @SuppressWarnings({ "rawtypes", "unchecked" }) Map<Class, Object> managersCache = (Map<Class, Object>) ReflectionTestUtils.getField(kylinConfig, "managersCache");
    managersCache.put(ProjectManager.class, projectManager);
    Answer<ProjectInstance> answer = new Answer<ProjectInstance>() {

        @Override
        public ProjectInstance answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            if (args == null || args.length == 0) {
                return null;
            }
            String uuid = (String) args[0];
            return uuid2Projects.get(uuid);
        }
    };
    when(projectManager.getPrjByUuid(anyString())).thenAnswer(answer);
}
Also used : KylinConfig(org.apache.kylin.common.KylinConfig) ProjectInstance(org.apache.kylin.metadata.project.ProjectInstance) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProjectManager(org.apache.kylin.metadata.project.ProjectManager) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 KylinConfig (org.apache.kylin.common.KylinConfig)1 ProjectInstance (org.apache.kylin.metadata.project.ProjectInstance)1 ProjectManager (org.apache.kylin.metadata.project.ProjectManager)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1