@Before public void initTest() { pictureRepository.deleteAll(); picture = new Picture(); picture.setTitle(DEFAULT_TITLE); picture.setDescription(DEFAULT_DESCRIPTION); picture.setPictureFile(ByteBuffer.wrap(DEFAULT_PICTURE_FILE)); picture.setCreated(DEFAULT_CREATED); picture.setModified(DEFAULT_MODIFIED); }
@Test public void getPicture() throws Exception { // Initialize the database pictureRepository.save(picture); // Get the picture restPictureMockMvc .perform(get("/api/pictures/{id}", picture.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(picture.getId().toString())) .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString())) .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString())) .andExpect(jsonPath("$.pictureFile").value(DEFAULT_PICTURE_FILE.toString())) .andExpect(jsonPath("$.favourites").value(DEFAULT_FAVOURITES)) .andExpect(jsonPath("$.likes").value(DEFAULT_LIKES)) .andExpect(jsonPath("$.created").value(DEFAULT_CREATED.getTime())) .andExpect(jsonPath("$.modified").value(DEFAULT_MODIFIED.getTime())); }
@Test public void createPicture() throws Exception { int databaseSizeBeforeCreate = pictureRepository.findAll().size(); // Create the Picture PictureDTO pictureDTO = pictureMapper.pictureToPictureDTO(picture); restPictureMockMvc .perform( post("/api/pictures") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(pictureDTO))) .andExpect(status().isCreated()); // Validate the Picture in the database List<Picture> pictures = pictureRepository.findAll(); assertThat(pictures).hasSize(databaseSizeBeforeCreate + 1); Picture testPicture = pictures.get(pictures.size() - 1); assertThat(testPicture.getTitle()).isEqualTo(DEFAULT_TITLE); assertThat(testPicture.getDescription()).isEqualTo(DEFAULT_DESCRIPTION); assertThat(testPicture.getPictureFile()).isEqualTo(DEFAULT_PICTURE_FILE); assertThat(testPicture.getCreated()).isEqualTo(DEFAULT_CREATED); assertThat(testPicture.getModified()).isEqualTo(DEFAULT_MODIFIED); }
@Test public void deletePicture() throws Exception { // Initialize the database pictureRepository.save(picture); int databaseSizeBeforeDelete = pictureRepository.findAll().size(); // Get the picture restPictureMockMvc .perform( delete("/api/pictures/{id}", picture.getId()).accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate the database is empty List<Picture> pictures = pictureRepository.findAll(); assertThat(pictures).hasSize(databaseSizeBeforeDelete - 1); }
@Test public void checkTitleIsRequired() throws Exception { int databaseSizeBeforeTest = pictureRepository.findAll().size(); // set the field null picture.setTitle(null); // Create the Picture, which fails. PictureDTO pictureDTO = pictureMapper.pictureToPictureDTO(picture); restPictureMockMvc .perform( post("/api/pictures") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(pictureDTO))) .andExpect(status().isBadRequest()); List<Picture> pictures = pictureRepository.findAll(); assertThat(pictures).hasSize(databaseSizeBeforeTest); }
@Test public void updatePicture() throws Exception { // Initialize the database pictureRepository.save(picture); int databaseSizeBeforeUpdate = pictureRepository.findAll().size(); // Update the picture picture.setTitle(UPDATED_TITLE); picture.setDescription(UPDATED_DESCRIPTION); picture.setPictureFile(ByteBuffer.wrap(UPDATED_PICTURE_FILE)); picture.setCreated(UPDATED_CREATED); picture.setModified(UPDATED_MODIFIED); PictureDTO pictureDTO = pictureMapper.pictureToPictureDTO(picture); restPictureMockMvc .perform( put("/api/pictures") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(pictureDTO))) .andExpect(status().isOk()); // Validate the Picture in the database List<Picture> pictures = pictureRepository.findAll(); assertThat(pictures).hasSize(databaseSizeBeforeUpdate); Picture testPicture = pictures.get(pictures.size() - 1); assertThat(testPicture.getTitle()).isEqualTo(UPDATED_TITLE); assertThat(testPicture.getDescription()).isEqualTo(UPDATED_DESCRIPTION); assertThat(testPicture.getPictureFile()).isEqualTo(UPDATED_PICTURE_FILE); assertThat(testPicture.getCreated()).isEqualTo(UPDATED_CREATED); assertThat(testPicture.getModified()).isEqualTo(UPDATED_MODIFIED); }