implemented messages attachments

This commit is contained in:
Alfredo Oliviero 2024-10-22 16:37:00 +02:00
parent 660e399d44
commit 70cd652655
5 changed files with 143 additions and 52 deletions

View File

@ -4,11 +4,12 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.2.0-SNAPSHOT] ## [v2.2.1-SNAPSHOT]
- moved messages from storagehub to cassandra [#27514] - moved messages from storagehub to cassandra [#27514]
- import messages from storagehub
## [v2.1.1-SNAPSHOT] ## [v2.1.1]
- tests for Mail notification Catalogue Item Rejectsed [#28020] - tests for Mail notification Catalogue Item Rejectsed [#28020]

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId> <artifactId>social-networking-library</artifactId>
<version>2.2.0-SNAPSHOT</version> <version>2.2.1-SNAPSHOT</version>
<name>gCube Social Networking Library</name> <name>gCube Social Networking Library</name>
<description> <description>
The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities. The gCube Social Networking Library is the 'bridge' between your gCube Applications and the social networking facilities.

View File

@ -2541,13 +2541,15 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
_log.debug("Asking for Single Notification preference of " + userid + " Type: " + notificationType); _log.debug("Asking for Single Notification preference of " + userid + " Type: " + notificationType);
List<NotificationChannelType> toReturn = new ArrayList<NotificationChannelType>(); List<NotificationChannelType> toReturn = new ArrayList<NotificationChannelType>();
Map<NotificationType, NotificationChannelType[]> userNotPref = getUserNotificationPreferences(userid); Map<NotificationType, NotificationChannelType[]> userNotPref = getUserNotificationPreferences(userid);
if(userNotPref ==null || ! userNotPref.containsKey(notificationType) || userNotPref.get(notificationType) == null ) { if (userNotPref == null || !userNotPref.containsKey(notificationType)
_log.debug("Single Notification preference of " + userid + " Type: " + notificationType + " not existing ... creating default"); || userNotPref.get(notificationType) == null) {
_log.debug("Single Notification preference of " + userid + " Type: " + notificationType
+ " not existing ... creating default");
return createNewNotificationType(userid, notificationType); return createNewNotificationType(userid, notificationType);
} }
NotificationChannelType[] toProcess = userNotPref.get(notificationType); NotificationChannelType[] toProcess = userNotPref.get(notificationType);
if (toProcess.length == 0){ if (toProcess.length == 0) {
_log.debug("size of user notification preferences " + 0); _log.debug("size of user notification preferences " + 0);
return toReturn; return toReturn;
} }
@ -2572,16 +2574,17 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
String valueToInsert = ""; String valueToInsert = "";
NotificationChannelType[] wpTypes = NotificationChannelType.values(); NotificationChannelType[] wpTypes = NotificationChannelType.values();
// Set default channels to PORTAL for workspace notifications (starting with WP_), otherwise use all channels // Set default channels to PORTAL for workspace notifications (starting with
// WP_), otherwise use all channels
if (notificationType.toString().startsWith("WP_")) { if (notificationType.toString().startsWith("WP_")) {
valueToInsert += NotificationChannelType.PORTAL; valueToInsert += NotificationChannelType.PORTAL;
toReturn.add(NotificationChannelType.PORTAL); toReturn.add(NotificationChannelType.PORTAL);
} else { } else {
for (int i = 0; i < wpTypes.length; i++) { for (int i = 0; i < wpTypes.length; i++) {
valueToInsert += wpTypes[i]; valueToInsert += wpTypes[i];
if (i < wpTypes.length-1) if (i < wpTypes.length - 1)
valueToInsert += ","; valueToInsert += ",";
toReturn.add(wpTypes[i]); //add the new added notification type toReturn.add(wpTypes[i]); // add the new added notification type
} }
} }
@ -2646,7 +2649,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
* {@inheritDoc} * {@inheritDoc}
* *
* by default Workspace and Calendar Notifications are set to Portal * by default Workspace and Calendar Notifications are set to Portal
* check if the number of preferences found is the same of NotificationType.values().length, if different creates the missing entries * check if the number of preferences found is the same of
* NotificationType.values().length, if different creates the missing entries
*/ */
@Override @Override
public Map<NotificationType, NotificationChannelType[]> getUserNotificationPreferences(String userid) public Map<NotificationType, NotificationChannelType[]> getUserNotificationPreferences(String userid)
@ -2669,9 +2673,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
// Check if the number of results is different from the total number of NotificationType values, meaning some preferences are missing // Check if the number of results is different from the total number of
// NotificationType values, meaning some preferences are missing
List<Row> results = new ArrayList<>(); List<Row> results = new ArrayList<>();
if(result!=null) results = result.all(); if (result != null)
results = result.all();
if (results.size() != NotificationType.values().length) { if (results.size() != NotificationType.values().length) {
_log.debug("Userid " + userid + " settings incomplete, initiating missing preferences..."); _log.debug("Userid " + userid + " settings incomplete, initiating missing preferences...");
@ -2691,9 +2697,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
_log.debug("Missing preference for " + notificationType + ", setting default."); _log.debug("Missing preference for " + notificationType + ", setting default.");
NotificationChannelType[] defaultChannels; NotificationChannelType[] defaultChannels;
// Set default channels to PORTAL for workspace notifications (starting with WP_), otherwise use all channels // Set default channels to PORTAL for workspace notifications (starting with
// WP_), otherwise use all channels
if (notificationType.toString().startsWith("WP_")) { if (notificationType.toString().startsWith("WP_")) {
defaultChannels = new NotificationChannelType[]{ NotificationChannelType.PORTAL }; defaultChannels = new NotificationChannelType[] { NotificationChannelType.PORTAL };
} else { } else {
defaultChannels = NotificationChannelType.values(); defaultChannels = NotificationChannelType.values();
} }
@ -2711,12 +2718,18 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
results = (result != null) ? result.all() : new ArrayList<>(); results = (result != null) ? result.all() : new ArrayList<>();
} }
_log.debug("Notification preferences Found for " + userid + " : " + results.size()) ; _log.debug("Notification preferences Found for " + userid + " : " + results.size());
for (Row row: results){ for (Row row : results) {
String[] channels = row.getString(PREFERENCE).split(","); String[] channels = row.getString(PREFERENCE).split(",");
//_log.debug("Row : " + row.getString(PREFERENCE)); // _log.debug("Row : " + row.getString(PREFERENCE));
if (channels != null && channels.length == 1 && channels[0].toString().equals("") ) { //it is empty, preference is set to no notification at all if (channels != null && channels.length == 1 && channels[0].toString().equals("")) { // it is empty,
//_log.debug("adding CHANNELS NULL: " + getNotificationType(row.getString(TYPE)) + ", " + new NotificationChannelType[0]); // preference is set
// to no
// notification at
// all
// _log.debug("adding CHANNELS NULL: " +
// getNotificationType(row.getString(TYPE)) + ", " + new
// NotificationChannelType[0]);
toReturn.put(getNotificationType(row.getString(TYPE)), new NotificationChannelType[0]); toReturn.put(getNotificationType(row.getString(TYPE)), new NotificationChannelType[0]);
} else { } else {
NotificationChannelType[] toAdd = new NotificationChannelType[channels.length]; NotificationChannelType[] toAdd = new NotificationChannelType[channels.length];
@ -2725,12 +2738,13 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
toAdd[i] = (getChannelType(channels[i])); toAdd[i] = (getChannelType(channels[i]));
} }
} }
//_log.debug("adding channels not null: " + getNotificationType(row.getString(TYPE)) + ", " + toAdd.toString()); // _log.debug("adding channels not null: " +
// getNotificationType(row.getString(TYPE)) + ", " + toAdd.toString());
toReturn.put(getNotificationType(row.getString(TYPE)), toAdd); toReturn.put(getNotificationType(row.getString(TYPE)), toAdd);
} }
} }
_log.debug("Returning:"+toReturn.size()); _log.debug("Returning:" + toReturn.size());
return toReturn; return toReturn;
} }
@ -4933,7 +4947,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.setColumn(Schema.ISDELETED, QueryBuilder.literal(true)) // Imposta il campo 'read' al valore fornito .setColumn(Schema.ISDELETED, QueryBuilder.literal(true)) // Imposta il campo 'read' al valore fornito
.whereColumn(Schema.FROM_ID).isEqualTo(QueryBuilder.literal(sentMessage.getUser_id())) // Filtro per .whereColumn(Schema.FROM_ID).isEqualTo(QueryBuilder.literal(sentMessage.getUser_id())) // Filtro per
// 'from_id' // 'from_id'
.whereColumn(Schema.CREATION_TIME).isEqualTo(QueryBuilder.literal(sentMessage.getCreation_time().toInstant())) .whereColumn(Schema.CREATION_TIME)
.isEqualTo(QueryBuilder.literal(sentMessage.getCreation_time().toInstant()))
.whereColumn(Schema.MESSAGE_ID).isEqualTo(QueryBuilder.literal(sentMessage.getUUID())); // Filtro .whereColumn(Schema.MESSAGE_ID).isEqualTo(QueryBuilder.literal(sentMessage.getUUID())); // Filtro
// per // per
// 'message_id' // 'message_id'
@ -5014,8 +5029,20 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
return receivedMessage; return receivedMessage;
} }
protected boolean saveSentMessage(Message message, CqlSession session) { public boolean saveSentMessage(Message message, CqlSession session) {
// MessageSent messageSent = new MessageSent(message, false, false, false); // MessageSent messageSent = new MessageSent(message, false, false, false);
if (session == null)
session = conn.getKeyspaceSession();
boolean isread = false;
boolean isopened = false;
boolean isdeleted = false;
if (message instanceof MessageSent) {
MessageSent sent = (MessageSent) message;
isread = sent.isRead();
isopened = sent.isOpened();
isdeleted = sent.isDeleted();
}
RegularInsert insert = QueryBuilder.insertInto(Schema.TABLE_MESSAGES_SENT) RegularInsert insert = QueryBuilder.insertInto(Schema.TABLE_MESSAGES_SENT)
.value(Schema.MESSAGE_ID, QueryBuilder.literal(UUID.fromString(message.getId()))) .value(Schema.MESSAGE_ID, QueryBuilder.literal(UUID.fromString(message.getId())))
@ -5025,20 +5052,43 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.value(Schema.SUBJECT, QueryBuilder.literal(message.getSubject())) .value(Schema.SUBJECT, QueryBuilder.literal(message.getSubject()))
.value(Schema.BODY, QueryBuilder.literal(message.getBody())) .value(Schema.BODY, QueryBuilder.literal(message.getBody()))
.value(Schema.CREATION_TIME, QueryBuilder.literal(message.getCreation_time().toInstant())) .value(Schema.CREATION_TIME, QueryBuilder.literal(message.getCreation_time().toInstant()))
.value(Schema.ISREAD, QueryBuilder.literal(false)) .value(Schema.ISREAD, QueryBuilder.literal(isread))
.value(Schema.ISOPENED, QueryBuilder.literal(false)) .value(Schema.ISOPENED, QueryBuilder.literal(isopened))
.value(Schema.ISDELETED, QueryBuilder.literal(false)); .value(Schema.ISDELETED, QueryBuilder.literal(isdeleted));
session.execute(insert.build()); try {
_log.info("insert query {}", insert);
SimpleStatement builded = insert.build();
_log.info("builded query {}", builded);
session.execute(builded);
_log.debug("Wrote sent message with id " + message.getId());
} catch (Exception e) {
e.printStackTrace();
return false;
}
_log.debug("Wrote sent message with id " + message.getId()); _log.debug("Wrote sent message with id " + message.getId());
return true; return true;
} }
protected boolean saveReceivedMessage(Message message, String recipientId, CqlSession session) { public boolean saveReceivedMessage(Message message, String recipientId, CqlSession session) {
// MessageReceived messageReceived = new MessageReceived(message, recipientId, // MessageReceived messageReceived = new MessageReceived(message, recipientId,
// false, false, false); // false, false, false);
if (session == null)
session = conn.getKeyspaceSession();
boolean isread = false;
boolean isopened = false;
boolean isdeleted = false;
if (message instanceof MessageReceived) {
MessageReceived received = (MessageReceived) message;
isread = received.isRead();
isopened = received.isOpened();
isdeleted = received.isDeleted();
}
RegularInsert insert = QueryBuilder.insertInto(Schema.TABLE_MESSAGES_RECEIVED) RegularInsert insert = QueryBuilder.insertInto(Schema.TABLE_MESSAGES_RECEIVED)
.value(Schema.MESSAGE_ID, QueryBuilder.literal(UUID.fromString(message.getId()))) .value(Schema.MESSAGE_ID, QueryBuilder.literal(UUID.fromString(message.getId())))
@ -5049,18 +5099,28 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.value(Schema.SUBJECT, QueryBuilder.literal(message.getSubject())) .value(Schema.SUBJECT, QueryBuilder.literal(message.getSubject()))
.value(Schema.BODY, QueryBuilder.literal(message.getBody())) .value(Schema.BODY, QueryBuilder.literal(message.getBody()))
.value(Schema.CREATION_TIME, QueryBuilder.literal(message.getCreation_time().toInstant())) .value(Schema.CREATION_TIME, QueryBuilder.literal(message.getCreation_time().toInstant()))
.value(Schema.ISREAD, QueryBuilder.literal(false)) .value(Schema.ISREAD, QueryBuilder.literal(isread))
.value(Schema.ISOPENED, QueryBuilder.literal(false)) .value(Schema.ISOPENED, QueryBuilder.literal(isopened))
.value(Schema.ISDELETED, QueryBuilder.literal(false)); .value(Schema.ISDELETED, QueryBuilder.literal(isdeleted));
session.execute(insert.build()); try {
_log.info("insert query {}", insert);
SimpleStatement builded = insert.build();
_log.info("builded query {}", builded);
session.execute(builded);
_log.debug("Wrote sent message with id " + message.getId()); _log.debug("Wrote sent message with id " + message.getId());
} catch (Exception e) {
e.printStackTrace();
throw e;
// return false;
}
return true; return true;
} }
protected boolean saveAttachmentMessageEntry(String messageKey, Attachment toSave, CqlSession session) { public boolean saveAttachmentMessageEntry(String message_id, Attachment toSave, CqlSession session) {
// Inserting data // Inserting data
if (session == null) if (session == null)
session = conn.getKeyspaceSession(); session = conn.getKeyspaceSession();
@ -5068,7 +5128,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try { try {
RegularInsert insert = QueryBuilder.insertInto(Schema.TABLE_MESSAGES_ATTACHMENTS) RegularInsert insert = QueryBuilder.insertInto(Schema.TABLE_MESSAGES_ATTACHMENTS)
.value(Schema.MESSAGE_ID, QueryBuilder.literal(UUID.fromString(messageKey))) .value(Schema.MESSAGE_ID, QueryBuilder.literal(UUID.fromString(message_id)))
.value(Schema.ATTACH_ID, QueryBuilder.literal(UUID.fromString(toSave.getId()))) .value(Schema.ATTACH_ID, QueryBuilder.literal(UUID.fromString(toSave.getId())))
.value(Schema.URI, QueryBuilder.literal(toSave.getUri())) .value(Schema.URI, QueryBuilder.literal(toSave.getUri()))
.value(Schema.NAME, QueryBuilder.literal(toSave.getName())) .value(Schema.NAME, QueryBuilder.literal(toSave.getName()))
@ -5078,7 +5138,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
session.execute(insert.build()); session.execute(insert.build());
_log.debug("Wrote attachment " + toSave.getName() + " for message with id " + messageKey); _log.debug("Wrote attachment " + toSave.getName() + " for message with id " + message_id);
} catch (Exception e) { } catch (Exception e) {
@ -5155,7 +5215,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
@Override @Override
public Message sendMessage(String fromId, List<String> addresses, String subject, String body, public Message sendMessage(String fromId, List<String> addresses, String subject, String body,
List<Attachment> attachments) throws IllegalArgumentException { List<Attachment> attachments) throws IllegalArgumentException {
String messageId = UUID.randomUUID().toString(); // Generate UUID for the message return sendMessage(fromId, addresses, subject, body, attachments, Message.generateUUID());
}
@Override
public Message sendMessage(String fromId, List<String> addresses, String subject, String body,
List<Attachment> attachments, String messageId) throws IllegalArgumentException {
boolean has_attachments = attachments != null && !attachments.isEmpty(); boolean has_attachments = attachments != null && !attachments.isEmpty();
Message message = new Message(messageId, fromId, null, addresses, subject, body, new Date(), has_attachments); Message message = new Message(messageId, fromId, null, addresses, subject, body, new Date(), has_attachments);
@ -5219,7 +5284,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Update update = QueryBuilder.update(Schema.TABLE_MESSAGES_SENT) Update update = QueryBuilder.update(Schema.TABLE_MESSAGES_SENT)
.setColumn(Schema.ISREAD, QueryBuilder.literal(set_read)) // Imposta il campo 'read' al valore fornito .setColumn(Schema.ISREAD, QueryBuilder.literal(set_read)) // Imposta il campo 'read' al valore fornito
.whereColumn(Schema.FROM_ID).isEqualTo(QueryBuilder.literal(fromId)) // Filtro per 'from_id' .whereColumn(Schema.FROM_ID).isEqualTo(QueryBuilder.literal(fromId)) // Filtro per 'from_id'
.whereColumn(Schema.CREATION_TIME).isEqualTo(QueryBuilder.literal(sentMessage.getCreation_time().toInstant())) .whereColumn(Schema.CREATION_TIME)
.isEqualTo(QueryBuilder.literal(sentMessage.getCreation_time().toInstant()))
.whereColumn(Schema.MESSAGE_ID).isEqualTo(QueryBuilder.literal(UUID.fromString(messageId))); // Filtro .whereColumn(Schema.MESSAGE_ID).isEqualTo(QueryBuilder.literal(UUID.fromString(messageId))); // Filtro
// per // per
// 'message_id' // 'message_id'
@ -5258,7 +5324,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
} }
@Override @Override
public Attachment getMessageAttachmentById(String messageid, String attachid) { public Attachment getMessageAttachmentByIdFilename(String messageid, String attachid) {
if (attachid == null) { if (attachid == null) {
throw new NullArgumentException("the timeInMillis must be before today"); throw new NullArgumentException("the timeInMillis must be before today");

View File

@ -682,6 +682,7 @@ public interface DatabookStore {
void closeConnection(); void closeConnection();
public Message sendMessage(String fromId, List<String> addresses, String subject, String body, List<Attachment> attachments); public Message sendMessage(String fromId, List<String> addresses, String subject, String body, List<Attachment> attachments);
public Message sendMessage(String fromId, List<String> addresses, String subject, String body, List<Attachment> attachments, String messageId);
public List<MessageSent> getSentMessagesBySender(String fromId, Date timestamp, Integer limit); public List<MessageSent> getSentMessagesBySender(String fromId, Date timestamp, Integer limit);
public List<MessageReceived> getReceivedMessagesByRecipient(String recipientId, Date timestamp, Integer limit); public List<MessageReceived> getReceivedMessagesByRecipient(String recipientId, Date timestamp, Integer limit);
@ -697,7 +698,8 @@ public interface DatabookStore {
public MessageSent setSentMessageRead(String fromId, String messageId, boolean set_read); public MessageSent setSentMessageRead(String fromId, String messageId, boolean set_read);
public MessageReceived setReceivedMessageRead(String recipientId, String messageId, boolean set_read); public MessageReceived setReceivedMessageRead(String recipientId, String messageId, boolean set_read);
public Attachment getMessageAttachmentById(String messageId, String filename);
public Attachment getMessageAttachmentByIdFilename(String messageId, String filename);
public List<Attachment> getMessageAttachmentsById(String messageId); public List<Attachment> getMessageAttachmentsById(String messageId);
public List<MessageSent> getSentMessagesBySender(String fromId, String messageId, Date timestamp, Integer limit, public List<MessageSent> getSentMessagesBySender(String fromId, String messageId, Date timestamp, Integer limit,

View File

@ -90,6 +90,7 @@ public class MessagesTest extends BaseDbTest{
@Test @Test
public void testMessagesReceivedByRecipient() throws Exception { public void testMessagesReceivedByRecipient() throws Exception {
Message message = store.sendMessage(testFrom, recipients, "testMessagesReceivedByRecipient", body, null); Message message = store.sendMessage(testFrom, recipients, "testMessagesReceivedByRecipient", body, null);
assertNotNull(message);
List<MessageReceived> receiveds = store.getReceivedMessagesByRecipient(recipient, null, null); List<MessageReceived> receiveds = store.getReceivedMessagesByRecipient(recipient, null, null);
MessageReceived received = receiveds.get(0); MessageReceived received = receiveds.get(0);
@ -99,6 +100,7 @@ public class MessagesTest extends BaseDbTest{
@Test @Test
public void testUnreadMessagesReceivedByRecipient() throws Exception { public void testUnreadMessagesReceivedByRecipient() throws Exception {
Message message = store.sendMessage(testFrom, recipients, "testUnreadMessagesReceivedByRecipient", body, null); Message message = store.sendMessage(testFrom, recipients, "testUnreadMessagesReceivedByRecipient", body, null);
assertNotNull(message);
List<MessageReceived> receiveds = store.getReceivedMessagesByRecipient(recipient, null, null, 1, false, false, List<MessageReceived> receiveds = store.getReceivedMessagesByRecipient(recipient, null, null, 1, false, false,
null); null);
@ -386,10 +388,16 @@ public class MessagesTest extends BaseDbTest{
public void testSentMessagesOrderedByTimestampDescending() throws Exception { public void testSentMessagesOrderedByTimestampDescending() throws Exception {
// Invia tre messaggi con timestamp differenti // Invia tre messaggi con timestamp differenti
Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null); Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null);
assertNotNull(message1);
Thread.sleep(1000); // Attendi 1 secondo per garantire un timestamp diverso Thread.sleep(1000); // Attendi 1 secondo per garantire un timestamp diverso
Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null); Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null);
assertNotNull(message2);
Thread.sleep(1000); // Attendi un altro secondo Thread.sleep(1000); // Attendi un altro secondo
Message message3 = store.sendMessage(testFrom, recipients, subject + "3", body, null); Message message3 = store.sendMessage(testFrom, recipients, subject + "3", body, null);
assertNotNull(message3);
// Recupera tutti i messaggi inviati dall'utente // Recupera tutti i messaggi inviati dall'utente
List<MessageSent> sentMessages = store.getSentMessagesBySender(testFrom, null, 10); List<MessageSent> sentMessages = store.getSentMessagesBySender(testFrom, null, 10);
@ -413,10 +421,16 @@ public class MessagesTest extends BaseDbTest{
public void testReceivedMessagesOrderedByTimestampDescending() throws Exception { public void testReceivedMessagesOrderedByTimestampDescending() throws Exception {
// Invia tre messaggi con timestamp differenti // Invia tre messaggi con timestamp differenti
Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null); Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null);
assertNotNull(message1);
Thread.sleep(1000); // Attendi 1 secondo per garantire un timestamp diverso Thread.sleep(1000); // Attendi 1 secondo per garantire un timestamp diverso
Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null); Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null);
assertNotNull(message2);
Thread.sleep(1000); // Attendi un altro secondo Thread.sleep(1000); // Attendi un altro secondo
Message message3 = store.sendMessage(testFrom, recipients, subject + "3", body, null); Message message3 = store.sendMessage(testFrom, recipients, subject + "3", body, null);
assertNotNull(message3);
// Recupera tutti i messaggi ricevuti dal destinatario // Recupera tutti i messaggi ricevuti dal destinatario
List<MessageReceived> receivedMessages = store.getReceivedMessagesByRecipient(recipient, null, 10); List<MessageReceived> receivedMessages = store.getReceivedMessagesByRecipient(recipient, null, 10);
@ -439,6 +453,8 @@ public class MessagesTest extends BaseDbTest{
public void testUnreadMessagesOnlyReturned() throws Exception { public void testUnreadMessagesOnlyReturned() throws Exception {
// Invia un messaggio normale // Invia un messaggio normale
Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null); Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null);
assertNotNull(message1);
// Invia un altro messaggio che verrà marcato come letto // Invia un altro messaggio che verrà marcato come letto
Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null); Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null);
@ -457,10 +473,16 @@ public class MessagesTest extends BaseDbTest{
public void testMessagesWithLimitAndOrder() throws Exception { public void testMessagesWithLimitAndOrder() throws Exception {
// Invia tre messaggi // Invia tre messaggi
Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null); Message message1 = store.sendMessage(testFrom, recipients, subject + "1", body, null);
assertNotNull(message1);
Thread.sleep(1000); // Attendi 1 secondo Thread.sleep(1000); // Attendi 1 secondo
Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null); Message message2 = store.sendMessage(testFrom, recipients, subject + "2", body, null);
assertNotNull(message2);
Thread.sleep(1000); Thread.sleep(1000);
Message message3 = store.sendMessage(testFrom, recipients, subject + "3", body, null); Message message3 = store.sendMessage(testFrom, recipients, subject + "3", body, null);
assertNotNull(message3);
// Recupera i primi due messaggi inviati, ordinati in modo decrescente per // Recupera i primi due messaggi inviati, ordinati in modo decrescente per
// timestamp // timestamp
@ -620,7 +642,7 @@ public class MessagesTest extends BaseDbTest{
assertNotNull("cannot obtain attach ", attach_id + "by msg id " + msg_id); assertNotNull("cannot obtain attach ", attach_id + "by msg id " + msg_id);
checkEqualAttachments(attach, by_message_id); checkEqualAttachments(attach, by_message_id);
Attachment by_attach_id = store.getMessageAttachmentById(msg_id, attach_id); Attachment by_attach_id = store.getMessageAttachmentByIdFilename(msg_id, attach_id);
assertNotNull("cannot obtain attach by id", attach_id); assertNotNull("cannot obtain attach by id", attach_id);
checkEqualAttachments(attach, by_attach_id); checkEqualAttachments(attach, by_attach_id);
} }