@Test public void getTripTest() throws Exception { User user = new User(); user.setId(1l); user.setUsername("damijano"); user.setFirstName("New"); user.setLastName("User"); user.setPassword("1234"); user.setEmail("*****@*****.**"); user.setResponsible("system"); user.setCreated(new Date()); user.setUpdated(new Date()); Trip trip = new Trip(); trip.setId(1l); trip.setTitle("Uživancija"); trip.setDestination("Ljubljana"); trip.setFreeSpaces(2); trip.setMeetingPoint("Celje"); trip.setStart(new Date()); trip.setFinish(new Date()); trip.setResponsible("damijano"); trip.setLeader(user); TripServiceImpl service = mock(TripServiceImpl.class); when(service.getTripById(1L)).thenReturn(trip); TripResource resource = new TripResource(); resource.service = service; Dispatcher dispatcher = MockDispatcherFactory.createDispatcher(); dispatcher.getRegistry().addSingletonResource(resource); { MockHttpRequest request = MockHttpRequest.get(URI + "/1"); MockHttpResponse response = new MockHttpResponse(); dispatcher.invoke(request, response); assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK); assertThat(response.getOutputHeaders().getFirst("Content-Type")) .isEqualTo(MediaType.APPLICATION_JSON_TYPE); assertThat(response.getContentAsString()).contains("{\"id\":1"); assertThat(response.getContentAsString()).excludes("password"); System.out.println(response.getContentAsString()); } }
private void prepareAdminUser() { User user = service.findUserByUsername(ADMIN_USER); if (user == null) { logger.info("Adding user '" + ADMIN_USER + "'."); Role role = service.findRoleByName(ADMIN_ROLE); Set<Role> roles = new HashSet<Role>(); roles.add(role); user = new User(); user.setUsername("admin"); user.setFirstName("Application"); user.setLastName("Administrator"); user.setPassword(ADMIN_PASSWORD); user.setEmail("*****@*****.**"); user.setResponsible("system"); user.setRoles(roles); service.addUser(user); } else { logger.info("User '" + ADMIN_USER + "' already present."); } }