@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
 @RequestMapping(
     value = "/report",
     method = RequestMethod.POST,
     headers = "Accept=application/json")
 public ResponseEntity<Map<String, Object>> userReport(@RequestBody Report rp) {
   Map<String, Object> map = new HashMap<String, Object>();
   if (reportDao.saveReport(rp) == true) {
     map.put("MESSAGE", "REPORT HAS BEEN SENT");
     map.put("STATUS", HttpStatus.ACCEPTED.value());
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
   } else {
     map.put("MESSAGE", "REPORT HAS BEEN SENT FIALED");
     map.put("STATUS", HttpStatus.NOT_ACCEPTABLE.value());
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
   }
 }
예제 #3
0
 @RequestMapping(
     value = "/signup",
     method = RequestMethod.POST,
     headers = "Accept=application/json")
 public ResponseEntity<Map<String, Object>> userSignup(
     @RequestBody User user, HttpServletResponse respone) {
   Map<String, Object> map = new HashMap<String, Object>();
   if (userDao.saveUser(user) == true) {
     map.put("MESSAGE", "USER HAS BEEN SIGN UP");
     map.put("STATUS", HttpStatus.ACCEPTED.value());
     map.put("DATA", userDao.getUserByEmail(user.getEmail()));
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
   } else {
     map.put("MESSAGE", "USER SIGN UP FIALED");
     map.put("STATUS", HttpStatus.NOT_ACCEPTABLE.value());
     return new ResponseEntity<Map<String, Object>>(map, HttpStatus.NOT_ACCEPTABLE);
   }
 }
  @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());
  }
  @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());
  }
  @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());
  }