Search in sources :

Example 66 with PublisherData

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

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)

Example 67 with PublisherData

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

the class NotificationsManagerTest method testUnsubscribe_v2.

@Test
public void testUnsubscribe_v2() {
    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(id, context);
    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 68 with PublisherData

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

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

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

the class NotificationsManagerTest method testGetSubscriptionInfos.

// markPublisherNews
@Test
public void testGetSubscriptionInfos() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fi1-" + UUID.randomUUID().toString());
    SubscriptionContext context = new SubscriptionContext("Course", new Long(789521), UUID.randomUUID().toString());
    PublisherData publisherData = new PublisherData("Forum", "e.g. forumdata=keyofforum", null);
    Publisher publisher = notificationManager.getOrCreatePublisher(context, publisherData);
    dbInstance.commitAndCloseSession();
    notificationManager.subscribe(id, context, publisherData);
    dbInstance.commitAndCloseSession();
    // get infos
    List<SubscriptionInfo> infos = notificationManager.getSubscriptionInfos(id, publisher.getType());
    Assert.assertNotNull(infos);
}
Also used : SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) 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 70 with PublisherData

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

the class NotificationsManagerTest method testGetSubscribersByTypes.

@Test
public void testGetSubscribersByTypes() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("type1-" + UUID.randomUUID().toString());
    // create a first publisher
    String identifier = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context1 = new SubscriptionContext("Subscribers", new Long(123), identifier);
    PublisherData publisherData1 = new PublisherData("testGetSubscribersByType1", "e.g. forumdata=keyofforum", null);
    Publisher publisher1 = notificationManager.getOrCreatePublisher(context1, publisherData1);
    dbInstance.commitAndCloseSession();
    String identifier2 = UUID.randomUUID().toString().replace("-", "");
    SubscriptionContext context2 = new SubscriptionContext("Subscribers", new Long(123), identifier2);
    PublisherData publisherData2 = new PublisherData("testGetSubscribersByType2", "e.g. forumdata=keyofforum", null);
    Publisher publisher2 = notificationManager.getOrCreatePublisher(context2, publisherData2);
    dbInstance.commitAndCloseSession();
    // add subscribers
    notificationManager.subscribe(id, context1, publisherData1);
    notificationManager.subscribe(id, context2, publisherData2);
    dbInstance.commitAndCloseSession();
    // get subscribers without types
    List<Subscriber> emptySubscribers = notificationManager.getSubscribers(id, null);
    Assert.assertNotNull(emptySubscribers);
    Assert.assertEquals(2, emptySubscribers.size());
    // get subscribers with 1 type
    List<String> types = Collections.singletonList(publisher1.getType());
    List<Subscriber> typedSubscribers = notificationManager.getSubscribers(id, types);
    Assert.assertNotNull(typedSubscribers);
    Assert.assertEquals(1, typedSubscribers.size());
    // get subscribers with 2 types
    List<String> allTypes = new ArrayList<String>(2);
    allTypes.add(publisher1.getType());
    allTypes.add(publisher2.getType());
    List<Subscriber> allSubscribers = notificationManager.getSubscribers(id, allTypes);
    Assert.assertNotNull(allSubscribers);
    Assert.assertEquals(2, allSubscribers.size());
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) 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)

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