@Test
  public void shouldCommandStringBeAssembledCorrectlyForSingleUser() throws Exception {
    // GIVEN

    payload = mockPayload(1);
    mockExecutionCommand(payload.size());
    String payloadJson = om.writeValueAsString(payload);

    // command params as passed to the serveraction implementation
    Map<String, String> commandParams = new HashMap<>();
    commandParams.put(UserHookParams.PAYLOAD.param(), payloadJson);
    commandParams.put(UserHookParams.SCRIPT.param(), "/hookfolder/hook.name");
    commandParams.put(UserHookParams.CMD_TIME_FRAME.param(), "1000");
    commandParams.put(UserHookParams.CMD_INPUT_FILE.param(), "/test/user_data.csv");
    commandParams.put(UserHookParams.CLUSTER_SECURITY_TYPE.param(), SecurityType.KERBEROS.name());
    commandParams.put(UserHookParams.CMD_HDFS_USER.param(), "test-hdfs-user");

    EasyMock.expect(executionCommand.getCommandParams()).andReturn(commandParams);
    EasyMock.expect(objectMapperMock.readValue(payloadJson, Map.class)).andReturn(payload);

    // captures the command arguments passed to the shell callable through the factory
    commandCapture = EasyMock.newCapture();

    // the callable mock returns a dummy result, no assertions made on the result
    EasyMock.expect(shellCommandUtilityWrapper.runCommand(EasyMock.capture(commandCapture))).andReturn(new ShellCommandUtil.Result(0, null, null)).times(payload.size());

    customScriptServerAction.setExecutionCommand(executionCommand);

    EasyMock.expect(collectionPersisterServiceFactoryMock.createCsvFilePersisterService(EasyMock.anyString())).andReturn(collectionPersisterService);
    EasyMock.expect(collectionPersisterService.persistMap(EasyMock.anyObject())).andReturn(Boolean.TRUE);

    replayAll();

    // WHEN
    CommandReport commandReport = customScriptServerAction.execute(requestSharedDataContext);

    // THEN
    String[] commandArray = commandCapture.getValue();
    Assert.assertNotNull("The command to be executed must not be null!", commandArray);

    Assert.assertEquals("The command argument array length is not as expected!", 6, commandArray.length);
    Assert.assertEquals("The command script is not as expected", "/hookfolder/hook.name", commandArray[0]);
  }
Test suite for the PostUserCreationHookServer action class.
ambari-server/src/test/java/org/apache/ambari/server/serveraction/users/PostUserCreationHookServerActionTest.java