/** * Returns the parent blip. * * @return the parent of this blip. */ public Blip getParentBlip() { if (parentBlipId == null) { return null; } return wavelet.getBlips().get(parentBlipId); }
/** * Returns the list of child blips. * * @return the children of this blip. */ public List<Blip> getChildBlips() { List<Blip> result = new ArrayList<Blip>(childBlipIds.size()); for (String childId : childBlipIds) { Blip childBlip = wavelet.getBlips().get(childId); if (childBlip != null) { result.add(childBlip); } } return result; }
/** * Updates the shadow map for a given wavelet. */ private void updateShadowMap(Wavelet wavelet) { for (Blip blip : wavelet.getBlips().values()) { if (isShadowBlip(blip)) { String shadowBlipId = blip.getBlipId(); if (!shadowBlipMap.containsValue(shadowBlipId)) { String originalBlipId = blip.getAnnotations().get(ECHOEY_ANNOTATION).get(0).getValue(); shadowBlipMap.put(originalBlipId, shadowBlipId); } } } }
/** * Creates a new {@code Blip} object used for this session. A temporary * id will be assigned to the newly created {@code Blip} object. * * @param wavelet the wavelet that owns this blip. * @param initialContent the initial content of the new blip. * @param parentBlipId the parent of this blip. * @return an instance of new {@code Blip} object used for this session. */ private static Blip newBlip(Wavelet wavelet, String initialContent, String parentBlipId, String blipId, String threadId) { Blip newBlip = new Blip(blipId, initialContent, parentBlipId, threadId, wavelet); if (parentBlipId != null) { Blip parentBlip = wavelet.getBlips().get(parentBlipId); if (parentBlip != null) { parentBlip.getChildBlipIds().add(newBlip.getBlipId()); } } wavelet.getBlips().put(newBlip.getBlipId(), newBlip); BlipThread thread = wavelet.getThread(threadId); if (thread != null) { thread.appendBlip(newBlip); } return newBlip; }
public void testInsertInlineBlipCantInsertAtTheBeginning() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); assertEquals(1, wavelet.getBlips().size()); try { blip.insertInlineBlip(0); fail("Should have thrown an exception when trying to insert inline blip at index 0."); } catch (IllegalArgumentException e) { // Expected. } assertEquals(1, wavelet.getBlips().size()); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getBlips()).thenReturn(blips); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); when(wavelet.getThread(anyString())).thenReturn(new BlipThread("rootThread", -1, Lists.newArrayList(ROOT_BLIP_ID, CHILD_BLIP_ID), blips)); }
public void testInsertInlineBlipCantInsertAtTheBeginning() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); assertEquals(1, wavelet.getBlips().size()); try { blip.insertInlineBlip(0); fail("Should have thrown an exception when trying to insert inline blip at index 0."); } catch (IllegalArgumentException e) { // Expected. } assertEquals(1, wavelet.getBlips().size()); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getBlips()).thenReturn(blips); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); when(wavelet.getThread(anyString())).thenReturn(new BlipThread("rootThread", -1, Lists.newArrayList(ROOT_BLIP_ID, CHILD_BLIP_ID), blips)); }
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"); }
public void testBlipOperations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); assertEquals(1, wavelet.getBlips().size()); Blip other = blip.reply(); other.append("hello world"); assertEquals("\nhello world", other.getContent()); assertEquals(2, wavelet.getBlips().size()); Blip inline = blip.insertInlineBlip(3); assertEquals("\n", inline.getContent()); assertEquals(3, wavelet.getBlips().size()); }
public void testBlipOperations() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); assertEquals(1, wavelet.getBlips().size()); Blip other = blip.reply(); other.append("hello world"); assertEquals("\nhello world", other.getContent()); assertEquals(2, wavelet.getBlips().size()); Blip inline = blip.insertInlineBlip(3); assertEquals("\n", inline.getContent()); assertEquals(3, wavelet.getBlips().size()); }
public void testCreateChildOfBlip() throws Exception { Blip blip = mock(Blip.class); when(blip.getBlipId()).thenReturn("blip1"); when(blip.getWavelet()).thenReturn(wavelet); Map<String, Blip> blips = new HashMap<String, Blip>(); blips.put("blip1", blip); when(wavelet.getBlip("blip1")).thenReturn(blip); when(wavelet.getBlips()).thenReturn(blips); OperationQueue queue = new OperationQueue(); Blip newBlip = queue.createChildOfBlip(blip); assertEquals(blip.getBlipId(), newBlip.getParentBlipId()); assertEquals(blip, newBlip.getParentBlip()); assertEquals(2, blips.size()); } }
public void testCreateChildOfBlip() throws Exception { Blip blip = mock(Blip.class); when(blip.getBlipId()).thenReturn("blip1"); when(blip.getWavelet()).thenReturn(wavelet); Map<String, Blip> blips = new HashMap<String, Blip>(); blips.put("blip1", blip); when(wavelet.getBlip("blip1")).thenReturn(blip); when(wavelet.getBlips()).thenReturn(blips); OperationQueue queue = new OperationQueue(); Blip newBlip = queue.createChildOfBlip(blip); assertEquals(blip.getBlipId(), newBlip.getParentBlipId()); assertEquals(blip, newBlip.getParentBlip()); assertEquals(2, blips.size()); } }
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")); }
/** * Creates a child blip of another blip. * * @param blip the parent blip. * @return an instance of {@link Blip} that represents the new child blip. */ public Blip createChildOfBlip(Blip blip) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, -1, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip newBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.BLIP_CREATE_CHILD, blip, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
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")); }
/** * Inserts a new inline blip at a specified location. * * @param blip the blip to anchor this inline blip from. * @param position the position in the given blip to insert this new inline * blip. * @return an instance of {@link Blip} that represents the inline blip. */ public Blip insertInlineBlipToDocument(Blip blip, int position) { // Create a new thread. String tempBlipId = generateTempBlipId(blip.getWavelet()); Wavelet wavelet = blip.getWavelet(); BlipThread thread = new BlipThread(tempBlipId, position, new ArrayList<String>(), wavelet.getBlips()); // Add the new thread to the blip and wavelet. blip.addThread(thread); wavelet.addThread(thread); // Create a new blip in the new thread. Blip inlineBlip = newBlip(blip.getWavelet(), "", blip.getBlipId(), tempBlipId, thread.getId()); appendOperation(OperationType.DOCUMENT_INSERT_INLINE_BLIP, blip, Parameter.of(ParamsProperty.INDEX, position), Parameter.of(ParamsProperty.BLIP_DATA, inlineBlip.serialize())); return inlineBlip; }