/** * Appends a blip to the end of this thread. * * @param blip the blip to append. */ void appendBlip(Blip blip) { blipIds.add(blip.getBlipId()); }
/** * Removes a blip from this thread. * * @param blip the blip to remove. * @return {@code true} if this thread contained the given id, and removal was * successful. */ boolean removeBlip(Blip blip) { return blipIds.remove(blip.getBlipId()); }
/** * Removes a blip from this wavelet. * * @param blip the blip to be removed. */ public void delete(Blip blip) { delete(blip.getBlipId()); }
/** * 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); } } } }
/** * Inserts an inline blip at the given position. * * @param position the index to insert the inline blip at. This has to be * greater than 0. * @return an instance of {@link Blip} that represents the new inline blip. */ public Blip insertInlineBlip(int position) { if (position <= 0 || position > content.length()) { throw new IllegalArgumentException("Illegal inline blip position: " + position + ". Position has to be greater than 0 and less than or equal to length."); } // Shift the elements. shift(position, 1); content = content.substring(0, position) + " " + content.substring(position); // Generate the operation. Blip inlineBlip = operationQueue.insertInlineBlipToDocument(this, position); // Insert the inline blip element. Element element = new Element(ElementType.INLINE_BLIP); element.setProperty(INLINE_BLIP_ELEMENT_ID_KEY, inlineBlip.getBlipId()); elements.put(position, element); return inlineBlip; }
/** * Creates and appends a new operation to the operation queue. * * @param opType the type of the operation. * @param blip the blip to apply this operation to. * @param parameters the parameters that should be added as a property of * the operation. * @return an instance of {@link OperationRequest} that represents the queued * operation. */ OperationRequest appendOperation(OperationType opType, Blip blip, Parameter... parameters) { return appendOperation(opType, blip.getWaveId(), blip.getWaveletId(), blip.getBlipId(), parameters); }
/** * Updates an existing shadow blip. * * @param shadowBlip the blip that is shadowing. * @param blipToShadow the blip being shadowed. */ private void updateShadowBlip(Blip shadowBlip, Blip blipToShadow) { Preconditions.checkNotNull(shadowBlip, "Shadow blip can't be null"); Preconditions.checkNotNull(blipToShadow, "Blip to shadow can't be null"); shadowBlip.all().replace(blipToShadow.getContent()); for (Annotation annotation : blipToShadow.getAnnotations()) { if (annotation.getName().equals(ECHOEY_ANNOTATION)) { continue; } shadowBlip.range(annotation.getRange().getStart(), annotation.getRange().getEnd()).annotate( annotation.getName(), annotation.getValue()); } shadowBlip.all().annotate(ECHOEY_ANNOTATION, blipToShadow.getBlipId()); shadowBlipMap.put(blipToShadow.getBlipId(), shadowBlip.getBlipId()); }
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 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"); }
/** * Creates a new shadow blip. * * Note that this method will not know the id of the new blip since the * server will generate it. * * @param blip the blip to create a new shadow blip for. */ private void createShadowBlip(Blip blip) { Blip newBlip = blip.continueThread(); newBlip.all().replace(blip.getContent()); newBlip.all().annotate(ECHOEY_ANNOTATION, blip.getBlipId()); }
public void refactor_testSerializeAndDeserializeBlipEvent() throws Exception { List<String> contributorsAdded = new ArrayList<String>(); contributorsAdded.add("foo@google.com"); contributorsAdded.add("bar@google.com"); List<String> contributorsRemoved = new ArrayList<String>(); contributorsRemoved.add("baz@google.com"); Blip blip = mock(Blip.class); when(blip.getBlipId()).thenReturn("blip123"); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getBlip("blip123")).thenReturn(blip); EventMessageBundle bundle = new EventMessageBundle("http://10.1.1.1", "http://wave-active-api.example.com"); BlipContributorsChangedEvent expected = new BlipContributorsChangedEvent(wavelet, bundle, "mprasetya@google.com", 1l, "blip123", contributorsAdded, contributorsRemoved); Context context = new Context(); Event actualEvent = EventSerializer.deserialize(wavelet, bundle, EventSerializer.serialize(expected, context), context); BlipContributorsChangedEvent actual = BlipContributorsChangedEvent.as(actualEvent); assertEquals(expected, actual); assertEquals(expected.getContributorsAdded(), actual.getContributorsAdded()); assertEquals(expected.getContributorsRemoved(), actual.getContributorsRemoved()); }
/** * 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 refactor_testSerializeAndDeserializeGadgetStateChanged() throws Exception { Map<String, String> oldState = new HashMap<String, String>(); oldState.put("key1", "value1"); oldState.put("key2", "value2"); Blip blip = mock(Blip.class); when(blip.getBlipId()).thenReturn("blip123"); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getBlip("blip123")).thenReturn(blip); EventMessageBundle bundle = new EventMessageBundle("http://10.1.1.1", "http://wave-active-api.example.com"); GadgetStateChangedEvent expected = new GadgetStateChangedEvent(wavelet, bundle, "mprasetya@google.com", 1l, "blip123", 5, oldState); Context context = new Context(); Event actualEvent = EventSerializer.deserialize(wavelet, bundle, EventSerializer.serialize(expected, context), context); GadgetStateChangedEvent actual = GadgetStateChangedEvent.as(actualEvent); assertEquals(expected, actual); assertEquals(expected.getIndex(), actual.getIndex()); assertEquals(expected.getOldState(),actual.getOldState()); }
public void testProxyFor() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); Blip proxiedBlip = blip.proxyFor("proxyuser"); assertEquals(blip.getBlipId(), proxiedBlip.getBlipId()); assertEquals(blip.getWaveId(), proxiedBlip.getWaveId()); assertEquals(blip.getWaveletId(), proxiedBlip.getWaveletId()); proxiedBlip.reply(); List<OperationRequest> pendingOps = proxiedBlip.getOperationQueue().getPendingOperations(); assertEquals(1, pendingOps.size()); assertEquals("proxyuser", pendingOps.get(0).getParameter(ParamsProperty.PROXYING_FOR)); }
public void testProxyFor() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); Blip proxiedBlip = blip.proxyFor("proxyuser"); assertEquals(blip.getBlipId(), proxiedBlip.getBlipId()); assertEquals(blip.getWaveId(), proxiedBlip.getWaveId()); assertEquals(blip.getWaveletId(), proxiedBlip.getWaveletId()); proxiedBlip.reply(); List<OperationRequest> pendingOps = proxiedBlip.getOperationQueue().getPendingOperations(); assertEquals(1, pendingOps.size()); assertEquals("proxyuser", pendingOps.get(0).getParameter(ParamsProperty.PROXYING_FOR)); }
public void refactor_testSerializeAndDeserializeGadgetStateChanged() throws Exception { Map<String, String> oldState = new HashMap<String, String>(); oldState.put("key1", "value1"); oldState.put("key2", "value2"); Blip blip = mock(Blip.class); when(blip.getBlipId()).thenReturn("blip123"); Wavelet wavelet = mock(Wavelet.class); when(wavelet.getBlip("blip123")).thenReturn(blip); EventMessageBundle bundle = new EventMessageBundle("http://10.1.1.1", "http://wave-active-api.example.com"); GadgetStateChangedEvent expected = new GadgetStateChangedEvent(wavelet, bundle, "mprasetya@google.com", 1l, "blip123", 5, oldState); Context context = new Context(); Event actualEvent = EventSerializer.deserialize(wavelet, bundle, EventSerializer.serialize(expected, context), context); GadgetStateChangedEvent actual = GadgetStateChangedEvent.as(actualEvent); assertEquals(expected, actual); assertEquals(expected.getIndex(), actual.getIndex()); assertEquals(expected.getOldState(),actual.getOldState()); }
public void testInlineBlip() throws Exception { Blip blip = newBlip("\n1234", Collections.<Annotation>emptyList()); assertEquals(-1, blip.getInlineBlipOffset()); Blip inlineBlip = blip.insertInlineBlip(3); assertTrue(blip.getChildBlipIds().contains(inlineBlip.getBlipId())); assertEquals(3, inlineBlip.getInlineBlipOffset()); assertEquals("\n12 34", blip.getContent()); assertEquals(ElementType.INLINE_BLIP, blip.getElements().get(3).getType()); }
public void testInlineBlip() throws Exception { Blip blip = newBlip("\n1234", Collections.<Annotation>emptyList()); assertEquals(-1, blip.getInlineBlipOffset()); Blip inlineBlip = blip.insertInlineBlip(3); assertTrue(blip.getChildBlipIds().contains(inlineBlip.getBlipId())); assertEquals(3, inlineBlip.getInlineBlipOffset()); assertEquals("\n12 34", blip.getContent()); assertEquals(ElementType.INLINE_BLIP, blip.getElements().get(3).getType()); }