@Test
  public void testRangerDenyTask() throws Exception {
    RangerDenyTask rangerDenyTask = new RangerDenyTask(mockClient, conf, rangerDenyWork);
    when(conf.get(RANGER_REST_URL)).thenReturn("rangerEndpoint");
    when(rangerDenyWork.getSourceDbName()).thenReturn("srcdb");
    when(rangerDenyWork.getTargetDbName()).thenReturn("tgtdb");
    when(rangerDenyWork.getRangerConfigResource()).thenReturn(new URL("file://ranger.xml"));
    when(rangerDenyWork.getMetricCollector()).thenReturn(metricCollector);
    when(conf.getBoolVar(HiveConf.ConfVars.REPL_RANGER_ADD_DENY_POLICY_TARGET)).thenReturn(true);
    when(conf.get(RANGER_HIVE_SERVICE_NAME)).thenReturn("hive");
    int status = rangerDenyTask.execute();
    Assert.assertEquals(0, status);
    ArgumentCaptor<RangerExportPolicyList> rangerPolicyCapture = ArgumentCaptor.forClass(RangerExportPolicyList.class);
    ArgumentCaptor<String> rangerEndpoint = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> serviceName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> targetDb = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<HiveConf> confCaptor = ArgumentCaptor.forClass(HiveConf.class);
    ArgumentCaptor<String> policyName = ArgumentCaptor.forClass(String.class);
    Mockito.verify(mockClient,
            Mockito.never()).deleteRangerPolicy(policyName.capture(), rangerEndpoint.capture(), serviceName.capture(),
            confCaptor.capture());
    Mockito.verify(mockClient,
            Mockito.times(1)).importRangerPolicies(rangerPolicyCapture.capture(),
            targetDb.capture(), rangerEndpoint.capture(), serviceName.capture(), confCaptor.capture());
    Assert.assertEquals("tgtdb", targetDb.getAllValues().get(0));
    Assert.assertEquals("rangerEndpoint", rangerEndpoint.getAllValues().get(0));
    Assert.assertEquals("hive", serviceName.getAllValues().get(0));
    RangerExportPolicyList actualPolicyList = rangerPolicyCapture.getAllValues().get(0);
    //Deny policy is added
    Assert.assertEquals(1, actualPolicyList.getListSize());
    RangerPolicy denyPolicy = actualPolicyList.getPolicies().get(0);
    Assert.assertEquals("hive", denyPolicy.getService());
    Assert.assertEquals("srcdb_replication deny policy for tgtdb", denyPolicy.getName());
    Assert.assertEquals(1, denyPolicy.getDenyExceptions().size());
    Assert.assertEquals("public", denyPolicy.getDenyPolicyItems().get(0).getGroups().get(0));
    Assert.assertEquals(8, denyPolicy.getDenyPolicyItems().get(0).getAccesses().size());
    boolean isReplAdminDenied = false;
    for (RangerPolicy.RangerPolicyItemAccess access : denyPolicy.getDenyPolicyItems().get(0).getAccesses()) {
      if (access.getType().equalsIgnoreCase("ReplAdmin")) {
        isReplAdminDenied = true;
      }
    }
    Assert.assertTrue(isReplAdminDenied);
    //Deny exception is for hive user. Deny exception is not for repl admin permission
    Assert.assertEquals("hive", denyPolicy.getDenyExceptions().get(0).getUsers().get(0));
    Assert.assertEquals(10, denyPolicy.getDenyExceptions().get(0).getAccesses().size());
    isReplAdminDenied = false;
    for (RangerPolicy.RangerPolicyItemAccess access : denyPolicy.getDenyExceptions().get(0).getAccesses()) {
      if (access.getType().equalsIgnoreCase("ReplAdmin")) {
        isReplAdminDenied = true;
      }
    }
    Assert.assertTrue(isReplAdminDenied);
    when(conf.getBoolVar(HiveConf.ConfVars.REPL_RANGER_ADD_DENY_POLICY_TARGET)).thenReturn(false);
    status = rangerDenyTask.execute();
    Assert.assertEquals(0, status);
    Mockito.verify(mockClient,
            Mockito.times(1)).deleteRangerPolicy(policyName.capture(), rangerEndpoint.capture(), serviceName.capture(),
            confCaptor.capture());
    Assert.assertEquals("srcdb_replication deny policy for tgtdb", policyName.getAllValues().get(0));
    Assert.assertEquals("rangerEndpoint", rangerEndpoint.getAllValues().get(0));
    Assert.assertEquals("hive", serviceName.getAllValues().get(0));
  }
Unit test class for testing Ranger Load.
ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestRangerLoadTask.java