コード例 #1
0
  @Test
  public void secondPassageOfMiddleSensorIsIgnored() {
    CurrentRaceStatus currentRaceStatus = new CurrentRaceStatus();
    currentRaceStatus.setState(RaceStatus.State.ACTIVE);
    currentRaceStatus.setCallbackUrl(callbackUrl);
    repository.save(currentRaceStatus);

    given()
        .param("sensorID", "SPLIT")
        .param("timestamp", 1234)
        .when()
        .post(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.ACCEPTED.value());
    given()
        .param("sensorID", "SPLIT")
        .param("timestamp", 12345)
        .when()
        .post(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.ALREADY_REPORTED.value());

    currentRaceStatus = repository.findByRaceId(CurrentRaceStatus.ID);
    verify(restTemplateMock, times(1))
        .postForLocation(
            "http://localhost:" + port + "/onracestatusupdate",
            RaceStatus.builder()
                .event(RaceStatus.Event.MIDDLE)
                .middleTime(new Date(1234))
                .state(RaceStatus.State.ACTIVE)
                .build());
    assertNotNull(currentRaceStatus);
    assertEquals(new Long(1234), currentRaceStatus.getMiddleTime());
  }
コード例 #2
0
  @Test
  public void canGetStatusOnlyByGet() {
    when()
        .post(CurrentRaceController.STATUS_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    when()
        .delete(CurrentRaceController.STATUS_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    when()
        .put(CurrentRaceController.STATUS_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    when()
        .patch(CurrentRaceController.STATUS_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());

    CurrentRaceStatus currentRaceStatus = new CurrentRaceStatus();
    currentRaceStatus.setState(RaceStatus.State.ACTIVE);
    repository.save(currentRaceStatus);

    when()
        .get(CurrentRaceController.STATUS_URL)
        .then()
        .statusCode(HttpStatus.OK.value())
        .body("state", is(RaceStatus.State.ACTIVE.name()));
  }
コード例 #3
0
  @Test
  public void startRace_returnFoundIfAlreadyActive() {
    CurrentRaceStatus currentRaceStatus = new CurrentRaceStatus();
    currentRaceStatus.setState(RaceStatus.State.ACTIVE);
    repository.save(currentRaceStatus);

    given()
        .param("callbackUrl", "asd")
        .when()
        .post(CurrentRaceController.START_RACE_URL)
        .then()
        .statusCode(HttpStatus.FOUND.value());
  }
コード例 #4
0
  @Test
  public void canNotUpdatePassageTime_WithFaultySensorID() {
    CurrentRaceStatus currentRaceStatus = new CurrentRaceStatus();
    currentRaceStatus.setState(RaceStatus.State.ACTIVE);
    repository.save(currentRaceStatus);

    given()
        .param("sensorID", "FAULTY")
        .param("timestamp", 1234)
        .when()
        .post(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.EXPECTATION_FAILED.value());
  }
コード例 #5
0
  @Test
  public void canStartRace_OnlyByPost() {
    given()
        .param(CurrentRaceController.START_RACE_URL, "asd")
        .when()
        .get("/startRace")
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    given()
        .param(CurrentRaceController.START_RACE_URL, "asd")
        .when()
        .delete("/startRace")
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    given()
        .param(CurrentRaceController.START_RACE_URL, "asd")
        .when()
        .put("/startRace")
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    given()
        .param(CurrentRaceController.START_RACE_URL, "asd")
        .when()
        .patch("/startRace")
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());

    given()
        .param("callbackUrl", "asd")
        .when()
        .post(CurrentRaceController.START_RACE_URL)
        .then()
        .statusCode(HttpStatus.ACCEPTED.value());

    CurrentRaceStatus currentRaceStatus = repository.findByRaceId(CurrentRaceStatus.ID);

    assertNotNull(currentRaceStatus);
    assertEquals(RaceStatus.State.ACTIVE, currentRaceStatus.getState());
  }
コード例 #6
0
  @Test
  public void canCancelRaceIfStartedAndOnlyPost() {
    when()
        .get(CurrentRaceController.CANCEL_RACE_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    when()
        .put(CurrentRaceController.CANCEL_RACE_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    when()
        .delete(CurrentRaceController.CANCEL_RACE_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    when()
        .patch(CurrentRaceController.CANCEL_RACE_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());

    CurrentRaceStatus currentRaceStatus = new CurrentRaceStatus();
    currentRaceStatus.setState(RaceStatus.State.ACTIVE);
    currentRaceStatus.setCallbackUrl(callbackUrl);
    repository.save(currentRaceStatus);

    when()
        .post(CurrentRaceController.CANCEL_RACE_URL)
        .then()
        .statusCode(HttpStatus.ACCEPTED.value());

    currentRaceStatus = repository.findByRaceId(CurrentRaceStatus.ID);

    verify(restTemplateMock, atLeastOnce())
        .postForLocation(
            "http://localhost:" + port + "/onracestatusupdate",
            RaceStatus.builder().state(RaceStatus.State.INACTIVE).build());

    assertNotNull(currentRaceStatus);
    assertEquals(RaceStatus.State.INACTIVE, currentRaceStatus.getState());
  }
コード例 #7
0
  @Test
  public void canUpdatePassageTime_OnlyByPost() {
    given()
        .param("sensorID", "START")
        .param("timestamp", 1234)
        .when()
        .get(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    given()
        .param("sensorID", "START")
        .param("timestamp", 1234)
        .when()
        .delete(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    given()
        .param("sensorID", "START")
        .param("timestamp", 1234)
        .when()
        .put(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());
    given()
        .param("sensorID", "START")
        .param("timestamp", 1234)
        .when()
        .patch(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.METHOD_NOT_ALLOWED.value());

    CurrentRaceStatus currentRaceStatus = new CurrentRaceStatus();
    currentRaceStatus.setState(RaceStatus.State.ACTIVE);
    currentRaceStatus.setCallbackUrl(callbackUrl);
    repository.save(currentRaceStatus);

    assertEquals(1, repository.findAll().size());
    given()
        .param("sensorID", "START")
        .param("timestamp", 1234)
        .when()
        .post(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.ACCEPTED.value());
    given()
        .param("sensorID", "SPLIT")
        .param("timestamp", 12345)
        .when()
        .post(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.ACCEPTED.value());
    given()
        .param("sensorID", "FINISH")
        .param("timestamp", 123456)
        .when()
        .post(CurrentRaceController.PASSAGE_DETECTED_URL)
        .then()
        .statusCode(HttpStatus.ACCEPTED.value());

    currentRaceStatus = repository.findByRaceId(CurrentRaceStatus.ID);

    verify(restTemplateMock, times(1))
        .postForLocation(
            "http://localhost:" + port + "/onracestatusupdate",
            RaceStatus.builder()
                .event(RaceStatus.Event.START)
                .startTime(new Date(1234))
                .state(RaceStatus.State.ACTIVE)
                .build());
    verify(restTemplateMock, times(1))
        .postForLocation(
            "http://localhost:" + port + "/onracestatusupdate",
            RaceStatus.builder()
                .event(RaceStatus.Event.MIDDLE)
                .startTime(new Date(1234))
                .middleTime(new Date(12345))
                .state(RaceStatus.State.ACTIVE)
                .build());
    verify(restTemplateMock, times(1))
        .postForLocation(
            "http://localhost:" + port + "/onracestatusupdate",
            RaceStatus.builder()
                .event(RaceStatus.Event.FINISH)
                .startTime(new Date(1234))
                .middleTime(new Date(12345))
                .finishTime(new Date(123456))
                .state(RaceStatus.State.INACTIVE)
                .build());
    assertNotNull(currentRaceStatus);
    assertEquals(new Long(1234), currentRaceStatus.getStartTime());
    assertEquals(new Long(12345), currentRaceStatus.getMiddleTime());
    assertEquals(new Long(123456), currentRaceStatus.getFinishTime());
    assertEquals(RaceStatus.Event.FINISH, currentRaceStatus.getEvent());
    assertEquals(RaceStatus.State.INACTIVE, currentRaceStatus.getState());
  }