@Override public void putBlip(String blipId, ConversationBlip newBlip) { if (blipId.startsWith(TEMP_ID_MARKER)) { tempBlipIdMap.put(blipId, newBlip.getId()); } }
/** * Extracts the blip ids of the given list of blips. * * @param children the blips. * @return the blip ids of the blips. */ private static List<String> toBlipIdList(List<ConversationBlip> children) { List<String> ids = Lists.newArrayListWithCapacity(children.size()); for (ConversationBlip child : children) { ids.add(child.getId()); } return ids; }
/** * Returns the blip id of the first blip in the root thread. * * @param conversation the conversation to get the blip id from. */ public static String getRootBlipId(Conversation conversation) { ConversationBlip rootBlip = conversation.getRootThread().getFirstBlip(); return (rootBlip != null) ? rootBlip.getId() : ""; } }
@Override public Map<String, Long> getBlipVersions(WaveletId id) { Conversation c = view.getConversation(WaveletBasedConversation.idFor(id)); Map<String, Long> blipVersions = new HashMap<String, Long>(); for (ConversationBlip blip : BlipIterators.breadthFirst(c)) { blipVersions.put(blip.getId(), blip.getLastModifiedVersion()); } return blipVersions; }
@Override public WaveletData toWaveletData(Wavelet wavelet, Conversation conversation, EventMessageBundle eventMessageBundle) { WaveletData waveletData = super.toWaveletData(wavelet, conversation, eventMessageBundle); List<String> blipIds = Lists.newLinkedList(); for (ConversationBlip conversationBlip : conversation.getRootThread().getBlips()) { blipIds.add(conversationBlip.getId()); } waveletData.setRootThread(new BlipThread("", -1 , blipIds, null)); return waveletData; }
public void testPutNonTemporaryBlip() throws Exception { // Non temporary blip is ignored Conversation conversation = mock(Conversation.class); ConversationBlip blip = mock(ConversationBlip.class); String blipId = "b+1234"; when(blip.getId()).thenReturn(blipId); when(conversation.getBlip(blipId)).thenReturn(blip); operationContext.putBlip(blip.getId(), blip); assertEquals(operationContext.getBlip(conversation, blipId), blip); }
public void testPutNonTemporaryBlip() throws Exception { // Non temporary blip is ignored Conversation conversation = mock(Conversation.class); ConversationBlip blip = mock(ConversationBlip.class); String blipId = "b+1234"; when(blip.getId()).thenReturn(blipId); when(conversation.getBlip(blipId)).thenReturn(blip); operationContext.putBlip(blip.getId(), blip); assertEquals(operationContext.getBlip(conversation, blipId), blip); }
public void testResolveRootContext() throws Exception { ConversationBlip newBlip = conversation.getRootThread().appendBlip(); eventMessages.requireBlip(newBlip.getId(), Lists.newArrayList(Context.ROOT)); ContextResolver.resolveContext( eventMessages, wavelet, conversation, new EventDataConverterV21()); Set<String> blips = eventMessages.getBlipData().keySet(); assertEquals(2, blips.size()); assertTrue(blips.contains(conversation.getRootThread().getFirstBlip().getId())); assertTrue(blips.contains(newBlip.getId())); }
public void testResolveRootContext() throws Exception { ConversationBlip newBlip = conversation.getRootThread().appendBlip(); eventMessages.requireBlip(newBlip.getId(), Lists.newArrayList(Context.ROOT)); ContextResolver.resolveContext( eventMessages, wavelet, conversation, new EventDataConverterV21()); Set<String> blips = eventMessages.getBlipData().keySet(); assertEquals(2, blips.size()); assertTrue(blips.contains(conversation.getRootThread().getFirstBlip().getId())); assertTrue(blips.contains(newBlip.getId())); }
public void testResolveContext() throws Exception { eventMessages.requireBlip( conversation.getRootThread().getFirstBlip().getId(), Lists.newArrayList(Context.CHILDREN)); ContextResolver.resolveContext( eventMessages, wavelet, conversation, new EventDataConverterV21()); Set<String> blips = eventMessages.getBlipData().keySet(); assertEquals(2, blips.size()); for (ConversationBlip blip : conversation.getRootThread().getBlips()) { assertTrue(blips.contains(blip.getId())); } }
public void testResolveContext() throws Exception { eventMessages.requireBlip( conversation.getRootThread().getFirstBlip().getId(), Lists.newArrayList(Context.CHILDREN)); ContextResolver.resolveContext( eventMessages, wavelet, conversation, new EventDataConverterV21()); Set<String> blips = eventMessages.getBlipData().keySet(); assertEquals(2, blips.size()); for (ConversationBlip blip : conversation.getRootThread().getBlips()) { assertTrue(blips.contains(blip.getId())); } }
public void testCannotGetBlipAsDataDocument() { ConversationBlip blip = target.getRootThread().appendBlip(); try { target.getDataDocument(blip.getId()); fail("Expected an exception fetching a blip document as a data doc"); } catch (IllegalArgumentException expected) { } }
public void testCannotGetBlipAsDataDocument() { ConversationBlip blip = target.getRootThread().appendBlip(); try { target.getDataDocument(blip.getId()); fail("Expected an exception fetching a blip document as a data doc"); } catch (IllegalArgumentException expected) { } }
public void testInsetBlipBeforeFirstBlipCreatesNewFirstBlip() { ConversationThread thread = target.getRootThread(); ConversationBlip oldFirst = thread.appendBlip(); ConversationBlip newFirst = thread.insertBlip(oldFirst); assertSame(thread.getFirstBlip(), newFirst); assertSame(newFirst, target.getBlip(newFirst.getId())); assertSame(oldFirst, target.getBlip(oldFirst.getId())); assertEquals(Arrays.asList(newFirst, oldFirst), getBlipList(thread)); }
public void testInsetBlipBeforeFirstBlipCreatesNewFirstBlip() { ConversationThread thread = target.getRootThread(); ConversationBlip oldFirst = thread.appendBlip(); ConversationBlip newFirst = thread.insertBlip(oldFirst); assertSame(thread.getFirstBlip(), newFirst); assertSame(newFirst, target.getBlip(newFirst.getId())); assertSame(oldFirst, target.getBlip(oldFirst.getId())); assertEquals(Arrays.asList(newFirst, oldFirst), getBlipList(thread)); }
public void testDeleteLastBlipInThreadRemovesThread() { ConversationBlip rootBlip = target.getRootThread().appendBlip(); ConversationThread topThread = rootBlip.addReplyThread(); ConversationBlip topBlip = topThread.appendBlip(); ConversationThread firstReply = topBlip.addReplyThread(); firstReply.appendBlip().delete(); assertNull(topBlip.getReplyThread(firstReply.getId())); assertManifestXml("<blip id=\"" + rootBlip.getId() + "\">" + "<thread id=\"" + topThread.getId() + "\">" + "<blip id=\"" + topBlip.getId() + "\"></blip>" + "</thread>" + "</blip>"); }
public void testDeleteLastBlipInThreadRemovesThread() { ConversationBlip rootBlip = target.getRootThread().appendBlip(); ConversationThread topThread = rootBlip.addReplyThread(); ConversationBlip topBlip = topThread.appendBlip(); ConversationThread firstReply = topBlip.addReplyThread(); firstReply.appendBlip().delete(); assertNull(topBlip.getReplyThread(firstReply.getId())); assertManifestXml("<blip id=\"" + rootBlip.getId() + "\">" + "<thread id=\"" + topThread.getId() + "\">" + "<blip id=\"" + topBlip.getId() + "\"></blip>" + "</thread>" + "</blip>"); }
public void testAppendBlipAppendsBlipsToThread() { ConversationThread thread = target.getRootThread(); ConversationBlip b1 = thread.appendBlip(); ConversationBlip b2 = thread.appendBlip(); ConversationBlip b3 = thread.appendBlip(); assertSame(b1, thread.getFirstBlip()); assertSame(target, b1.getConversation()); assertSame(thread, b1.getThread()); assertSame(b1, target.getBlip(b1.getId())); assertEquals(Arrays.asList(b1, b2, b3), getBlipList(thread)); }
public void testAppendBlipAppendsBlipsToThread() { ConversationThread thread = target.getRootThread(); ConversationBlip b1 = thread.appendBlip(); ConversationBlip b2 = thread.appendBlip(); ConversationBlip b3 = thread.appendBlip(); assertSame(b1, thread.getFirstBlip()); assertSame(target, b1.getConversation()); assertSame(thread, b1.getThread()); assertSame(b1, target.getBlip(b1.getId())); assertEquals(Arrays.asList(b1, b2, b3), getBlipList(thread)); }
public void testObsoleteThreadThenRestoreRemoveBlipDoesntDie() { WaveletBasedConversationBlip first = target.getRootThread().appendBlip(); WaveletBasedConversationThread willBecomeEmpty = first.addReplyThread(); ConversationBlip toggleBlip = willBecomeEmpty.appendBlip(); String toggleBlipId = toggleBlip.getId(); // Make the thread empty by remotely removing its blip. ManifestBlip manifestRootBlip = target.getManifest().getRootThread().getBlip(0); ManifestThread manifestReply = manifestRootBlip.getReply(0); manifestReply.removeBlip(manifestReply.getBlip(0)); assertThreadValid(willBecomeEmpty); // Re-add then remove the blip, as can happen in playback. manifestReply.appendBlip(toggleBlipId); manifestReply.removeBlip(manifestReply.getBlip(0)); }