private SimpleDocument createFrenchSimpleAttachment() {
   String language = "fr";
   String fileName = "test.odp";
   String title = "Mon document de test";
   String description = "Ceci est un document de test";
   String creatorId = "10";
   Date creationDate = RandomGenerator.getRandomCalendar().getTime();
   SimpleAttachment file =
       new SimpleAttachment(
           fileName,
           language,
           title,
           description,
           "Ceci est un test".getBytes(Charsets.UTF_8).length,
           MimeTypes.MIME_TYPE_OO_PRESENTATION,
           creatorId,
           creationDate,
           null);
   SimpleDocumentPK pk = new SimpleDocumentPK(null, instanceId);
   pk.setOldSilverpeasId(5);
   SimpleDocument attachment = new HistorisedDocument();
   attachment.setPK(pk);
   attachment.setFile(file);
   attachment.setForeignId("12");
   return AttachmentServiceFactory.getAttachmentService()
       .createAttachment(
           attachment, new ByteArrayInputStream("Ceci est un test".getBytes(Charsets.UTF_8)));
 }
 /**
  * Test of convertXMLToNotificationData method, of class NotificationServerUtil.
  *
  * @throws Exception
  */
 @Test
 public void testConvertXMLToNotificationData() throws Exception {
   Date dateParam = RandomGenerator.getRandomCalendar().getTime();
   String p_XML =
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<NOTIFY>	<LOGIN>		<USER>"
           + "<![CDATA[user]]></USER>		<PASSWORD><![CDATA[password]]></PASSWORD>	</LOGIN>	"
           + "<MESSAGE><![CDATA[message]]></MESSAGE>	<SENDER>		<ID><![CDATA[bart.simpson@silverpeas"
           + ".com]]></ID>		<NAME><![CDATA[Bart Simpson]]></NAME>		<ANSWERALLOWED>true"
           + "</ANSWERALLOWED>	</SENDER>	<COMMENT><![CDATA[comment]]></COMMENT>	<TARGET CHANNEL=\"SMTP\">"
           + "		<NAME><![CDATA[Home Simpson]]></NAME>		<RECEIPT><![CDATA[receipt]]></RECEIPT>		"
           + "<PARAM><![CDATA[date=#DATE#"
           + dateParam.getTime()
           + ";string=bonjour le monde;; 0 + 0 == la tête à "
           + "toto]]></PARAM>	</TARGET>	<PRIORITY SPEED=\"fast\"/>	<REPORT>	</REPORT></NOTIFY>";
   NotificationData expResult = new NotificationData();
   Map<String, Object> params = new HashMap<String, Object>(2);
   params.put("string", "bonjour le monde; 0 + 0 = la tête à toto");
   params.put("date", dateParam);
   expResult.setAnswerAllowed(true);
   expResult.setComment("comment");
   expResult.setLoginPassword("password");
   expResult.setLoginUser("user");
   expResult.setMessage("message");
   expResult.setNotificationId(0L);
   expResult.setPrioritySpeed("fast");
   expResult.setSenderId("*****@*****.**");
   expResult.setSenderName("Bart Simpson");
   expResult.setTargetChannel("SMTP");
   expResult.setTargetName("Home Simpson");
   expResult.setTargetParam(params);
   expResult.setTargetReceipt("receipt");
   NotificationData result = NotificationServerUtil.convertXMLToNotificationData(p_XML);
   assertEquals(expResult, result);
 }
 /** 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 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();
   }
 }