@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 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); }