在命令行上使用maven通过Docker Maven容器3.5.4-jdk8时,我的测试失败了

时间:2018-11-25 20:25:36

标签: maven spring-boot docker gitlab-ci

我有以下通过IDE的测试,并以Junit甚至在使用mvn clean verify的命令行下运行时通过。

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(SpringRunner.class)
@WebFluxTest(controllers = AddNewEntryController.class)
@Import({ThymeleafAutoConfiguration.class})
public class AddNewEntryControllerTest {

@Autowired
WebTestClient webTestClient;

@MockBean
TimeKeepingEntryService service;

@Captor
private ArgumentCaptor<Flux<TimeKeepingEntry>> captor;

@Autowired
AddNewEntryController controller;

LocalDateTime now = LocalDateTime.now();
String month = now.getMonth().getDisplayName(TextStyle.FULL, Locale.ENGLISH);
TimeKeepingEntry entry1 = new TimeKeepingEntry(month,
        now.getDayOfMonth(), now.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH), now.toLocalTime(),
        LocalTime.parse("00:30", DateTimeFormatter.ofPattern("HH:mm")),
        now.toLocalTime().plusHours(7), "7.5", false );

@Test
public void addNewEntryPage() {
    EntityExchangeResult<String> result = webTestClient
            .get().uri("/add-new-entry")
            .exchange()
            .expectStatus().isOk()
            .expectBody(String.class).returnResult();

    assertThat(result.getResponseBody())
            .contains("<title>Add New Time Entry</title>")
            .contains("<input type=\"text\" class=\"form-control\" readonly=\"readonly\" id=\"month\" name=\"month\" value=\"" + month + "\">")
            .contains("<input data-date-format=\"dd\" id=\"datepicker\" name=\"dateOfMonth\" value=\"0\">")
            .contains("<input type=\"text\" class=\"form-control\" id=\"day\" name=\"day\" value=\"" + now.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH) + "\">");
}

@Test
public void addNewEntrySubmit() {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
    formData.add("month", month);
    formData.add("dateOfMonth", Integer.toString(21));
    formData.add("day", "Tuesday");
    formData.add("startTime", "09:00");
    formData.add("endTime", "17:00");
    formData.add("breakLength", "00:30");
    formData.add("onsite", Boolean.toString(false));

    given(service.addTimeKeepingEntry(any())).willReturn(Mono.empty());

    webTestClient.post().uri("/add-new-entry").accept(MediaType.TEXT_HTML).contentType(MediaType.APPLICATION_FORM_URLENCODED)
            .body(BodyInserters.fromFormData(formData)).exchange().expectStatus().isSeeOther().expectHeader().valueEquals(HttpHeaders.LOCATION, "/");

    verify(service).addTimeKeepingEntry(captor.capture());
    TimeKeepingEntry timeKeepingEntry = captor.getValue().blockFirst();
    assertThat(timeKeepingEntry.getMonth()).isEqualTo(month);
}

}

但是,当我将代码推送到Gitlab.com时,CI接管并使用了maven docker容器3.5.4-jdk8时,它失败并出现以下错误。

Field error in object 'timeKeepingEntry' on field 'startTime': rejected `value [09:00]; codes typeMismatch.timeKeepingEntry.startTime,typeMismatch.startTime,typeMismatch.java.time.LocalTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [timeKeepingEntry.startTime,startTime]; arguments []; default message [startTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalTime' for property 'startTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull java.time.LocalTime] for value '09:00'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [09:00]]]` 

0 个答案:

没有答案