/** Test of selectByStatus method, of class PublicationDAO. */ @Test public void testSelectByStatus_3args_2() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); List<String> componentIds = new ArrayList<String>(); componentIds.add("kmelia200"); componentIds.add("kmelia201"); String status = "Valid"; Collection<PublicationDetail> result = PublicationDAO.selectByStatus(con, componentIds, status); assertEquals(result.size(), 2); status = "Draft"; result = PublicationDAO.selectByStatus(con, componentIds, status); assertEquals(result.size(), 0); status = "Valid"; componentIds.remove("kmelia200"); result = PublicationDAO.selectByStatus(con, componentIds, status); assertEquals(result.size(), 0); } finally { connection.close(); } }
/** Test of selectByFatherIds method, of class PublicationDAO. */ @Test public void testSelectByFatherIds() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); List<String> fatherIds = new ArrayList<String>(); fatherIds.add("110"); PublicationPK pubPK = new PublicationPK("useless", "kmelia200"); String sorting = "P.pubName"; List<String> status = new ArrayList<String>(); status.add("Valid"); boolean filterOnVisibilityPeriod = true; ArrayList<PublicationDetail> result = PublicationDAO.selectByFatherIds( con, fatherIds, pubPK, sorting, status, filterOnVisibilityPeriod); assertEquals(result.size(), 2); // Test on an empty node fatherIds.clear(); fatherIds.add("999"); result = PublicationDAO.selectByFatherIds( con, fatherIds, pubPK, sorting, status, filterOnVisibilityPeriod); assertEquals(result.size(), 0); } finally { connection.close(); } }
/** Test of changeInstanceId method, of class PublicationDAO. */ @Test public void testChangeInstanceId() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pk = new PublicationPK("100", "kmelia200"); PublicationDetail detail = PublicationDAO.loadRow(con, pk); assertEquals(pk, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); String targetInstance = "kmelia" + RandomGenerator.getRandomInt(600); PublicationDAO.changeInstanceId(con, pk, targetInstance); pk = new PublicationPK("100", targetInstance); detail = PublicationDAO.loadRow(con, pk); assertEquals(pk, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals(targetInstance, detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); } finally { connection.close(); } }
/** Test of selectByNameAndNodeId method, of class PublicationDAO. */ @Test public void testSelectByNameAndNodeId() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pubPK = new PublicationPK("100", "kmelia200"); String name = "Publication 1"; int nodeId = 110; PublicationDetail result = PublicationDAO.selectByNameAndNodeId(con, pubPK, name, nodeId); assertEquals(pubPK, result.getPK()); assertEquals("Homer Simpson", result.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(result.getBeginDate())); assertEquals("00:00", result.getBeginHour()); assertEquals("Contenu de la publication 1", result.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(result.getCreationDate())); assertEquals("100", result.getCreatorId()); assertEquals("Première publication de test", result.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(result.getEndDate())); assertEquals("23:59", result.getEndHour()); assertEquals(1, result.getImportance()); assertEquals("0", result.getInfoId()); assertEquals("kmelia200", result.getInstanceId()); assertEquals("test", result.getKeywords()); assertEquals("Publication 1", result.getName()); assertEquals("Valid", result.getStatus()); assertEquals("300", result.getValidatorId()); assertEquals("Publication 1", result.getTitle()); } finally { connection.close(); } }
/** Test of selectByStatus method, of class PublicationDAO. */ @Test public void testSelectByStatus_3args_1() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pubPK = new PublicationPK("useless", "kmelia200"); String status = "Valid"; Collection<PublicationDetail> result = PublicationDAO.selectByStatus(con, pubPK, status); assertEquals(result.size(), 2); status = "Draft"; result = PublicationDAO.selectByStatus(con, pubPK, status); assertEquals(result.size(), 0); } finally { connection.close(); } }
/** Test of selectByFatherPK method, of class PublicationDAO. */ @Test public void testSelectByFatherPK_Connection_NodePK() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); NodePK fatherPK = new NodePK("110", "kmelia200"); Collection<PublicationDetail> result = PublicationDAO.selectByFatherPK(con, fatherPK); assertNotNull(result); assertEquals(2, result.size()); Iterator<PublicationDetail> iter = result.iterator(); PublicationDetail detail = iter.next(); PublicationPK primaryKey = new PublicationPK("100", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); detail = iter.next(); primaryKey = new PublicationPK("101", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Bart Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("01:10", detail.getBeginHour()); assertEquals("Contenu de la publication 2", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("101", detail.getCreatorId()); assertEquals("2ème publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("20:35", detail.getEndHour()); assertEquals(5, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 2", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 2", detail.getTitle()); } finally { connection.close(); } }
@Test public void testGetAllPublicationsIDbyUserid() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); String user100 = "100"; // who created pub1 String user200 = "200"; // who updated pub1 and pub2 String pub1Id = "100"; PublicationDetail detail1 = PublicationDAO.loadRow(con, new PublicationPK(pub1Id)); // who created pub1 SocialInformationPublication sp1 = new SocialInformationPublication(new PublicationWithStatus((detail1), false)); assertNotNull("SocialInformationPublication1 must be not null", sp1); List<SocialInformation> list100 = new ArrayList<SocialInformation>(); list100.add(sp1); Date begin = DateUtil.parse("2008/11/01"); Date end = DateUtil.parse("2008/11/30"); List<SocialInformation> list100DOA = PublicationDAO.getAllPublicationsIDbyUserid(con, user100, begin, end); assertEquals("Must be equal", list100.get(0), list100DOA.get(0)); // who created pub2 String user101 = "101"; // who created pub2 String pub2Id = "101"; PublicationDetail detail2 = PublicationDAO.loadRow(con, new PublicationPK(pub2Id)); SocialInformationPublication sp2 = new SocialInformationPublication(new PublicationWithStatus((detail2), false)); assertNotNull("SocialInformationPublication2 must be not null", sp2); List<SocialInformation> list101 = new ArrayList<SocialInformation>(); list101.add(sp2); List<SocialInformation> list101DOA = PublicationDAO.getAllPublicationsIDbyUserid(con, user101, begin, end); assertTrue("Must be equal", list101.get(0).equals(list101DOA.get(0))); // who updated pub1 and pub2 begin = DateUtil.parse("2009/11/01"); end = DateUtil.parse("2009/11/30"); SocialInformationPublication sp1User200 = new SocialInformationPublication(new PublicationWithStatus((detail1), true)); assertNotNull("SocialInformationPublication2 must be not null", sp1User200); SocialInformationPublication sp2User200 = new SocialInformationPublication(new PublicationWithStatus((detail2), true)); assertNotNull("SocialInformationPublication2 must be not null", sp2User200); List<SocialInformation> list200 = new ArrayList<SocialInformation>(); list200.add(sp2User200); list200.add(sp1User200); List<SocialInformation> list200DOA = PublicationDAO.getAllPublicationsIDbyUserid(con, user200, begin, end); assertEquals("Must be equal", list200.get(0), list200DOA.get(0)); assertEquals("Must be equal", list200.get(1), list200DOA.get(1)); // test nbr of elements list200DOA = PublicationDAO.getAllPublicationsIDbyUserid(con, user200, begin, end); assertEquals("Must be equal", list200.get(0), list200DOA.get(0)); List<String> options = new ArrayList<String>(); options.add("kmelia200"); List<String> myContactsIds = new ArrayList<String>(); myContactsIds.add(user100); myContactsIds.add(user200); list200DOA = PublicationDAO.getSocialInformationsListOfMyContacts( con, myContactsIds, options, begin, end); assertNotNull("SocialInformationPublication of my contact must be not null", list200DOA); assertTrue( "SocialInformationPublication of my contact must be not empty", !list200DOA.isEmpty()); } finally { connection.close(); } }
/** Test of insertRow method, of class PublicationDAO. */ @Test public void testInsertRow() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pk = new PublicationPK("500", "kmelia36"); Calendar now = Calendar.getInstance(); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.HOUR_OF_DAY, 0); Calendar beginDate = RandomGenerator.getCalendarAfter(now); Calendar endDate = RandomGenerator.getCalendarAfter(beginDate); String name = RandomGenerator.getRandomString(); String description = RandomGenerator.getRandomString(); String creatorId = "" + RandomGenerator.getRandomInt(); int importance = RandomGenerator.getRandomInt(5); String version = RandomGenerator.getRandomString(); String contenu = RandomGenerator.getRandomString(); StringBuilder buffer = new StringBuilder(); int nbKeywords = RandomGenerator.getRandomInt(5) + 2; for (int i = 0; i < nbKeywords; i++) { buffer.append(RandomGenerator.getRandomString()); if (i < (nbKeywords - 1)) { buffer.append(' '); } } String keywords = buffer.toString(); PublicationDetail detail = new PublicationDetail( pk, name, description, now.getTime(), beginDate.getTime(), endDate.getTime(), creatorId, importance, version, keywords, contenu); detail.setBeginHour(DateUtil.formatTime(beginDate)); detail.setEndHour(DateUtil.formatTime(endDate)); PublicationDAO.insertRow(con, detail); PublicationDetail result = PublicationDAO.loadRow(con, pk); detail.setUpdateDate(now.getTime()); detail.setUpdaterId(creatorId); detail.setInfoId("0"); assertEquals(detail.getPK(), result.getPK()); assertEquals(detail.getAuthor(), result.getAuthor()); assertEquals(detail.getBeginDate(), result.getBeginDate()); assertEquals(detail.getBeginHour(), result.getBeginHour()); assertEquals(detail.getContent(), result.getContent()); assertEquals(detail.getCreationDate(), result.getCreationDate()); assertEquals(detail.getUpdateDate(), result.getCreationDate()); assertEquals(detail.getCreatorId(), result.getCreatorId()); assertEquals(detail.getDescription(), result.getDescription()); assertEquals(detail.getEndDate(), result.getEndDate()); assertEquals(detail.getEndHour(), result.getEndHour()); assertEquals(detail.getImportance(), result.getImportance()); assertEquals(detail.getInfoId(), result.getInfoId()); assertEquals(detail.getInstanceId(), result.getInstanceId()); assertEquals(detail.getKeywords(), result.getKeywords()); assertEquals(detail.getName(), result.getName()); assertEquals(detail.getStatus(), result.getStatus()); assertEquals(detail.getTitle(), result.getTitle()); } finally { connection.close(); } }
/** Test of storeRow method, of class PublicationDAO. */ @Test public void testStoreRow() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); PublicationPK pk = new PublicationPK("100", "kmelia200"); PublicationDetail detail = PublicationDAO.loadRow(con, pk); assertEquals(pk, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); Calendar now = Calendar.getInstance(); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.HOUR_OF_DAY, 0); Calendar beginDate = RandomGenerator.getCalendarAfter(now); Calendar endDate = RandomGenerator.getCalendarAfter(beginDate); String name = RandomGenerator.getRandomString(); String description = RandomGenerator.getRandomString(); String creatorId = "" + RandomGenerator.getRandomInt(); int importance = RandomGenerator.getRandomInt(5); String version = RandomGenerator.getRandomString(); String contenu = RandomGenerator.getRandomString(); StringBuilder buffer = new StringBuilder(); int nbKeywords = RandomGenerator.getRandomInt(5) + 2; for (int i = 0; i < nbKeywords; i++) { buffer.append(RandomGenerator.getRandomString()); if (i < (nbKeywords - 1)) { buffer.append(' '); } } String keywords = buffer.toString(); detail.setName(name); detail.setDescription(description); detail.setCreationDate(now.getTime()); detail.setBeginDateAndHour(beginDate.getTime()); detail.setEndDateAndHour(endDate.getTime()); detail.setCreatorId(creatorId); detail.setImportance(importance); detail.setVersion(version); detail.setKeywords(keywords); detail.setContent(contenu); detail.setBeginHour(DateUtil.formatTime(beginDate)); detail.setEndHour(DateUtil.formatTime(endDate)); PublicationDAO.storeRow(con, detail); PublicationDetail result = PublicationDAO.loadRow(con, pk); detail.setUpdateDate(now.getTime()); detail.setUpdaterId(creatorId); detail.setInfoId("0"); assertEquals(detail.getPK(), result.getPK()); assertEquals(detail.getAuthor(), result.getAuthor()); assertEquals(detail.getBeginDate(), result.getBeginDate()); assertEquals(detail.getBeginHour(), result.getBeginHour()); assertEquals(detail.getContent(), result.getContent()); assertEquals(detail.getCreationDate(), result.getCreationDate()); assertEquals(detail.getUpdateDate(), result.getCreationDate()); assertEquals(detail.getCreatorId(), result.getCreatorId()); assertEquals(detail.getDescription(), result.getDescription()); assertEquals(detail.getEndDate(), result.getEndDate()); assertEquals(detail.getEndHour(), result.getEndHour()); assertEquals(detail.getImportance(), result.getImportance()); assertEquals(detail.getInfoId(), result.getInfoId()); assertEquals(detail.getInstanceId(), result.getInstanceId()); assertEquals(detail.getKeywords(), result.getKeywords()); assertEquals(detail.getName(), result.getName()); assertEquals(detail.getStatus(), result.getStatus()); assertEquals(detail.getTitle(), result.getTitle()); } finally { connection.close(); } }
/** Test of selectByFatherPK method, of class PublicationDAO. */ @Test public void testSelectByFatherPK_5args() throws Exception { IDatabaseConnection connection = getConnection(); try { Connection con = connection.getConnection(); NodePK fatherPK = new NodePK("110", "kmelia200"); String sorting = null; boolean filterOnVisibilityPeriod = false; String userId = "100"; Collection<PublicationDetail> result = PublicationDAO.selectByFatherPK(con, fatherPK, sorting, filterOnVisibilityPeriod, userId); assertNotNull(result); assertEquals(1, result.size()); Iterator<PublicationDetail> iter = result.iterator(); PublicationDetail detail = iter.next(); PublicationPK primaryKey = new PublicationPK("100", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); filterOnVisibilityPeriod = true; result = PublicationDAO.selectByFatherPK(con, fatherPK, sorting, filterOnVisibilityPeriod, userId); assertNotNull(result); assertEquals(1, result.size()); iter = result.iterator(); detail = iter.next(); primaryKey = new PublicationPK("100", "kmelia200"); assertEquals(primaryKey, detail.getPK()); assertEquals("Homer Simpson", detail.getAuthor()); assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate())); assertEquals("00:00", detail.getBeginHour()); assertEquals("Contenu de la publication 1", detail.getContent()); assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate())); assertEquals("100", detail.getCreatorId()); assertEquals("Première publication de test", detail.getDescription()); assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate())); assertEquals("23:59", detail.getEndHour()); assertEquals(1, detail.getImportance()); assertEquals("0", detail.getInfoId()); assertEquals("kmelia200", detail.getInstanceId()); assertEquals("test", detail.getKeywords()); assertEquals("Publication 1", detail.getName()); assertEquals("Valid", detail.getStatus()); assertEquals("300", detail.getValidatorId()); assertEquals("Publication 1", detail.getTitle()); } finally { connection.close(); } }