Search in sources :

Example 1 with Repository

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);
}
Also used : Repository(org.apache.sqoop.repository.Repository) MJob(org.apache.sqoop.model.MJob) MLink(org.apache.sqoop.model.MLink) RepositoryManager(org.apache.sqoop.repository.RepositoryManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File)

Aggregations

File (java.io.File)1 MJob (org.apache.sqoop.model.MJob)1 MLink (org.apache.sqoop.model.MLink)1 Repository (org.apache.sqoop.repository.Repository)1 RepositoryManager (org.apache.sqoop.repository.RepositoryManager)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1