@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); } } }
@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())); }
@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); }
@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); }
@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()); }
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()); }