@Test public void testCreateProject() throws IOException, Exception { _dbInjecter.injectUser("ProjectManager"); Project project = new Project(); project.setName("PROJECT"); project.setDescription("this is a project!"); project.setLatitude(1.0f); project.setLongitude(2.0f); project.setShopActive(true); project.setVisible(true); project.setManager(_userRepository.findByName("ProjectManager")); String userToken = _tokenAuthenticationService.getTokenFromUser(_userRepository.findById(1L).orElse(null)); mockMvc.perform(post(Uris.PROJECT_CREATE).header("X-AUTH-TOKEN", userToken).contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(project))) .andExpect(status().isOk()); assertThat(_projectRepository.count()).isEqualTo(1L); }
@RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) public ResponseEntity<?> createProject(@RequestBody Project project) { try { projectRepository.save(project); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }
ProjectController { @RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) public ResponseEntity<?> createProject(@RequestBody Project project) { try { projectRepository.save(project); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } }
ProjectController { @RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) public ResponseEntity<?> createProject(@RequestBody Project project) { try { projectRepository.save(project); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }  }
ProjectController { @RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) public ResponseEntity<?> createProject(@RequestBody Project project) { try { projectRepository.save(project); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }  @RequestMapping(value = Uris.PROJECTS, method = RequestMethod.GET) @JsonView(Views.ProjectNameAndId.class) ResponseEntity<?> getAllProjects(); @RequestMapping(value = Uris.PROJECT, method = RequestMethod.GET) @JsonView(Views.ProjectData.class) ResponseEntity<?> getProject(@RequestParam long projectId); @RequestMapping(value = Uris.ARTICLES, method = RequestMethod.GET) @JsonView(Views.ProjectArticle.class) ResponseEntity<?> getArticlesForProject(@RequestParam long projectId); @RequestMapping(value = Uris.IMAGES, method = RequestMethod.GET) @JsonView(Views.ProjectImage.class) ResponseEntity<?> getImagesForProject(@RequestParam long projectId); @RequestMapping(value = Uris.PROJECT_EDIT, method = RequestMethod.POST) ResponseEntity<?> editProject(@RequestBody Project project); @RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) ResponseEntity<?> createProject(@RequestBody Project project); @RequestMapping(value = Uris.PROJECT_DELETE, method = RequestMethod.DELETE) ResponseEntity<?> deleteProject(@RequestParam Long id); @RequestMapping(value = Uris.PROJECT_REMOVE_ARTICLE, method = RequestMethod.POST) ResponseEntity<?> removeArticle(@RequestParam Long articleId); @RequestMapping(value = Uris.PROJECT_MAIN_IMAGE, method = RequestMethod.POST) @Transactional ResponseEntity<?> addMainImage(@RequestParam Long projectId, @RequestParam("file") MultipartFile file); @RequestMapping(value = Uris.PROJECT_IMAGE_CREATE_EDIT, method = RequestMethod.POST) @Transactional ResponseEntity<?> createEditProjectImageData(@RequestBody ProjectImageRequest projectImageRequest); @RequestMapping(value = Uris.PROJECT_IMAGE_UPLOAD, method = RequestMethod.POST) @Transactional ResponseEntity<?> uploadUserImage(@RequestParam Long imageId, @RequestParam("file") MultipartFile file); @RequestMapping(value = Uris.PROJECT_IMAGE_DELETE, method = RequestMethod.POST) ResponseEntity<?> removeProjectImage(@RequestParam Long projectImageId, @RequestParam String imageFileName); }
ProjectController { @RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) public ResponseEntity<?> createProject(@RequestBody Project project) { try { projectRepository.save(project); return new ResponseEntity<>(HttpStatus.OK); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } }  @RequestMapping(value = Uris.PROJECTS, method = RequestMethod.GET) @JsonView(Views.ProjectNameAndId.class) ResponseEntity<?> getAllProjects(); @RequestMapping(value = Uris.PROJECT, method = RequestMethod.GET) @JsonView(Views.ProjectData.class) ResponseEntity<?> getProject(@RequestParam long projectId); @RequestMapping(value = Uris.ARTICLES, method = RequestMethod.GET) @JsonView(Views.ProjectArticle.class) ResponseEntity<?> getArticlesForProject(@RequestParam long projectId); @RequestMapping(value = Uris.IMAGES, method = RequestMethod.GET) @JsonView(Views.ProjectImage.class) ResponseEntity<?> getImagesForProject(@RequestParam long projectId); @RequestMapping(value = Uris.PROJECT_EDIT, method = RequestMethod.POST) ResponseEntity<?> editProject(@RequestBody Project project); @RequestMapping(value = Uris.PROJECT_CREATE, method = RequestMethod.POST) ResponseEntity<?> createProject(@RequestBody Project project); @RequestMapping(value = Uris.PROJECT_DELETE, method = RequestMethod.DELETE) ResponseEntity<?> deleteProject(@RequestParam Long id); @RequestMapping(value = Uris.PROJECT_REMOVE_ARTICLE, method = RequestMethod.POST) ResponseEntity<?> removeArticle(@RequestParam Long articleId); @RequestMapping(value = Uris.PROJECT_MAIN_IMAGE, method = RequestMethod.POST) @Transactional ResponseEntity<?> addMainImage(@RequestParam Long projectId, @RequestParam("file") MultipartFile file); @RequestMapping(value = Uris.PROJECT_IMAGE_CREATE_EDIT, method = RequestMethod.POST) @Transactional ResponseEntity<?> createEditProjectImageData(@RequestBody ProjectImageRequest projectImageRequest); @RequestMapping(value = Uris.PROJECT_IMAGE_UPLOAD, method = RequestMethod.POST) @Transactional ResponseEntity<?> uploadUserImage(@RequestParam Long imageId, @RequestParam("file") MultipartFile file); @RequestMapping(value = Uris.PROJECT_IMAGE_DELETE, method = RequestMethod.POST) ResponseEntity<?> removeProjectImage(@RequestParam Long projectImageId, @RequestParam String imageFileName);  }