From 8e1994d596b8eaddeda523beb0ef075be8cd35cb Mon Sep 17 00:00:00 2001 From: Alfredo Oliviero Date: Tue, 1 Oct 2024 11:15:32 +0200 Subject: [PATCH] junit for notifications --- .../databook/server/NotificationsTest.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/test/java/org/gcube/portal/databook/server/NotificationsTest.java diff --git a/src/test/java/org/gcube/portal/databook/server/NotificationsTest.java b/src/test/java/org/gcube/portal/databook/server/NotificationsTest.java new file mode 100644 index 0000000..6d9f455 --- /dev/null +++ b/src/test/java/org/gcube/portal/databook/server/NotificationsTest.java @@ -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 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 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 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()); + } + } + +}