junit for notifications

This commit is contained in:
Alfredo Oliviero 2024-10-01 11:15:32 +02:00
parent dbc43a5ed9
commit 8e1994d596
1 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,115 @@
package org.gcube.portal.databook.server;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.gcube.portal.databook.shared.NotificationChannelType;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portal.databook.shared.ex.NotificationChannelTypeNotFoundException;
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
import org.junit.Test;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
import com.datastax.oss.driver.api.querybuilder.delete.Delete;
import com.datastax.oss.driver.api.querybuilder.select.Select;
public class NotificationsTest extends BaseDbTest {
protected String userId = "alfredo.oliviero";
// protected String userId = "alina.sirbu";
@Test
public void baseQuery() throws Exception {
CqlSession session = getConnection().getKeyspaceSession();
SimpleStatement test_count = SimpleStatement.builder(
"select * from vretimeline limit 1")
// .addPositionalValues(set_read, userId, UUID.fromString(messageId))
.build();
ResultSet result = session.execute(test_count);
List<Row> all = result.all();
org.junit.Assert.assertTrue(all.size() == 1);
// _log.info("baseTest found {}", all.get(0));
System.out.print("baseTest found" + all.get(0));
}
@Test
public void preferencesNotificatonsConfig()
throws NotificationTypeNotFoundException, NotificationChannelTypeNotFoundException, Exception {
Map<NotificationType, NotificationChannelType[]> preferences = getStore()
.getUserNotificationPreferences(userId);
for (NotificationType type : preferences.keySet()) {
System.out.println("## preferences type " + type);
for (NotificationChannelType channelType : preferences.get(type)) {
System.out.println("## -- " + channelType);
}
}
}
@Test
public void prefNotificatonChannels()
throws NotificationChannelTypeNotFoundException, NotificationTypeNotFoundException, Exception {
List<NotificationChannelType> channels = getStore().getUserNotificationChannels(userId,
NotificationType.CAT_ITEM_PUBLISHED);
for (NotificationChannelType channel : channels) {
System.out.println("## -- " + channel);
}
}
@Test
public void getCatPreferencesQuery() throws Exception {
Select select = QueryBuilder.selectFrom(Schema.USER_NOTIFICATIONS_PREFERENCES)
.all()
.whereColumn("userid").isEqualTo(QueryBuilder.literal(userId))
.whereColumn("type").in(
// QueryBuilder.literal("WP_ITEM_NEW"),
QueryBuilder.literal("CAT_ITEM_DELETE"),
QueryBuilder.literal("CAT_ITEM_PUBLISHED"),
QueryBuilder.literal("CAT_ITEM_REJECTED"),
QueryBuilder.literal("CAT_ITEM_SUBMITTED"),
QueryBuilder.literal("CAT_ITEM_UPDATED"));
SimpleStatement statement = select.build();
CqlSession session = getConnection().getKeyspaceSession();
ResultSet resultSet = session.execute(statement);
for (Row row : resultSet) {
// Supponendo che la tua tabella abbia colonne "userid", "type", e altre
String userId = row.getString("userid");
String type = row.getString("type");
// Stampa i valori delle colonne
System.out.println("UserId: " + userId + ", Type: " + type);
}
}
@Test
public void deleteCatPreferencesQuery() throws Exception {
Delete delete = QueryBuilder.deleteFrom(Schema.USER_NOTIFICATIONS_PREFERENCES)
.whereColumn("userid").isEqualTo(QueryBuilder.literal(userId))
.whereColumn("type").in(
QueryBuilder.literal("CAT_ITEM_DELETE"),
QueryBuilder.literal("CAT_ITEM_PUBLISHED"),
QueryBuilder.literal("CAT_ITEM_REJECTED"),
QueryBuilder.literal("CAT_ITEM_SUBMITTED"),
QueryBuilder.literal("CAT_ITEM_UPDATED"));
SimpleStatement statement = delete.build();
CqlSession session = getConnection().getKeyspaceSession();
ResultSet resultSet = session.execute(statement);
for (Row row : resultSet) {
// Stampa i valori delle colonne
System.out.println(row.getFormattedContents());
}
}
}