diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2017-09-03 21:44:16 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2017-09-03 21:48:53 -0700 |
commit | 72ee0f10ddca0d880e50d13446f9ac0269e542eb (patch) | |
tree | 9dc1bfe0e4300ab05fb3ac1cd44dac6c44b71c18 /src/test/java/com/p4square | |
parent | fa7d0ec7d486dccb55c50ba635a638a855a513c1 (diff) |
Adding notification emails when questions and answers are posted to the feed.20170903
Diffstat (limited to 'src/test/java/com/p4square')
-rw-r--r-- | src/test/java/com/p4square/grow/backend/feed/ThreadResourceTest.java | 68 | ||||
-rw-r--r-- | src/test/java/com/p4square/grow/backend/feed/TopicResourceTest.java | 70 |
2 files changed, 138 insertions, 0 deletions
diff --git a/src/test/java/com/p4square/grow/backend/feed/ThreadResourceTest.java b/src/test/java/com/p4square/grow/backend/feed/ThreadResourceTest.java new file mode 100644 index 0000000..bb4e8ca --- /dev/null +++ b/src/test/java/com/p4square/grow/backend/feed/ThreadResourceTest.java @@ -0,0 +1,68 @@ +package com.p4square.grow.backend.feed; + +import com.p4square.grow.backend.GrowBackend; +import com.p4square.grow.backend.NotificationService; +import com.p4square.grow.model.Message; +import com.p4square.grow.provider.CollectionProvider; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; +import org.restlet.Request; +import org.restlet.data.Method; +import org.restlet.ext.jackson.JacksonRepresentation; +import org.restlet.representation.Representation; + +import static org.junit.Assert.assertNotNull; + +/** + * Tests for the feed's ThreadResource. + */ +public class ThreadResourceTest { + + private ThreadResource resource; + + private GrowBackend mockBackend; + private CollectionProvider<String, String, Message> mockProvider; + private NotificationService mockNotificationService; + + @Before + public void setup() { + mockNotificationService = EasyMock.createMock(NotificationService.class); + mockProvider = EasyMock.createMock(CollectionProvider.class); + + mockBackend = EasyMock.createMock(GrowBackend.class); + EasyMock.expect(mockBackend.getMessageProvider()).andReturn(mockProvider).anyTimes(); + EasyMock.expect(mockBackend.getNotificationService()).andReturn(mockNotificationService).anyTimes(); + + resource = new ThreadResource(); + resource.setApplication(mockBackend); + } + + @Test + public void testNotification() throws Exception { + // Prepare request + Message message = new Message(); + message.setMessage("Test message"); + Representation entity = new JacksonRepresentation<>(message); + + Request request = new Request(Method.POST, "/feed/leader/thread-id"); + request.getAttributes().put("topic", "leader"); + request.getAttributes().put("thread", "thread-id"); + + // Set expectations + mockProvider.put(EasyMock.eq("leader/thread-id"), EasyMock.anyString(), EasyMock.anyObject(Message.class)); + mockNotificationService.sendNotification("A new response was posted on the leader topic:\n\nTest message"); + EasyMock.replay(mockBackend, mockProvider, mockNotificationService); + + // Test + resource.setRequest(request); + resource.doInit(); + Representation result = resource.post(entity); + + // Verify + EasyMock.verify(mockBackend, mockProvider, mockNotificationService); + + assertNotNull(result); + } + +}
\ No newline at end of file diff --git a/src/test/java/com/p4square/grow/backend/feed/TopicResourceTest.java b/src/test/java/com/p4square/grow/backend/feed/TopicResourceTest.java new file mode 100644 index 0000000..46f6696 --- /dev/null +++ b/src/test/java/com/p4square/grow/backend/feed/TopicResourceTest.java @@ -0,0 +1,70 @@ +package com.p4square.grow.backend.feed; + +import com.p4square.grow.backend.GrowBackend; +import com.p4square.grow.backend.NotificationService; +import com.p4square.grow.model.Message; +import com.p4square.grow.model.MessageThread; +import com.p4square.grow.provider.CollectionProvider; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; +import org.restlet.Request; +import org.restlet.data.Method; +import org.restlet.ext.jackson.JacksonRepresentation; +import org.restlet.representation.Representation; + +import static org.junit.Assert.assertNotNull; + +/** + * Tests for the feed's TopicResource. + */ +public class TopicResourceTest { + + private TopicResource resource; + + private GrowBackend mockBackend; + private CollectionProvider<String, String, MessageThread> mockProvider; + private NotificationService mockNotificationService; + + @Before + public void setup() { + mockNotificationService = EasyMock.createMock(NotificationService.class); + mockProvider = EasyMock.createMock(CollectionProvider.class); + + mockBackend = EasyMock.createMock(GrowBackend.class); + EasyMock.expect(mockBackend.getThreadProvider()).andReturn(mockProvider).anyTimes(); + EasyMock.expect(mockBackend.getNotificationService()).andReturn(mockNotificationService).anyTimes(); + + resource = new TopicResource(); + resource.setApplication(mockBackend); + } + + @Test + public void testNotification() throws Exception { + // Prepare request + Message message = new Message(); + message.setMessage("Test message"); + MessageThread thread = new MessageThread(); + thread.setMessage(message); + Representation entity = new JacksonRepresentation<>(thread); + + Request request = new Request(Method.POST, "/feed/leader"); + request.getAttributes().put("topic", "leader"); + + // Set expectations + mockProvider.put(EasyMock.eq("leader"), EasyMock.anyString(), EasyMock.anyObject(MessageThread.class)); + mockNotificationService.sendNotification("A new question was posted on the leader topic:\n\nTest message"); + EasyMock.replay(mockBackend, mockProvider, mockNotificationService); + + // Test + resource.setRequest(request); + resource.doInit(); + Representation result = resource.post(entity); + + // Verify + EasyMock.verify(mockBackend, mockProvider, mockNotificationService); + + assertNotNull(result); + } + +}
\ No newline at end of file |