@Test
public void testCreatePrincipalDistributedKeytab() throws IOException {

  MockClientContext mockClientContext = new MockClientContext(DEFAULT_JOB_NAME);
  String jobname = "testJobname";
  String keytab = "testKeytab";
  File keytabFile = createKeytabFile(keytab);
  RunJobParameters parameters = mock(RunJobParameters.class);
  when(parameters.getPrincipal()).thenReturn("principal");
  when(parameters.getKeytab()).thenReturn(keytabFile.getAbsolutePath());
  when(parameters.getName()).thenReturn(jobname);
  when(parameters.isDistributeKeytab()).thenReturn(true);
  FileSystemOperations fsOperations =
      new FileSystemOperations(mockClientContext);
  KerberosPrincipal result =
      KerberosPrincipalFactory.create(fsOperations,
          mockClientContext.getRemoteDirectoryManager(), parameters);
  Path stagingDir = mockClientContext.getRemoteDirectoryManager()
      .getJobStagingArea(parameters.getName(), true);
  String expectedKeytabFilePath =
      FileUtilitiesForTests.getFilename(stagingDir, keytab).getAbsolutePath();
  assertNotNull(result);
  assertEquals(expectedKeytabFilePath, result.getKeytab());
  assertEquals("principal", result.getPrincipalName());
}