/** * Returns the offset of this blip if it is inline, or -1 if it's not. If the * parent is not in the offset, this method will always return -1 since it * can't determine the inline blip status. * * @return the offset of this blip if it is inline, or -1 if it's not inline * or if the parent is not in the context. * @deprecated please use {@code getThread().getLocation()} to get the offset * of the inline reply thread that contains this blip. */ @Deprecated public int getInlineBlipOffset() { Blip parent = getParentBlip(); if (parent == null) { return -1; } for (Entry<Integer, Element> entry : parent.getElements().entrySet()) { Element element = entry.getValue(); if (element.getType() == ElementType.INLINE_BLIP && blipId.equals(element.getProperty(INLINE_BLIP_ELEMENT_ID_KEY))) { return entry.getKey(); } } return -1; }
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()); } }
/** * Removes a blip from this wavelet. * * @param blipId the id of the blip to be removed. */ public void delete(String blipId) { operationQueue.deleteBlip(this, blipId); Blip removed = blips.remove(blipId); if (removed != null) { // Remove the blip from the parent blip. Blip parentBlip = removed.getParentBlip(); if (parentBlip != null) { parentBlip.deleteChildBlipId(blipId); } // Remove the blip from the containing thread. BlipThread thread = removed.getThread(); if (thread != null) { thread.removeBlip(removed); } // If the containing thread is now empty, remove it from the parent blip // and from the wavelet. if (thread != null && parentBlip != null && thread.isEmpty()) { parentBlip.removeThread(thread); threads.remove(thread.getId()); } } }
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"); }