ExecuteJavaScriptModifier implements CollectorJob { @Override public void setParameters(Map<String, String> params) throws ParametersException { cmd = params.get(CMD_PARAM); snippetUrl = params.get(URL_PARAM); ParametersValidator.checkAtLeastOneNotBlank( "Either 'cmd' or 'snippetUrl' parameter must be provided for executejavascript modifier.", cmd, snippetUrl); if (params.containsKey(BASIC_AUTH_USERNAME) && params.containsKey(BASIC_AUTH_PASSWORD)) { String username = params.get(BASIC_AUTH_USERNAME); String password = params.get(BASIC_AUTH_PASSWORD); String encoded = encodeBasicAuth(username, password); LOG.info("Setting basic auth '{}:{}' encoded to: '{}'", username, password, encoded); basicAuth = encoded; } else { boolean containOnlyOne = params.containsKey(BASIC_AUTH_USERNAME) || params.containsKey(BASIC_AUTH_PASSWORD); if (containOnlyOne) { throw new ParametersException( "You have to specify both " + BASIC_AUTH_USERNAME + " and " + BASIC_AUTH_PASSWORD); } } } ExecuteJavaScriptModifier(ExternalSnippetHttpClient httpClient,
      JavaScriptJobExecutor jsExecutor); @Override CollectorStepResult collect(); @Override void setParameters(Map<String, String> params); static final String NAME; }
@Test(expected = ParametersException.class) public void setParameters_MissingParam_ValidationPassedUnsuccessfully() throws ParametersException { when(params.get("basicAuthUsername")).thenReturn("admin"); when(params.get("basicAuthPassword")).thenReturn(null); tested.setParameters(params); }
@Test public void setParameters_CmdIsValid_ValidationPassedSuccessfully() throws ParametersException { setupCmdParam(); tested.setParameters(params); }
@Test public void setParameters_SnippetUrlIsValid_ValidationPassedSuccessfully() throws ParametersException { setupSnippetUrlParam(); tested.setParameters(params); }
@Test public void setParameters_BothCmdAndSnippetUrlAreProvided_ValidationPassedSuccessfully() throws ParametersException { setupCmdParam(); setupSnippetUrlParam(); tested.setParameters(params); }
@Test(expected = ParametersException.class) public void setParameters_NoSourceIsPassed_ValidationPassedUnsuccessfully() throws ParametersException { tested.setParameters(params); }