@Test public void shouldFailIfBrowserIsNotConfigured() { JobConfig jobConfig = copyOfBuilder(createTestConfig()).withBrowser(Browser.Type.FIREFOX).build(); expectStatusCodeForConfig(jobConfig, UNPROCESSABLE_ENTITY.value()); }
@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 shouldUseMaxThreadsPerJobIfNoThreadsAreConfigured() throws BrowserNotInstalledException { //Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withThreads(0) .build(); //When JobConfig sanitizedConfig = jLineupRunnerFactory.sanitizeJobConfig(jobConfig); //Then assertThat(sanitizedConfig.threads, is(jLineupWebProperties.getMaxThreadsPerJob())); }
@Test(expected = BrowserNotInstalledException.class) public void shouldThrowBrowserNotInstalledException() throws BrowserNotInstalledException { // Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withBrowser(FIREFOX) .build(); //When jLineupRunnerFactory.sanitizeJobConfig(jobConfig); }
@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())); } }
@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 shouldReturn422IfConfigValidationFails() throws Exception { // given JobConfig jobConfig = JobConfig.copyOfBuilder(exampleConfig()).withUrls(null).build(); when(jLineupService.startBeforeRun(jobConfig)).thenThrow(new ConfigValidationException("Validation message")); // when ResultActions result = mvc .perform(post("/runs") .content(JobConfig.prettyPrint(jobConfig)) .contentType(MediaType.APPLICATION_JSON)); // then result .andExpect(status().isUnprocessableEntity()) .andExpect(content().string("\"Validation message\"")); }