Search in sources :

Example 56 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testAllPublishers.

@Test
public void testAllPublishers() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    List<Publisher> publishers = notificationManager.getAllPublisher();
    Assert.assertNotNull(publishers);
    Assert.assertTrue(publishers.contains(publisher));
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 57 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testSubscribe.

@Test
public void testSubscribe() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("subs-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(publisher);
    // subscribe
    notificationManager.subscribe(id, context, publisherData);
    dbInstance.commitAndCloseSession();
    // check
    boolean subscribed = notificationManager.isSubscribed(id, context);
    Assert.assertTrue(subscribed);
    dbInstance.commitAndCloseSession();
    // double check
    Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
    Assert.assertNotNull(subscriber);
    Assert.assertEquals(publisher, subscriber.getPublisher());
    dbInstance.commitAndCloseSession();
    // triple check
    Subscriber reloadedSubscriber = notificationManager.getSubscriber(subscriber.getKey());
    Assert.assertNotNull(reloadedSubscriber);
    Assert.assertEquals(subscriber, reloadedSubscriber);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 58 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testMarkSubscriberRead.

@Test
public void testMarkSubscriberRead() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("subs-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("All", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testAllPublishers", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commit();
    Assert.assertNotNull(publisher);
    // subscribe
    notificationManager.subscribe(id, context, publisherData);
    dbInstance.commit();
    // load the subscriber
    Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
    Assert.assertNotNull(subscriber);
    dbInstance.commitAndCloseSession();
    sleep(2000);
    notificationManager.markSubscriberRead(id, context);
    // check the last modification date
    Subscriber reloadedSubscriber = notificationManager.getSubscriber(subscriber.getKey());
    Assert.assertNotNull(reloadedSubscriber);
    Assert.assertEquals(subscriber, reloadedSubscriber);
    Assert.assertTrue(subscriber.getLastModified().before(reloadedSubscriber.getLastModified()));
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 59 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testGetSubscriberIdentities.

@Test
public void testGetSubscriberIdentities() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("valid1b-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("valid1b-" + UUID.randomUUID().toString());
    // create a publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("Subscribers", new Long(123), identifier);
    PublisherData publisherData = new PublisherData("testGetSubscriberIdentities", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    // add subscribers
    notificationManager.subscribe(id1, context, publisherData);
    notificationManager.subscribe(id2, context, publisherData);
    dbInstance.commitAndCloseSession();
    // get identities
    List<Identity> identities = notificationManager.getSubscriberIdentities(publisher);
    Assert.assertNotNull(identities);
    Assert.assertEquals(2, identities.size());
    Assert.assertTrue(identities.contains(id1));
    Assert.assertTrue(identities.contains(id2));
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Example 60 with SubscriptionContext

use of org.olat.core.commons.services.notifications.SubscriptionContext in project OpenOLAT by OpenOLAT.

the class NotificationsManagerTest method testCreateUpdatePublisher.

@Test
public void testCreateUpdatePublisher() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("PS2", new Long(124), identifier);
    PublisherData publisherData = new PublisherData("testPublisherSubscriber", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    // check values
    Assert.assertNotNull(publisher);
    Assert.assertNotNull(publisher.getKey());
    Assert.assertNotNull(publisher.getCreationDate());
    Assert.assertNotNull(publisher.getLatestNewsDate());
    Assert.assertEquals("PS2", publisher.getResName());
    Assert.assertEquals(new Long(124), publisher.getResId());
    sleep(2000);
    // update the publisher
    notificationManager.markPublisherNews(context, null, false);
    // check if exists and last news date is updated
    Publisher reloadedPublisher = notificationManager.getPublisher(context);
    Assert.assertNotNull(reloadedPublisher);
    Assert.assertEquals(publisher, reloadedPublisher);
    Assert.assertTrue(publisher.getLatestNewsDate().before(reloadedPublisher.getLatestNewsDate()));
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) PublisherData(org.olat.core.commons.services.notifications.PublisherData) Test(org.junit.Test)

Aggregations

SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)204 PublisherData (org.olat.core.commons.services.notifications.PublisherData)84 Identity (org.olat.core.id.Identity)72 Test (org.junit.Test)66 Publisher (org.olat.core.commons.services.notifications.Publisher)58 RepositoryEntry (org.olat.repository.RepositoryEntry)38 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)28 BusinessGroup (org.olat.group.BusinessGroup)28 ArrayList (java.util.ArrayList)20 Subscriber (org.olat.core.commons.services.notifications.Subscriber)20 HttpResponse (org.apache.http.HttpResponse)18 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)18 Forum (org.olat.modules.fo.Forum)18 File (java.io.File)16 HttpGet (org.apache.http.client.methods.HttpGet)16 CollaborationTools (org.olat.collaboration.CollaborationTools)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 NamedContainerImpl (org.olat.core.util.vfs.NamedContainerImpl)14 Roles (org.olat.core.id.Roles)12