use of org.apache.sqoop.repository.Repository in project ranger by apache.
the class RangerSqoopAuthorizerTest method initSqoopAuth.
/**
* Help function: init sqoop to enable ranger authentication
*/
private static void initSqoopAuth() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
// init sqoop configruation
String basedir = System.getProperty("basedir");
if (basedir == null) {
basedir = new File(".").getCanonicalPath();
}
String sqoopConfigDirPath = basedir + "/src/test/resources/";
System.setProperty(ConfigurationConstants.SYSPROP_CONFIG_DIR, sqoopConfigDirPath);
SqoopConfiguration.getInstance().initialize();
// init sqoop authorization
AuthorizationManager.getInstance().initialize();
// mock sqoop class for authentication
RepositoryManager repositoryManager = mock(RepositoryManager.class);
RepositoryManager.setInstance(repositoryManager);
Repository repository = mock(Repository.class);
when(repositoryManager.getRepository()).thenReturn(repository);
MLink link = mock(MLink.class);
when(repository.findLink(anyString())).thenReturn(link);
MJob job = mock(MJob.class);
when(repository.findJob(anyString())).thenReturn(job);
// mock user "zhangqiang" as the creator of any link and any job
when(link.getCreationUser()).thenReturn(ZHANGQIANG);
when(job.getCreationUser()).thenReturn(ZHANGQIANG);
}
Aggregations