Esempio n. 1
0
 @Before
 public void initTest() {
   news = new News();
   news.setTitle(DEFAULT_TITLE);
   news.setDate(DEFAULT_DATE);
   news.setContent(DEFAULT_CONTENT);
 }
Esempio n. 2
0
  /** POST /newss -> Create a new news. */
  @RequestMapping(
      value = "/newss",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<News> createNews(@Valid @RequestBody News news) throws URISyntaxException {
    log.debug("REST request to save News : {}", news);
    if (news.getId() != null) {
      return ResponseEntity.badRequest()
          .headers(
              HeaderUtil.createFailureAlert(
                  "news", "idexists", "A new news cannot already have an ID"))
          .body(null);
    }
    News result = newsRepository.save(news);
    List<Subscription> subscriptions =
        subscriptionRepository
            .findAll()
            .stream()
            .filter(item -> (item.getIdMarketPlace().equals(result.getMarketPlace().getId())))
            .collect(Collectors.toList());
    String title = result.getMarketPlace().getName() + " vous a envoyé une News !";
    String content = result.getTitle() + "\n\n\n" + result.getContent();

    for (Subscription subscription : subscriptions) {
      mailService.sendEmail(subscription.getUser().getEmail(), title, content, false, false);
    }
    return ResponseEntity.created(new URI("/api/newss/" + result.getId()))
        .headers(HeaderUtil.createEntityCreationAlert("news", result.getId().toString()))
        .body(result);
  }
Esempio n. 3
0
 /** PUT /newss -> Updates an existing news. */
 @RequestMapping(
     value = "/newss",
     method = RequestMethod.PUT,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<News> updateNews(@Valid @RequestBody News news) throws URISyntaxException {
   log.debug("REST request to update News : {}", news);
   if (news.getId() == null) {
     return createNews(news);
   }
   News result = newsRepository.save(news);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityUpdateAlert("news", news.getId().toString()))
       .body(result);
 }
Esempio n. 4
0
  @Test
  @Transactional
  public void getNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    // Get the news
    restNewsMockMvc
        .perform(get("/api/newss/{id}", news.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(news.getId().intValue()))
        .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString()))
        .andExpect(jsonPath("$.date").value(DEFAULT_DATE_STR))
        .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString()));
  }
Esempio n. 5
0
  @Test
  @Transactional
  public void updateNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    int databaseSizeBeforeUpdate = newsRepository.findAll().size();

    // Update the news
    news.setTitle(UPDATED_TITLE);
    news.setDate(UPDATED_DATE);
    news.setContent(UPDATED_CONTENT);

    restNewsMockMvc
        .perform(
            put("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isOk());

    // Validate the News in the database
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeUpdate);
    News testNews = newss.get(newss.size() - 1);
    assertThat(testNews.getTitle()).isEqualTo(UPDATED_TITLE);
    assertThat(testNews.getDate()).isEqualTo(UPDATED_DATE);
    assertThat(testNews.getContent()).isEqualTo(UPDATED_CONTENT);
  }
Esempio n. 6
0
  @Test
  @Transactional
  public void createNews() throws Exception {
    int databaseSizeBeforeCreate = newsRepository.findAll().size();

    // Create the News

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isCreated());

    // Validate the News in the database
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeCreate + 1);
    News testNews = newss.get(newss.size() - 1);
    assertThat(testNews.getTitle()).isEqualTo(DEFAULT_TITLE);
    assertThat(testNews.getDate()).isEqualTo(DEFAULT_DATE);
    assertThat(testNews.getContent()).isEqualTo(DEFAULT_CONTENT);
  }
Esempio n. 7
0
  @Test
  @Transactional
  public void deleteNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    int databaseSizeBeforeDelete = newsRepository.findAll().size();

    // Get the news
    restNewsMockMvc
        .perform(delete("/api/newss/{id}", news.getId()).accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeDelete - 1);
  }
Esempio n. 8
0
  @Test
  @Transactional
  public void checkContentIsRequired() throws Exception {
    int databaseSizeBeforeTest = newsRepository.findAll().size();
    // set the field null
    news.setContent(null);

    // Create the News, which fails.

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isBadRequest());

    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeTest);
  }