public JobConfig() { this(configBuilder()); }
public static JobConfig exampleConfig() { return exampleConfigBuilder().build(); }
public JobConfig build() { return new JobConfig(this); } }
@Test(expected = BrowserNotInstalledException.class) public void shouldThrowBrowserNotInstalledException() throws BrowserNotInstalledException { // Given JobConfig jobConfig = copyOfBuilder(exampleConfig()) .withBrowser(FIREFOX) .build(); //When jLineupRunnerFactory.sanitizeJobConfig(jobConfig); }
@Test public void shouldStartBeforeRun() throws Exception { //given JobConfig jobConfig = JobConfig.exampleConfig(); //when JLineupRunStatus beforeStatus = testee.startBeforeRun(jobConfig); beforeStatus.getCurrentJobStepFuture().get().get(); //then verify(jLineupRunnerFactory).createBeforeRun(beforeStatus.getId(), jobConfig); verify(jLineupRunnerBefore).run(); }
@Test public void shouldReturn422ForUnsupportedBrowser() throws Exception { // given JobConfig jobConfig = exampleConfig(); when(jLineupService.startBeforeRun(jobConfig)).thenThrow(new BrowserNotInstalledException(jobConfig.browser)); // when ResultActions result = mvc .perform(post("/runs") .content(JobConfig.prettyPrint(jobConfig)) .contentType(MediaType.APPLICATION_JSON)); // then result .andExpect(status().isUnprocessableEntity()) .andExpect(content().string(containsString(jobConfig.browser.name()))); }
@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\"")); }
@Test(expected = FileNotFoundException.class) public void shouldThrowFileNotFoundExceptionWhenConfigFileIsNotFound() throws FileNotFoundException { JobConfig.readConfig("someWorkingDir", "nonexisting.json"); //assert that FileNotFoundException is thrown (see expected above) }
public static JobConfig defaultConfig() { return defaultConfig(EXAMPLE_URL); }
@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 shouldStartAfterRun() throws Exception { //given JobConfig jobConfig = JobConfig.exampleConfig(); when(jLineupRunnerBefore.run()).thenReturn(true); JLineupRunStatus beforeStatus = testee.startBeforeRun(jobConfig); //when beforeStatus.getCurrentJobStepFuture().get().get(); JLineupRunStatus afterStatus = testee.startAfterRun(beforeStatus.getId()); afterStatus.getCurrentJobStepFuture().get().get(); //then verify(jLineupRunnerFactory).createAfterRun(beforeStatus.getId(), jobConfig); verify(jLineupRunnerAfter).run(); }
@Test public void shouldStartNewRun() throws Exception { // given JobConfig jobConfig = exampleConfig(); JLineupRunStatus run = runStatusBuilder().withId("someNewId").withJobConfig(jobConfig).withState(State.BEFORE_RUNNING).build(); when(jLineupService.startBeforeRun(any())).thenReturn(run); // when ResultActions result = mvc .perform(post("/testContextPath/runs") .contextPath("/testContextPath") .content(JobConfig.prettyPrint(jobConfig)) .contentType(MediaType.APPLICATION_JSON)); // then result .andExpect(status().isAccepted()) .andExpect(content().json("{\"id\":\"someNewId\"}")) .andExpect(header().string("Location", "/testContextPath/runs/someNewId")); verify(jLineupService).startBeforeRun(jobConfig); }
@Test public void shouldReadMinimalConfigAndInsertDefaults() throws FileNotFoundException { JobConfig jobConfig = JobConfig.readConfig("src/test/resources/", "lineup_minimal_test.json"); assertThat(jobConfig.browser.isPhantomJS(), is(true)); assertThat(jobConfig.windowHeight, is(800)); assertThat(jobConfig.urls.get("https://www.otto.de").windowWidths, is(ImmutableList.of(800))); assertThat(jobConfig.urls.get("https://www.otto.de").paths, is(ImmutableList.of(""))); assertThat(jobConfig.globalWaitAfterPageLoad, is(0F)); assertThat(jobConfig.pageLoadTimeout, is(120)); assertThat(jobConfig.screenshotRetries, is(0)); }
public static JobConfig defaultConfig(String url) { return configBuilder().withUrls(ImmutableMap.of(url, new UrlConfig())).build(); }
@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 shouldContainReportPathInResult() throws Exception { //given JobConfig jobConfig = JobConfig.exampleConfig(); when(jLineupRunnerBefore.run()).thenReturn(true); JLineupRunStatus beforeStatus = testee.startBeforeRun(jobConfig); when(jLineupRunnerAfter.run()).thenReturn(true); beforeStatus.getCurrentJobStepFuture().get().get(); JLineupRunStatus afterStatus = testee.startAfterRun(beforeStatus.getId()); afterStatus.getCurrentJobStepFuture().get().get(); //when Optional<JLineupRunStatus> status = testee.getRun(beforeStatus.getId()); //then assertTrue(status.isPresent()); assertThat(status.get().getState(), is(State.FINISHED_WITHOUT_DIFFERENCES)); assertThat(status.get().getReports().getHtmlUrl(), is("/reports/report-" + beforeStatus.getId() + "/report.html")); assertThat(status.get().getReports().getJsonUrl(), is("/reports/report-" + beforeStatus.getId() + "/report.json")); }
@Test public void shouldNotCheckForErrorsIfDisabled() { //given when(webDriver.manage().logs().get(LogType.BROWSER)).thenReturn(new LogEntries(of(new LogEntry(Level.SEVERE, Instant.now().toEpochMilli(), "Fehler!")))); JobConfig jobConfig = JobConfig.exampleConfigBuilder().withCheckForErrorsInLog(false).build(); //when new LogErrorChecker().checkForErrors(webDriver, jobConfig); //then expect no exception } }
@Test public void shouldReadConfigAndParsedWithJackson() throws IOException { JobConfig jobConfigGson = JobConfig.readConfig("src/test/resources/", "lineup_test.json"); JobConfig jobConfigJackson = new ObjectMapper() .readValue(new File("src/test/resources/lineup_test.json"), JobConfig.class); Assert.assertEquals(jobConfigGson, jobConfigJackson); }
public static JobConfig.Builder exampleConfigBuilder() { return configBuilder() .withUrls(ImmutableMap.of("http://www.example.com", new UrlConfig( ImmutableList.of("/", "someOtherPath"), DEFAULT_MAX_DIFF, ImmutableList.of( new Cookie("exampleCookieName", "exampleValue", "http://www.example.com", "/", new Date(1000L), true) ), ImmutableMap.of("live", "www"), ImmutableMap.of("exampleLocalStorageKey", "value"), ImmutableMap.of("exampleSessionStorageKey", "value"), ImmutableList.of(600, 800, 1000), DEFAULT_MAX_SCROLL_HEIGHT, DEFAULT_WAIT_AFTER_PAGE_LOAD, DEFAULT_WAIT_AFTER_SCROLL, DEFAULT_WAIT_FOR_NO_ANIMATION_AFTER_SCROLL, DEFAULT_WARMUP_BROWSER_CACHE_TIME, "console.log('This is JavaScript!')", DEFAULT_WAIT_FOR_FONTS_TIME, new HttpCheckConfig(true), DEFAULT_MAX_COLOR_DIFF_PER_PIXEL, false ))); }