Search in sources :

Example 86 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class NotificationsManagerTest method testCreatePublisher.

@Test
public void testCreatePublisher() {
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context = new SubscriptionContext("PS", new Long(123), 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("PS", publisher.getResName());
    Assert.assertEquals(new Long(123), publisher.getResId());
    Assert.assertEquals(identifier, publisher.getSubidentifier());
    // check if exists
    Publisher reloadedPublisher = notificationManager.getPublisher(context);
    Assert.assertNotNull(reloadedPublisher);
    Assert.assertEquals(publisher, reloadedPublisher);
}
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 87 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class NotificationsManagerTest method testSubscriptions.

@Test
public void testSubscriptions() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("fi1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("fi2-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("fi3-" + UUID.randomUUID().toString());
    SubscriptionContext sc = new SubscriptionContext("Course", new Long(123), UUID.randomUUID().toString());
    PublisherData pd = new PublisherData("Forum", "e.g. forumdata=keyofforum", null);
    SubscriptionContext sc2 = new SubscriptionContext("Course2", new Long(123), UUID.randomUUID().toString());
    PublisherData pd2 = new PublisherData("Forum", "e.g. forumdata=keyofforum2", null);
    dbInstance.closeSession();
    notificationManager.subscribe(id1, sc, pd);
    notificationManager.subscribe(id3, sc, pd);
    notificationManager.subscribe(id2, sc2, pd2);
    notificationManager.subscribe(id1, sc2, pd2);
    dbInstance.closeSession();
    Publisher p = notificationManager.getPublisher(sc);
    assertNotNull(p);
    assertEquals(p.getResName(), sc.getResName());
    assertEquals(p.getResId(), sc.getResId());
    assertEquals(p.getSubidentifier(), sc.getSubidentifier());
    boolean isSub = notificationManager.isSubscribed(id1, sc);
    assertTrue("subscribed::", isSub);
    notificationManager.notifyAllSubscribersByEmail();
    dbInstance.closeSession();
    notificationManager.unsubscribe(id1, sc);
    dbInstance.closeSession();
    boolean isStillSub = notificationManager.isSubscribed(id1, sc);
    assertFalse("subscribed::", isStillSub);
    notificationManager.delete(sc);
    dbInstance.commitAndCloseSession();
    Publisher p2 = notificationManager.getPublisher(sc);
    assertNull("publisher marked deleted should not be found", p2);
}
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 88 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

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 89 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class NotificationsManagerTest method testUnsubscribe_v1.

@Test
public void testUnsubscribe_v1() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("unsubs-" + 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("testUnsubscribe", "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
    Subscriber subscriber = notificationManager.getSubscriber(id, publisher);
    Assert.assertNotNull(subscriber);
    // unsubscribe
    notificationManager.unsubscribe(subscriber);
    dbInstance.commitAndCloseSession();
    // check
    boolean subscribed = notificationManager.isSubscribed(id, context);
    Assert.assertFalse(subscribed);
}
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 90 with PublisherData

use of org.olat.core.commons.services.notifications.PublisherData in project openolat by klemens.

the class NotificationsManagerTest method testConcurrentCreateSubscriberWithOneIdentity.

/**
 * Test creation of concurrent subscriber
 */
@Test
public void testConcurrentCreateSubscriberWithOneIdentity() {
    final int NUM_OF_THREADS = 100;
    PublisherData pd = new PublisherData("CreateSubscriber", "e.g. forumdata=keyofforum", null);
    SubscriptionContext sc = new SubscriptionContext("Course", new Long(1238778566), UUID.randomUUID().toString().replace("-", ""));
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fci-" + UUID.randomUUID().toString());
    final CountDownLatch finishCount = new CountDownLatch(NUM_OF_THREADS);
    List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
    List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
    List<SubscribeThread> threads = new ArrayList<SubscribeThread>();
    for (int i = 0; i < NUM_OF_THREADS; i++) {
        SubscribeThread thread = new SubscribeThread(sc, pd, id, exceptionHolder, statusList, finishCount);
        threads.add(thread);
    }
    for (SubscribeThread thread : threads) {
        thread.start();
    }
    // sleep until threads should have terminated/excepted
    try {
        finishCount.await(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        log.error("", e);
    }
    for (Exception e : exceptionHolder) {
        log.error("Excpetion during concurrent subscription: ", e);
    }
    assertTrue("It throws an exception in test", exceptionHolder.isEmpty());
    assertEquals("Thread(s) did not finish", NUM_OF_THREADS, statusList.size());
    assertTrue("Subscriber does not exists", NotificationsManager.getInstance().isSubscribed(id, sc));
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) PublisherData(org.olat.core.commons.services.notifications.PublisherData) DBRuntimeException(org.olat.core.logging.DBRuntimeException) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

PublisherData (org.olat.core.commons.services.notifications.PublisherData)100 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)84 Test (org.junit.Test)64 Identity (org.olat.core.id.Identity)60 Publisher (org.olat.core.commons.services.notifications.Publisher)42 RepositoryEntry (org.olat.repository.RepositoryEntry)22 BusinessGroup (org.olat.group.BusinessGroup)20 HttpResponse (org.apache.http.HttpResponse)16 HttpGet (org.apache.http.client.methods.HttpGet)16 Subscriber (org.olat.core.commons.services.notifications.Subscriber)16 ArrayList (java.util.ArrayList)14 ContextualSubscriptionController (org.olat.core.commons.services.notifications.ui.ContextualSubscriptionController)12 Forum (org.olat.modules.fo.Forum)12 UriBuilder (javax.ws.rs.core.UriBuilder)10 SubscriptionInfoVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO)8 SubscriptionListItemVO (org.olat.core.commons.services.notifications.restapi.vo.SubscriptionListItemVO)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 ICourse (org.olat.course.ICourse)8 File (java.io.File)6 URI (java.net.URI)6