Exemplo n.º 1
1
 @Test
 public void serviceContacts() throws Exception {
   Trip t = new TimelessTrip("Trip 1", "Beschrijving", TripPrivacy.PUBLIC, testUser);
   User user1 = new User("Polle", "Hallo");
   user1.setFirstName("Polledvdp");
   user1.setLastName("Van de Pol");
   User user2 = new User("Bert", "Hallo");
   Enrollment enroll = new Enrollment(t, testUser);
   Enrollment enroll2 = new Enrollment(t, user1);
   Enrollment enroll3 = new Enrollment(t, user2);
   enroll.setStatus(Status.BUSY);
   enroll2.setStatus(Status.BUSY);
   ArrayList<Enrollment> enrollments = new ArrayList<>();
   enrollments.add(enroll);
   enrollments.add(enroll2);
   enrollments.add(enroll3);
   RequestBuilder requestBuilder =
       MockMvcRequestBuilders.post("/service/contacts")
           .param("username", "mathias")
           .param("password", "fred")
           .param("id", t.getId() + "");
   when(tripsService.checkLogin(anyString(), anyString())).thenReturn(true);
   when(tripsService.findUser(anyString())).thenReturn(testUser);
   when(tripsService.findEnrollmentsByTrip(t)).thenReturn(enrollments);
   when(tripsService.findTripById(t.getId(), testUser)).thenReturn(t);
   mockMvc
       .perform(requestBuilder)
       .andExpect(
           content()
               .string(
                   "{\"valid\":true,\"contacts\":[{\"firstName\":\"Polledvdp\",\"lastName\":\"Van de Pol\",\"email\":\"Polle\",\"latitude\":0,\"longitude\":0}]}"));
 }
Exemplo n.º 2
1
 @Test
 public void tripbyIdServiceSucces() throws Exception {
   Trip t = new TimelessTrip("Trip 1", "Beschrijving", TripPrivacy.PUBLIC, testUser);
   Enrollment enroll = new Enrollment(t, testUser);
   enroll.setStatus(Status.BUSY);
   Enrollment enroll2 = new Enrollment(t, new User("Mathias", "Bert"));
   enroll2.setStatus(Status.BUSY);
   ArrayList<Enrollment> enrollments = new ArrayList<>();
   enrollments.add(enroll);
   enrollments.add(enroll2);
   RequestBuilder requestBuilder =
       MockMvcRequestBuilders.post("/service/trip")
           .param("username", "mathias")
           .param("password", "fred")
           .param("id", t.getId() + "");
   when(tripsService.checkLogin(anyString(), anyString())).thenReturn(true);
   when(tripsService.findUser(anyString())).thenReturn(testUser);
   when(tripsService.findTripById(t.getId(), testUser)).thenReturn(t);
   when(tripsService.findEnrollmentsByUser(testUser)).thenReturn(enrollments);
   mockMvc
       .perform(requestBuilder)
       .andExpect(
           content()
               .string(
                   "{\"valid\":true,\"id\":"
                       + t.getId()
                       + ",\"title\":\"Trip 1\",\"description\":\"Beschrijving\",\"enrollments\":2,\"organizer\":\"[email protected]\",\"privacy\":\"PUBLIC\",\"isenrolled\":true,\"isstarted\":true,\"isactive\":false,\"istimeless\":true}"));
 }
Exemplo n.º 3
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}]}"));
 }