public void testSetRobotAddress() throws Exception { assertNull(wavelet.getRobotAddress()); wavelet.setRobotAddress("foo@appspot.com"); assertEquals("foo@appspot.com", wavelet.getRobotAddress()); try { wavelet.setRobotAddress("bar@appspot.com"); fail("Should have failed when trying to call Wavelet.setRobotAddress() for the second time"); } catch (IllegalStateException e) { assertEquals("Robot address has been set previously to foo@appspot.com", e.getMessage()); } }
public void testReply() throws Exception { assertEquals(1, wavelet.getBlips().size()); Blip replyBlip1 = mock(Blip.class); when(replyBlip1.getBlipId()).thenReturn("replyblip1"); Blip replyBlip2 = mock(Blip.class); when(replyBlip2.getBlipId()).thenReturn("replyblip2"); when(opQueue.appendBlipToWavelet(wavelet, "\n")).thenReturn(replyBlip1); when(opQueue.appendBlipToWavelet(wavelet, "\nFoo")).thenReturn(replyBlip2); try { wavelet.reply(null); fail("Should have failed when calling Wavelet.reply(null)."); } catch (IllegalArgumentException e) { // Expected. } try { wavelet.reply("Foo"); fail("Should have failed when calling Wavelet.reply(String) with arg that doesn't start " + "with a newline char."); } catch (IllegalArgumentException e) { // Expected. } Blip newBlip1 = wavelet.reply("\n"); Blip newBlip2 = wavelet.reply("\nFoo"); //operation must be submitted before it is added to wavelet, so should still be 1 assertEquals(1, wavelet.getBlips().size()); assertTrue(newBlip1.getBlipId().contains("replyblip1")); assertTrue(newBlip2.getBlipId().contains("replyblip2")); }
public void testGetDomain() throws Exception { assertEquals("example.com", wavelet.getDomain()); }
public void testProxyFor() throws Exception { OperationQueue proxiedQueue = mock(OperationQueue.class); when(opQueue.proxyFor("user2")).thenReturn(proxiedQueue); wavelet.setRobotAddress("foo+user1#5@appspot.com"); Wavelet proxiedWavelet = wavelet.proxyFor("user2"); assertTrue(wavelet.getParticipants().contains("foo+user2#5@appspot.com")); assertEquals(proxiedQueue, proxiedWavelet.getOperationQueue()); }
public void testProxyForShouldFailIfProxyIdIsInvalid() throws Exception { try { wavelet.proxyFor("foo@gmail.com"); fail("Should have failed since proxy id is not encoded."); } catch (IllegalArgumentException e) { // Expected. } }
public void testReply() throws Exception { assertEquals(1, wavelet.getBlips().size()); Blip replyBlip1 = mock(Blip.class); when(replyBlip1.getBlipId()).thenReturn("replyblip1"); Blip replyBlip2 = mock(Blip.class); when(replyBlip2.getBlipId()).thenReturn("replyblip2"); when(opQueue.appendBlipToWavelet(wavelet, "\n")).thenReturn(replyBlip1); when(opQueue.appendBlipToWavelet(wavelet, "\nFoo")).thenReturn(replyBlip2); try { wavelet.reply(null); fail("Should have failed when calling Wavelet.reply(null)."); } catch (IllegalArgumentException e) { // Expected. } try { wavelet.reply("Foo"); fail("Should have failed when calling Wavelet.reply(String) with arg that doesn't start " + "with a newline char."); } catch (IllegalArgumentException e) { // Expected. } Blip newBlip1 = wavelet.reply("\n"); Blip newBlip2 = wavelet.reply("\nFoo"); //operation must be submitted before it is added to wavelet, so should still be 1 assertEquals(1, wavelet.getBlips().size()); assertTrue(newBlip1.getBlipId().contains("replyblip1")); assertTrue(newBlip2.getBlipId().contains("replyblip2")); }
public void testGetDomain() throws Exception { assertEquals("example.com", wavelet.getDomain()); }
public void testProxyFor() throws Exception { OperationQueue proxiedQueue = mock(OperationQueue.class); when(opQueue.proxyFor("user2")).thenReturn(proxiedQueue); wavelet.setRobotAddress("foo+user1#5@appspot.com"); Wavelet proxiedWavelet = wavelet.proxyFor("user2"); assertTrue(wavelet.getParticipants().contains("foo+user2#5@appspot.com")); assertEquals(proxiedQueue, proxiedWavelet.getOperationQueue()); }
public void testProxyForShouldFailIfProxyIdIsInvalid() throws Exception { try { wavelet.proxyFor("foo@gmail.com"); fail("Should have failed since proxy id is not encoded."); } catch (IllegalArgumentException e) { // Expected. } }
public void testSetRobotAddress() throws Exception { assertNull(wavelet.getRobotAddress()); wavelet.setRobotAddress("foo@appspot.com"); assertEquals("foo@appspot.com", wavelet.getRobotAddress()); try { wavelet.setRobotAddress("bar@appspot.com"); fail("Should have failed when trying to call Wavelet.setRobotAddress() for the second time"); } catch (IllegalStateException e) { assertEquals("Robot address has been set previously to foo@appspot.com", e.getMessage()); } }
public void testDeleteByBlipId() throws Exception { assertEquals(1, wavelet.getBlips().size()); assertEquals("blip1", wavelet.getBlips().entrySet().iterator().next().getKey()); wavelet.delete("blip1"); assertEquals(0, wavelet.getBlips().size()); verify(opQueue).deleteBlip(wavelet, "blip1"); }
public void testDeleteByBlipId() throws Exception { assertEquals(1, wavelet.getBlips().size()); assertEquals("blip1", wavelet.getBlips().entrySet().iterator().next().getKey()); wavelet.delete("blip1"); assertEquals(0, wavelet.getBlips().size()); verify(opQueue).deleteBlip(wavelet, "blip1"); }
public void testDeleteByBlip() throws Exception { Blip parentBlip = mock(Blip.class); when(parentBlip.getBlipId()).thenReturn("parentblipid"); Blip childBlip = mock(Blip.class); when(childBlip.getBlipId()).thenReturn("childblipid"); when(childBlip.getParentBlip()).thenReturn(parentBlip); Map<String, Blip> blips = new HashMap<String, Blip>(); blips.put("parentblipid", parentBlip); blips.put("childblipid", childBlip); Set<String> participants = new LinkedHashSet<String>(); participants.add("foo@bar.com"); Map<String, String> roles = new HashMap<String, String>(); Map<String, BlipThread> threads = new HashMap<String, BlipThread>(); wavelet = new Wavelet(WAVE_ID, WAVELET_ID, "foo@bar.com", 1l, 1l, "Hello world", "parentblipid", null, roles, participants, new HashMap<String, String>(), new LinkedHashSet<String>(), blips, threads, opQueue); assertEquals(2, wavelet.getBlips().size()); wavelet.delete(childBlip); assertEquals(1, wavelet.getBlips().size()); verify(parentBlip).deleteChildBlipId("childblipid"); verify(opQueue).deleteBlip(wavelet, "childblipid"); }
public void testDeleteByBlip() throws Exception { Blip parentBlip = mock(Blip.class); when(parentBlip.getBlipId()).thenReturn("parentblipid"); Blip childBlip = mock(Blip.class); when(childBlip.getBlipId()).thenReturn("childblipid"); when(childBlip.getParentBlip()).thenReturn(parentBlip); Map<String, Blip> blips = new HashMap<String, Blip>(); blips.put("parentblipid", parentBlip); blips.put("childblipid", childBlip); Set<String> participants = new LinkedHashSet<String>(); participants.add("foo@bar.com"); Map<String, String> roles = new HashMap<String, String>(); Map<String, BlipThread> threads = new HashMap<String, BlipThread>(); wavelet = new Wavelet(WAVE_ID, WAVELET_ID, "foo@bar.com", 1l, 1l, "Hello world", "parentblipid", null, roles, participants, new HashMap<String, String>(), new LinkedHashSet<String>(), blips, threads, opQueue); assertEquals(2, wavelet.getBlips().size()); wavelet.delete(childBlip); assertEquals(1, wavelet.getBlips().size()); verify(parentBlip).deleteChildBlipId("childblipid"); verify(opQueue).deleteBlip(wavelet, "childblipid"); }
Wavelet actualWavelet = Wavelet.deserialize(opQueue, blips, threads, waveletData); assertEquals(expectedWavelet.getWaveId(), actualWavelet.getWaveId()); assertEquals(expectedWavelet.getWaveletId(), actualWavelet.getWaveletId()); assertEquals(expectedWavelet.getRootBlip().getBlipId(), actualWavelet.getRootBlip().getBlipId()); assertEquals(expectedWavelet.getCreationTime(), actualWavelet.getCreationTime()); assertEquals(expectedWavelet.getCreator(), actualWavelet.getCreator()); assertEquals(expectedWavelet.getLastModifiedTime(), actualWavelet.getLastModifiedTime()); assertEquals(expectedWavelet.getTitle(), actualWavelet.getTitle()); assertEquals(expectedWavelet.getParticipants().size(), actualWavelet.getParticipants().size()); assertEquals(expectedWavelet.getTags().size(), actualWavelet.getTags().size()); assertEquals(expectedWavelet.getDataDocuments().size(), actualWavelet.getDataDocuments().size());
Wavelet actualWavelet = Wavelet.deserialize(opQueue, blips, threads, waveletData); assertEquals(expectedWavelet.getWaveId(), actualWavelet.getWaveId()); assertEquals(expectedWavelet.getWaveletId(), actualWavelet.getWaveletId()); assertEquals(expectedWavelet.getRootBlip().getBlipId(), actualWavelet.getRootBlip().getBlipId()); assertEquals(expectedWavelet.getCreationTime(), actualWavelet.getCreationTime()); assertEquals(expectedWavelet.getCreator(), actualWavelet.getCreator()); assertEquals(expectedWavelet.getLastModifiedTime(), actualWavelet.getLastModifiedTime()); assertEquals(expectedWavelet.getTitle(), actualWavelet.getTitle()); assertEquals(expectedWavelet.getParticipants().size(), actualWavelet.getParticipants().size()); assertEquals(expectedWavelet.getTags().size(), actualWavelet.getTags().size()); assertEquals(expectedWavelet.getDataDocuments().size(), actualWavelet.getDataDocuments().size());