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);
}
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);
}
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()));
}
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);
}
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));
}
Aggregations