@Test public void shouldSanitizeJobConfig() throws BrowserNotInstalledException { //Given JobConfig evilJobConfig = copyOfBuilder(exampleConfig()) .withBrowser(CHROME_HEADLESS) .withThreads(Integer.MAX_VALUE) .withDebug(true) .withLogToFile(true) .withReportFormat(1) .build(); //When JobConfig sanitizedJobConfig = jLineupRunnerFactory.sanitizeJobConfig(evilJobConfig); //Then assertThat(sanitizedJobConfig.threads, is(jLineupWebProperties.getMaxThreadsPerJob())); assertThat(sanitizedJobConfig.debug, is(false)); assertThat(sanitizedJobConfig.logToFile, is(false)); assertThat(sanitizedJobConfig.reportFormat, is(DEFAULT_REPORT_FORMAT)); }
@Test public void shouldUseDefinedNumberOfThreadsIfConfiguredAndBelowMax() throws BrowserNotInstalledException { //Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withThreads(2) .build(); //When JobConfig sanitizedConfig = jLineupRunnerFactory.sanitizeJobConfig(jobConfig); //Then assertThat(sanitizedConfig.threads, is(2)); }
@Test public void shouldReduceNumberOfThreadsToMax() throws BrowserNotInstalledException { //Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withThreads(200) .build(); //When JobConfig sanitizedConfig = jLineupRunnerFactory.sanitizeJobConfig(jobConfig); //Then assertThat(sanitizedConfig.threads, is(jLineupWebProperties.getMaxThreadsPerJob())); } }
public static Builder copyOfBuilder(JobConfig jobConfig) { return configBuilder() .withName(jobConfig.name) .withUrls(jobConfig.urls) .withHttpCheck(jobConfig.httpCheck) .withBrowser(jobConfig.browser) .withGlobalWaitAfterPageLoad(jobConfig.globalWaitAfterPageLoad) .withPageLoadTimeout(jobConfig.pageLoadTimeout) .withWindowHeight(jobConfig.windowHeight) .withThreads(jobConfig.threads) .withScreenshotRetries(jobConfig.screenshotRetries) .withReportFormat(jobConfig.reportFormat) .withGlobalTimeout(jobConfig.globalTimeout) .withDebug(jobConfig.debug) .withLogToFile(jobConfig.logToFile) .withCheckForErrorsInLog(jobConfig.checkForErrorsInLog); }
@Test public void shouldUseMaxThreadsPerJobIfNoThreadsAreConfigured() throws BrowserNotInstalledException { //Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withThreads(0) .build(); //When JobConfig sanitizedConfig = jLineupRunnerFactory.sanitizeJobConfig(jobConfig); //Then assertThat(sanitizedConfig.threads, is(jLineupWebProperties.getMaxThreadsPerJob())); }