Beispiel #1
1
 @Test
 public void getLocationsService() throws Exception {
   Trip t = new TimelessTrip("Trip 1", "Beschrijving", TripPrivacy.PUBLIC, testUser);
   Enrollment enroll = new Enrollment(t, testUser);
   enroll.setStatus(Status.BUSY);
   ArrayList<Enrollment> enrollments = new ArrayList<>();
   enrollments.add(enroll);
   t.setLocations(new ArrayList<Location>());
   Location l1 = new Location(t, 12.00, 13.00, null, "Location", "Aangename location1", 0);
   Location l2 = new Location(t, 12.00, 13.00, null, "Location", "Aangename location2", 1);
   Location l3 = new Location(t, 12.00, 13.00, null, "Location", "Aangename location3", 2);
   Location l4 = new Location(t, 12.00, 13.00, null, "Location", "Aangename location4", 3);
   Location l5 = new Location(t, 12.00, 13.00, null, "Location", "Aangename location5", 4);
   List<String> antwoorden = new ArrayList<>();
   antwoorden.add("Groep A");
   antwoorden.add("Groep B");
   antwoorden.add("Groep C");
   antwoorden.add("Groep D");
   l1.addQuestion(new Question("Welke groep is de beste?", antwoorden, 2, null));
   l2.addQuestion(new Question("Welke groep is de beste?", antwoorden, 2, null));
   l3.addQuestion(new Question("Welke groep is de beste?", antwoorden, 2, null));
   l5.addQuestion(new Question("Welke groep is de beste?", antwoorden, 2, null));
   t.addLocation(l1);
   t.addLocation(l2);
   t.addLocation(l3);
   t.addLocation(l4);
   t.addLocation(l5);
   Map answeredQuestions = new HashMap<Question, Boolean>();
   answeredQuestions.put(l1.getQuestion(), Boolean.TRUE);
   answeredQuestions.put(l2.getQuestion(), Boolean.FALSE);
   answeredQuestions.put(l3.getQuestion(), Boolean.TRUE);
   answeredQuestions.put(l5.getQuestion(), Boolean.TRUE);
   enroll.setAnsweredQuestions(answeredQuestions);
   RequestBuilder requestBuilder =
       MockMvcRequestBuilders.post("/service/locations")
           .param("username", testUser.getEmail())
           .param("password", "password")
           .param("id", t.getId() + "");
   when(tripsService.checkLogin(anyString(), anyString())).thenReturn(true);
   when(tripsService.findTripById(t.getId(), testUser)).thenReturn(t);
   when(tripsService.findUser(testUser.getEmail())).thenReturn(testUser);
   when(tripsService.findEnrollmentsByUser(testUser)).thenReturn(enrollments);
   mockMvc
       .perform(requestBuilder)
       .andExpect(
           content()
               .string(
                   "{\"valid\":true,\"locations\":[{\"id\":null,\"title\":\"Location\",\"latitude\":12,\"longitude\":13,\"description\":\"Aangename location1\",\"question\":\"Welke groep is de beste?\",\"possibleAnswers\":[\"Groep A\",\"Groep B\",\"Groep C\",\"Groep D\"],\"answered\":true,\"correct\":true},{\"id\":null,\"title\":\"Location\",\"latitude\":12,\"longitude\":13,\"description\":\"Aangename location2\",\"question\":\"Welke groep is de beste?\",\"possibleAnswers\":[\"Groep A\",\"Groep B\",\"Groep C\",\"Groep D\"],\"answered\":true,\"correct\":true},{\"id\":null,\"title\":\"Location\",\"latitude\":12,\"longitude\":13,\"description\":\"Aangename location3\",\"question\":\"Welke groep is de beste?\",\"possibleAnswers\":[\"Groep A\",\"Groep B\",\"Groep C\",\"Groep D\"],\"answered\":true,\"correct\":true},{\"id\":null,\"title\":\"Location\",\"latitude\":12,\"longitude\":13,\"description\":\"Aangename location4\",\"question\":null},{\"id\":null,\"title\":\"Location\",\"latitude\":12,\"longitude\":13,\"description\":\"Aangename location5\",\"question\":\"Welke groep is de beste?\",\"possibleAnswers\":[\"Groep A\",\"Groep B\",\"Groep C\",\"Groep D\"],\"answered\":true,\"correct\":true}]}"));
 }
Beispiel #2
1
  @Test
  public void questionServiceSucces() throws Exception {
    Trip t = new TimelessTrip("Trip 1", "Beschrijving", TripPrivacy.PUBLIC, testUser);
    Location l1 = new Location(t, 12.00, 13.00, null, "Location", "Aangename location1", 0);
    List<String> antwoorden = new ArrayList<>();
    antwoorden.add("Groep A");
    antwoorden.add("Groep B");
    antwoorden.add("Groep C");
    antwoorden.add("Groep D");

    l1.addQuestion(new Question("Welke groep is de beste?", antwoorden, 2, null));
    when(tripsService.checkLogin(anyString(), anyString())).thenReturn(true);
    when(tripsService.findUser(anyString())).thenReturn(testUser);
    when(tripsService.findLocationById(anyInt())).thenReturn(l1);
    when(tripsService.checkAnswerFromQuestion(any(Question.class), anyInt(), any(User.class)))
        .thenReturn(true);
    RequestBuilder requestBuilder =
        MockMvcRequestBuilders.post("/service/answerQuestion")
            .param("username", "mathias")
            .param("password", "fred")
            .param("answerIndex", 2 + "")
            .param("locationId", 0 + "");
    mockMvc
        .perform(requestBuilder)
        .andExpect(content().string("{\"valid\":true,\"correct\":true}"));
  }