Skip to content
Snippets Groups Projects
Commit f2628d36 authored by srosse's avatar srosse
Browse files

OO-373,OO-372,OO-96: fix a unit tests, add an update context method to notifications manager

parent 4111491b
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,7 @@ public class MapperDAO { ...@@ -47,6 +47,7 @@ public class MapperDAO {
public PersistedMapper persistMapper(String sessionId, String mapperId, Serializable mapper) { public PersistedMapper persistMapper(String sessionId, String mapperId, Serializable mapper) {
PersistedMapper m = new PersistedMapper(); PersistedMapper m = new PersistedMapper();
m.setMapperId(mapperId); m.setMapperId(mapperId);
m.setLastModified(new Date());
m.setOriginalSessionId(sessionId); m.setOriginalSessionId(sessionId);
String configuration = XStreamHelper.createXStreamInstance().toXML(mapper); String configuration = XStreamHelper.createXStreamInstance().toXML(mapper);
......
...@@ -111,6 +111,14 @@ public abstract class NotificationsManager extends BasicManager { ...@@ -111,6 +111,14 @@ public abstract class NotificationsManager extends BasicManager {
*/ */
public abstract Publisher getOrCreatePublisher(final SubscriptionContext scontext, final PublisherData pdata); public abstract Publisher getOrCreatePublisher(final SubscriptionContext scontext, final PublisherData pdata);
/**
* Modify the publisher
* @param oldContext
* @param newContext
* @return
*/
public abstract Publisher updatePublisher(SubscriptionContext oldContext, SubscriptionContext newContext);
public abstract List<Publisher> getAllPublisher(); public abstract List<Publisher> getAllPublisher();
/** /**
......
...@@ -751,6 +751,17 @@ public class NotificationsManagerImpl extends NotificationsManager implements Us ...@@ -751,6 +751,17 @@ public class NotificationsManagerImpl extends NotificationsManager implements Us
} }
return notificationHandlers.get(type); return notificationHandlers.get(type);
} }
@Override
public Publisher updatePublisher(SubscriptionContext oldContext, SubscriptionContext newContext) {
Publisher p = getPublisherForUpdate(oldContext);
p.setResId(newContext.getResId());
p.setResName(newContext.getResName());
p.setSubidentifier(newContext.getSubidentifier());
return DBFactory.getInstance().getCurrentEntityManager().merge(p);
}
/** /**
* @param subscriber * @param subscriber
......
...@@ -97,6 +97,35 @@ public class NotificationsManagerTest extends OlatTestCase { ...@@ -97,6 +97,35 @@ public class NotificationsManagerTest extends OlatTestCase {
Assert.assertEquals(publisher, reloadedPublisher); Assert.assertEquals(publisher, reloadedPublisher);
} }
@Test
public void testUpdatePublisherContext() {
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.assertEquals("PS", publisher.getResName());
Assert.assertEquals(new Long(123), publisher.getResId());
Assert.assertEquals(identifier, publisher.getSubidentifier());
//modify
String modifiedIdentifier = UUID.randomUUID().toString().replace("-", "");
SubscriptionContext modifiedContext = new SubscriptionContext("PSModified", new Long(12300), modifiedIdentifier);
notificationManager.updatePublisher(context, modifiedContext);
dbInstance.commitAndCloseSession();
//check if exists
Publisher reloadedPublisher = notificationManager.getPublisher(modifiedContext);
Assert.assertNotNull(reloadedPublisher);
Assert.assertEquals(publisher, reloadedPublisher);
Assert.assertEquals("PSModified", reloadedPublisher.getResName());
Assert.assertEquals(new Long(12300), reloadedPublisher.getResId());
Assert.assertEquals(modifiedIdentifier, reloadedPublisher.getSubidentifier());
}
@Test @Test
public void testAllPublishers() { public void testAllPublishers() {
String identifier = UUID.randomUUID().toString().replace("-", ""); String identifier = UUID.randomUUID().toString().replace("-", "");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment