@Override public ObservableConversationView openConversation(WaveId waveId, WaveletId waveletId, ParticipantId participant) throws InvalidRequestException { WaveletName waveletName = WaveletName.of(waveId, waveletId); if (!openedConversations.containsKey(waveletName)) { openedConversations.put( waveletName, Maps.<ParticipantId, ObservableConversationView> newHashMap()); } Map<ParticipantId, ObservableConversationView> conversations = openedConversations.get(waveletName); if (!conversations.containsKey(participant)) { OpBasedWavelet wavelet = openWavelet(waveId, waveletId, participant); conversations.put(participant, conversationUtil.buildConversation(wavelet)); } return conversations.get(participant); }
/** * Returns the root conversation from the given wavelet. Or null if there is * none. * * @param wavelet the wavelet to get the conversation from. */ private ObservableConversation getRootConversation(ObservableWavelet wavelet) { if (!WaveletBasedConversation.waveletHasConversation(wavelet)) { // No conversation present, bail. return null; } ObservableConversation conversation = conversationUtil.buildConversation(wavelet).getRoot(); if (conversation.getRootThread().getFirstBlip() == null) { // No root blip is present, this will cause Robot API code // to fail when resolving the context of events. This might be fixed later // on by making changes to the ContextResolver. return null; } return conversation; } }
public void testWaveletWithNoBlipsResultsInEmptyTitleAndNoBlips() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals("", digest.getTitle()); assertEquals(digest.getBlipCount(), 0); }
public void testWaveletWithNoBlipsResultsInEmptyTitleAndNoBlips() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals("", digest.getTitle()); assertEquals(digest.getBlipCount(), 0); }
public void testWaveletWithBlipsResultsInNonEmptyTitle() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); String title = "title"; data.appendBlipWithText(title); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals(title, digest.getTitle()); assertEquals(1, digest.getBlipCount()); }
public void testWaveletWithBlipsResultsInNonEmptyTitle() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); String title = "title"; data.appendBlipWithText(title); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals(title, digest.getTitle()); assertEquals(1, digest.getBlipCount()); }
public void testUnreadCount() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); data.appendBlipWithText("blip number 1"); data.appendBlipWithText("blip number 2"); data.appendBlipWithText("blip number 3"); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true, true, false); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals(3, digest.getBlipCount()); assertEquals(2, digest.getUnreadCount()); } }
public void testUnreadCount() { TestingWaveletData data = new TestingWaveletData(WAVE_ID, CONVERSATION_WAVELET_ID, PARTICIPANT, true); data.appendBlipWithText("blip number 1"); data.appendBlipWithText("blip number 2"); data.appendBlipWithText("blip number 3"); ObservableWaveletData observableWaveletData = data.copyWaveletData().get(0); ObservableWavelet wavelet = OpBasedWavelet.createReadOnly(observableWaveletData); ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); SupplementedWave supplement = mock(SupplementedWave.class); when(supplement.isUnread(any(ConversationBlip.class))).thenReturn(true, true, false); Digest digest = digester.generateDigest(conversation, supplement, observableWaveletData); assertEquals(3, digest.getBlipCount()); assertEquals(2, digest.getUnreadCount()); } }
public void testGenerateWaveletBlipRemovedEvent() throws Exception { ObservableConversationThread rootThread = conversationUtil.buildConversation(wavelet).getRoot().getRootThread(); ObservableConversationBlip newBlip = rootThread.appendBlip(); newBlip.delete(); EventMessageBundle messages = generateAndCheckEvents(EventType.WAVELET_BLIP_REMOVED); assertEquals("Expected two events", 2, messages.getEvents().size()); // Blip removed should be the second event. WaveletBlipRemovedEvent event = WaveletBlipRemovedEvent.as(messages.getEvents().get(1)); assertEquals("Expected the same id as the removed blip", newBlip.getId(), event.getRemovedBlipId()); }
public void testGenerateWaveletBlipCreatedEvent() throws Exception { ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); ObservableConversationBlip newBlip = conversation.getRoot().getRootThread().appendBlip(); EventMessageBundle messages = generateAndCheckEvents(EventType.WAVELET_BLIP_CREATED); assertEquals("Expected one event", 1, messages.getEvents().size()); WaveletBlipCreatedEvent event = WaveletBlipCreatedEvent.as(messages.getEvents().get(0)); assertEquals("Expected the same id as the new blip", newBlip.getId(), event.getNewBlipId()); }
public void testGenerateWaveletBlipCreatedEvent() throws Exception { ObservableConversationView conversation = conversationUtil.buildConversation(wavelet); ObservableConversationBlip newBlip = conversation.getRoot().getRootThread().appendBlip(); EventMessageBundle messages = generateAndCheckEvents(EventType.WAVELET_BLIP_CREATED); assertEquals("Expected one event", 1, messages.getEvents().size()); WaveletBlipCreatedEvent event = WaveletBlipCreatedEvent.as(messages.getEvents().get(0)); assertEquals("Expected the same id as the new blip", newBlip.getId(), event.getNewBlipId()); }
public void testGenerateWaveletBlipRemovedEvent() throws Exception { ObservableConversationThread rootThread = conversationUtil.buildConversation(wavelet).getRoot().getRootThread(); ObservableConversationBlip newBlip = rootThread.appendBlip(); newBlip.delete(); EventMessageBundle messages = generateAndCheckEvents(EventType.WAVELET_BLIP_REMOVED); assertEquals("Expected two events", 2, messages.getEvents().size()); // Blip removed should be the second event. WaveletBlipRemovedEvent event = WaveletBlipRemovedEvent.as(messages.getEvents().get(1)); assertEquals("Expected the same id as the removed blip", newBlip.getId(), event.getRemovedBlipId()); }
public void testGenerateDocumentChangedEventOnlyOnce() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); // Change the document twice XmlStringBuilder builder = XmlStringBuilder.createText("some random content"); LineContainers.appendToLastLine(rootBlip.getContent(), builder); LineContainers.appendToLastLine(rootBlip.getContent(), builder); EventMessageBundle messages = generateAndCheckEvents(EventType.DOCUMENT_CHANGED); assertEquals("Expected one event only", 1, messages.getEvents().size()); }
public void testGenerateAnnotatedTextChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); String annotationKey = "key"; String annotationValue = "value"; rootBlip.getContent().setAnnotation(0, 1, annotationKey, annotationValue); EventMessageBundle messages = generateAndCheckEvents(EventType.ANNOTATED_TEXT_CHANGED); assertEquals("Expected one event only", 1, messages.getEvents().size()); AnnotatedTextChangedEvent event = AnnotatedTextChangedEvent.as(messages.getEvents().get(0)); assertEquals("Expected the key of the annotation", annotationKey, event.getName()); assertEquals("Expected the value of the annotation", annotationValue, event.getValue()); }
public void testGenerateAnnotatedTextChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); String annotationKey = "key"; String annotationValue = "value"; rootBlip.getContent().setAnnotation(0, 1, annotationKey, annotationValue); EventMessageBundle messages = generateAndCheckEvents(EventType.ANNOTATED_TEXT_CHANGED); assertEquals("Expected one event only", 1, messages.getEvents().size()); AnnotatedTextChangedEvent event = AnnotatedTextChangedEvent.as(messages.getEvents().get(0)); assertEquals("Expected the key of the annotation", annotationKey, event.getName()); assertEquals("Expected the value of the annotation", annotationValue, event.getValue()); }
public void testGenerateDocumentChangedEventOnlyOnce() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); // Change the document twice XmlStringBuilder builder = XmlStringBuilder.createText("some random content"); LineContainers.appendToLastLine(rootBlip.getContent(), builder); LineContainers.appendToLastLine(rootBlip.getContent(), builder); EventMessageBundle messages = generateAndCheckEvents(EventType.DOCUMENT_CHANGED); assertEquals("Expected one event only", 1, messages.getEvents().size()); }
public void testGenerateDocumentChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); XmlStringBuilder builder = XmlStringBuilder.createText("some random content"); LineContainers.appendToLastLine(rootBlip.getContent(), builder); EventMessageBundle messages = generateAndCheckEvents(EventType.DOCUMENT_CHANGED); assertEquals("Expected one event", 1, messages.getEvents().size()); // Can not check the blip id because it is not accessible, however the line // here below will confirm that there was actually a real // DocumentChangedEvent put into the message bundle. DocumentChangedEvent event = DocumentChangedEvent.as(messages.getEvents().get(0)); assertEquals(ALEX.getAddress(), event.getModifiedBy()); }
public void testGenerateDocumentChangedEvent() throws Exception { ConversationBlip rootBlip = conversationUtil.buildConversation(wavelet).getRoot().getRootThread().getFirstBlip(); XmlStringBuilder builder = XmlStringBuilder.createText("some random content"); LineContainers.appendToLastLine(rootBlip.getContent(), builder); EventMessageBundle messages = generateAndCheckEvents(EventType.DOCUMENT_CHANGED); assertEquals("Expected one event", 1, messages.getEvents().size()); // Can not check the blip id because it is not accessible, however the line // here below will confirm that there was actually a real // DocumentChangedEvent put into the message bundle. DocumentChangedEvent event = DocumentChangedEvent.as(messages.getEvents().get(0)); assertEquals(ALEX.getAddress(), event.getModifiedBy()); }
@Override protected void setUp() throws Exception { conversationUtil = new ConversationUtil(FakeIdGenerator.create()); eventGenerator = new EventGenerator(ROBOT_NAME, conversationUtil); waveletData = WaveletDataImpl.Factory.create(DOCUMENT_FACTORY).create( new EmptyWaveletSnapshot(WAVELET_NAME.waveId, WAVELET_NAME.waveletId, ALEX, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L)); // Robot should be participant in snapshot before deltas // otherwise events will be filtered out. waveletData.addParticipant(ROBOT); waveletData.addParticipant(ALEX); waveletData.setVersion(1); SilentOperationSink<WaveletOperation> executor = SilentOperationSink.Executor.<WaveletOperation, WaveletData> build(waveletData); output = new CapturingOperationSink<WaveletOperation>(); wavelet = new OpBasedWavelet(waveletData.getWaveId(), waveletData, CONTEXT_FACTORY, ParticipationHelper.DEFAULT, executor, output); // Make a conversation and clear the sink WaveletBasedConversation.makeWaveletConversational(wavelet); conversationUtil.buildConversation(wavelet).getRoot().getRootThread().appendBlip(); output.clear(); }
@Override protected void setUp() throws Exception { conversationUtil = new ConversationUtil(FakeIdGenerator.create()); eventGenerator = new EventGenerator(ROBOT_NAME, conversationUtil); waveletData = WaveletDataImpl.Factory.create(DOCUMENT_FACTORY).create( new EmptyWaveletSnapshot(WAVELET_NAME.waveId, WAVELET_NAME.waveletId, ALEX, HASH_FACTORY.createVersionZero(WAVELET_NAME), 0L)); // Robot should be participant in snapshot before deltas // otherwise events will be filtered out. waveletData.addParticipant(ROBOT); waveletData.addParticipant(ALEX); waveletData.setVersion(1); SilentOperationSink<WaveletOperation> executor = SilentOperationSink.Executor.<WaveletOperation, WaveletData> build(waveletData); output = new CapturingOperationSink<WaveletOperation>(); wavelet = new OpBasedWavelet(waveletData.getWaveId(), waveletData, CONTEXT_FACTORY, ParticipationHelper.DEFAULT, executor, output); // Make a conversation and clear the sink WaveletBasedConversation.makeWaveletConversational(wavelet); conversationUtil.buildConversation(wavelet).getRoot().getRootThread().appendBlip(); output.clear(); }