Пример #1
0
  @Test
  @DatabaseSetup(PATH_TO_NEWS)
  public void testList() throws Exception {

    List<News> list = newsDAO.list();

    Assert.assertNotNull(list);

    for (News news : list) {

      Assert.assertNotNull(news);

      if (news.getId() == 1L) {

        News newsExp = new News();
        newsExp.setShortText("test short");
        newsExp.setFullText("test full");
        newsExp.setTitle("test title");
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = dateFormat.parse("01/01/2015 11:10:00");
        newsExp.setCreationDate(date);
        newsExp.setModificationDate(new Timestamp(date.getTime()));
        newsExp.setId(1L);

        assertNews(newsExp, news);
      }
    }
  }
Пример #2
0
  @Before
  public void setUp() throws Exception {

    expectedNews = new News();
    expectedNews.setShortText("test short");
    expectedNews.setFullText("test full");
    expectedNews.setTitle("test title");
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    Date date = dateFormat.parse("01/01/2015 11:10:00");
    expectedNews.setCreationDate(date);
    expectedNews.setModificationDate(new Timestamp(date.getTime()));
  }
Пример #3
0
  @Test
  @DatabaseSetup(PATH_TO_NEWS)
  public void testFetchById() throws Exception {

    News actual = newsDAO.fetchById(1L);
    Assert.assertNotNull(actual);
    News newsExp = new News();
    newsExp.setShortText("test short");
    newsExp.setFullText("test full");
    newsExp.setTitle("test title");
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    Date date = dateFormat.parse("01/01/2015 11:10:00");
    newsExp.setCreationDate(date);
    newsExp.setModificationDate(new Timestamp(date.getTime()));
    newsExp.setId(1L);
    assertNews(newsExp, actual);
  }
Пример #4
0
  @Test
  @DatabaseSetup(PATH_TO_NEWS)
  public void testUpdate() throws Exception {

    News news = new News();
    news.setId(3l);
    news.setShortText("new");
    news.setFullText("new");
    news.setTitle("new");
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    Date date = dateFormat.parse("01/01/2015 11:10:00");
    news.setCreationDate(date);
    news.setModificationDate(new Timestamp(date.getTime()));

    newsDAO.update(news);

    News actual = newsDAO.fetchById(3L);

    assertNews(news, actual);
  }
Пример #5
0
  @Test
  @DatabaseSetup(PATH_TO_NEWS)
  public void testSave() throws Exception {

    Long id = newsDAO.add(expectedNews);

    News actual = newsDAO.fetchById(id);

    Assert.assertEquals(expectedNews.getCreationDate(), actual.getCreationDate());
    Assert.assertEquals(expectedNews.getFullText(), actual.getFullText());
    Assert.assertEquals(expectedNews.getShortText(), actual.getShortText());
    Assert.assertEquals(expectedNews.getModificationDate(), actual.getModificationDate());
    Assert.assertEquals(expectedNews.getTitle(), actual.getTitle());
  }
Пример #6
0
  private void assertNews(News expected, News actual) {

    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getCreationDate(), actual.getCreationDate());
    Assert.assertEquals(expected.getFullText(), actual.getFullText());
    Assert.assertEquals(expected.getShortText(), actual.getShortText());
    Assert.assertEquals(expected.getModificationDate(), actual.getModificationDate());
    Assert.assertEquals(expected.getTitle(), actual.getTitle());
  }