summaryrefslogtreecommitdiff
path: root/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2024-06-19 00:14:49 +0200
committerOrangerot <purple@orangerot.dev>2024-06-27 12:11:14 +0200
commit5b8851b6c268d0e93c158908fbfae9f8473db5ff (patch)
tree7010eb85d86fa2da06ea4ffbcdb01a685d502ae8 /pse-server/src/test/java/org/psesquared/server/subscriptions/api/data
Initial commitHEADmain
Diffstat (limited to 'pse-server/src/test/java/org/psesquared/server/subscriptions/api/data')
-rw-r--r--pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionActionDaoTests.java89
-rw-r--r--pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionDaoTests.java36
2 files changed, 125 insertions, 0 deletions
diff --git a/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionActionDaoTests.java b/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionActionDaoTests.java
new file mode 100644
index 0000000..f296a72
--- /dev/null
+++ b/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionActionDaoTests.java
@@ -0,0 +1,89 @@
+package org.psesquared.server.subscriptions.api.data.access;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.util.List;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.psesquared.server.BaseTest;
+import org.psesquared.server.model.Subscription;
+import org.psesquared.server.model.SubscriptionAction;
+import org.psesquared.server.model.User;
+
+public class SubscriptionActionDaoTests extends BaseTest {
+
+ @Test
+ public void existsByUserAndSubscriptionTest() {
+ String username = "testUser0";
+ String subscriptionUrl = new File("testfeeds/testPodcast0.xml").toURI().toString();
+ User user = authenticationDao.findByUsername(username).orElseThrow();
+ Subscription subscription = subscriptionDao.findByUrl(subscriptionUrl).orElseThrow();
+ boolean exists = subscriptionActionDao.existsByUserAndSubscription(user, subscription);
+ assertTrue(exists);
+ }
+
+ @Test
+ public void findByUserAndSubscriptionTest() {
+ String username = "testUser0";
+ String subscriptionUrl = new File("testfeeds/testPodcast0.xml").toURI().toString();
+ User user = authenticationDao.findByUsername(username).orElseThrow();
+ Subscription subscription = subscriptionDao.findByUrl(subscriptionUrl).orElseThrow();
+ SubscriptionAction subscriptionAction = subscriptionActionDao.findByUserAndSubscription(user, subscription)
+ .orElseThrow();
+ assertEquals(subscriptionAction.getSubscription().getUrl(), subscriptionUrl);
+ }
+
+ @Test
+ public void findByUserUsernameAndTimestampGreaterThanEqualTest() {
+ String username = "testUser0";
+ // Jede SubscriptionAction eines Nutzers hat einen Timestamp von zusätzlichen
+ // 1000000 zur Zeit 0
+ int factor = 1;
+ int timeDifference = 1000000;
+ long since = factor * timeDifference;
+ List<SubscriptionAction> subscriptionActions = subscriptionActionDao
+ .findByUserUsernameAndTimestampGreaterThanEqual(username, since);
+ assertEquals(numberOfSubscriptionsPerUser - factor, subscriptionActions.size());
+ }
+
+ @Test
+ public void findByUserUsernameAndAddedTrueTest() {
+ String username = "testUser0";
+ List<SubscriptionAction> subscriptionActions = subscriptionActionDao.findByUserUsernameAndAddedTrue(username);
+ assertEquals(subscriptionActions.size(), numberOfSubscriptionsPerUser);
+ }
+
+ @Test
+ public void findByUserUsernameAndAddedTrueAndTimestampGreaterThanEqualTest() {
+ String username = "testUser0";
+ // Jede SubscriptionAction eines Nutzers hat einen Timestamp von zusätzlichen
+ // 1000000 zur Zeit 0
+ // int puffer = 1000;
+ int factor = 1;
+ int timeDifference = 1000000;
+ long since = factor * timeDifference;
+ List<SubscriptionAction> subscriptionActions = subscriptionActionDao
+ .findByUserUsernameAndTimestampGreaterThanEqual(username, since);
+ assertEquals(numberOfSubscriptionsPerUser - factor, subscriptionActions.size());
+ // Eine EpisodeAction der gefundenen EpisodeActions auf added=false setzen
+ subscriptionActions.get(0).setAdded(false);
+ subscriptionActionDao.save(subscriptionActions.get(0));
+ List<SubscriptionAction> subscriptionActions2 = subscriptionActionDao
+ .findByUserUsernameAndAddedTrueAndTimestampGreaterThanEqual(username, since);
+ assertEquals(numberOfSubscriptionsPerUser - factor - 1, subscriptionActions2.size());
+ }
+
+ @Test
+ public void deleteUserTest() {
+ String username = "testUser0";
+ User user = authenticationDao.findByUsername(username).orElseThrow();
+ Assertions.assertEquals(numberOfSubscriptionsPerUser,
+ subscriptionActionDao.findByUserUsernameAndAddedTrue(username).size());
+ authenticationDao.delete(user);
+ Assertions.assertEquals(0, subscriptionActionDao.findByUserUsernameAndAddedTrue(username).size());
+ }
+
+}
diff --git a/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionDaoTests.java b/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionDaoTests.java
new file mode 100644
index 0000000..3ae0089
--- /dev/null
+++ b/pse-server/src/test/java/org/psesquared/server/subscriptions/api/data/access/SubscriptionDaoTests.java
@@ -0,0 +1,36 @@
+package org.psesquared.server.subscriptions.api.data.access;
+
+import org.junit.jupiter.api.Test;
+import org.psesquared.server.BaseTest;
+import org.psesquared.server.model.Subscription;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.io.File;
+
+public class SubscriptionDaoTests extends BaseTest {
+
+ @Test
+ public void findByUrlTest() {
+ String url = new File("testfeeds/testPodcast0.xml").toURI().toString();
+ Subscription subscription = subscriptionDao.findByUrl(url).orElseThrow();
+ assertEquals(subscription.getUrl(), url);
+ }
+
+ @Test
+ public void existsByUrlTest() {
+ String url = new File("testfeeds/testPodcast0.xml").toURI().toString();
+ boolean exists = subscriptionDao.existsByUrl(url);
+ assertTrue(exists);
+ boolean notExists = subscriptionDao.existsByUrl("blablabla");
+ assertFalse(notExists);
+ }
+
+ @Test
+ public void testCascadeDelete() {
+ String url = new File("testfeeds/testPodcast0.xml").toURI().toString();
+ Subscription subscription = subscriptionDao.findByUrl(url).orElseThrow();
+ assertDoesNotThrow(() -> subscriptionDao.delete(subscription));
+ }
+
+}