/** * @see #blindWavelet(WaveId, WaveletId, String, Map) * * @param threads a collection of threads that belong to this wavelet. */ public Wavelet blindWavelet(WaveId waveId, WaveletId waveletId, String proxyForId, Map<String, Blip> blips, Map<String, BlipThread> threads) { Util.checkIsValidProxyForId(proxyForId); Map<String, String> roles = new HashMap<String, String>(); return new Wavelet(waveId, waveletId, null, new BlipThread("", -1, new ArrayList<String>(), blips), Collections.<String>emptySet(), roles, blips, threads, new OperationQueue(proxyForId)); }
/** * Returns the new blip. * * @return the new blip. */ public Blip getNewBlip() { return wavelet.getBlip(newBlipId); }
/** * Returns a view of this wavelet that will proxy for the specified id. * * A shallow copy of the current wavelet is returned with the * {@code proxyingFor} field set. Any modifications made to this copy will be * done using the {@code proxyForId}, i.e. the * {@code robot+<proxyForId>@appspot.com} address will be used. * * If the wavelet was retrieved using the Active Robot API, that is * by {@code fetchWavelet}, then the address of the robot must be added to the * wavelet by calling {@code setRobotAddress} with the robot's address * before calling {@code proxy_for}. * * @param proxyForId the id to proxy. Please note that this parameter should * be properly encoded to ensure that the resulting participant id is * valid (see {@link Util#checkIsValidProxyForId(String)} for more * details). * @return a shallow copy of this wavelet with the proxying information set. */ public Wavelet proxyFor(String proxyForId) { Util.checkIsValidProxyForId(proxyForId); addProxyingParticipant(proxyForId); OperationQueue proxiedOperationQueue = operationQueue.proxyFor(proxyForId); return new Wavelet(this, proxiedOperationQueue); }
/** * 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; }
@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)); }
Wavelet expectedWavelet = new Wavelet(WaveId.of("example.com", "wave1"), WaveletId.of("example.com", "wavelet1"), "foo@bar.com", 1l, 1l, "Hello world", "blip1", null, roles, participants, dataDocument, tags, blips, threads, opQueue); WaveletData waveletData = expectedWavelet.serialize(); Wavelet actualWavelet = Wavelet.deserialize(opQueue, blips, threads, waveletData); assertEquals(expectedWavelet.getWaveId(), actualWavelet.getWaveId()); assertEquals(expectedWavelet.getWaveletId(), actualWavelet.getWaveletId()); assertEquals(expectedWavelet.getRootBlip().getBlipId(), actualWavelet.getRootBlip().getBlipId()); assertEquals(expectedWavelet.getCreationTime(), actualWavelet.getCreationTime()); assertEquals(expectedWavelet.getCreator(), actualWavelet.getCreator()); assertEquals(expectedWavelet.getLastModifiedTime(), actualWavelet.getLastModifiedTime()); assertEquals(expectedWavelet.getTitle(), actualWavelet.getTitle()); assertEquals(expectedWavelet.getParticipants().size(), actualWavelet.getParticipants().size()); assertEquals(expectedWavelet.getTags().size(), actualWavelet.getTags().size()); assertEquals(expectedWavelet.getDataDocuments().size(), actualWavelet.getDataDocuments().size());
public void testProxyFor() throws Exception { OperationQueue proxiedQueue = mock(OperationQueue.class); when(opQueue.proxyFor("user2")).thenReturn(proxiedQueue); wavelet.setRobotAddress("foo+user1#5@appspot.com"); Wavelet proxiedWavelet = wavelet.proxyFor("user2"); assertTrue(wavelet.getParticipants().contains("foo+user2#5@appspot.com")); assertEquals(proxiedQueue, proxiedWavelet.getOperationQueue()); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); when(wavelet.getOperationQueue()).thenReturn(new OperationQueue()); when(wavelet.getWaveId()).thenReturn(WaveId.of("example.com", "wave1")); when(wavelet.getWaveletId()).thenReturn(WaveletId.of("example.com", "wavelet1")); }
@Override protected void setUp() throws Exception { wavelet = mock(Wavelet.class); 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.<String>newArrayList(), new HashMap<String, Blip>())); }
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 testBlindWavelet() throws Exception { AbstractRobot robot = new MockRobot(); Wavelet blindWavelet = robot.blindWavelet(WAVE_1, WAVELET_1); assertEquals(0, blindWavelet.getOperationQueue().getPendingOperations().size()); blindWavelet.getParticipants().add("foo@test.com"); blindWavelet.reply("\n"); assertEquals(2, blindWavelet.getOperationQueue().getPendingOperations().size()); assertEquals(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX.method(), blindWavelet.getOperationQueue().getPendingOperations().get(0).getMethod()); assertEquals(OperationType.WAVELET_APPEND_BLIP.method(), blindWavelet.getOperationQueue().getPendingOperations().get(1).getMethod()); }
/** * Submits the pending operations associated with this {@link Wavelet}. * * @param wavelet the bundle that contains the operations to be submitted. * @param rpcServerUrl the active gateway to send the operations to. * @return a list of {@link JsonRpcResponse} that represents the responses * from the server for all operations that were submitted. * * @throws IllegalStateException if this method is called prior to setting the * proper consumer key, secret, and handler URL. * @throws IOException if there is a problem submitting the operations. */ public List<JsonRpcResponse> submit(Wavelet wavelet, String rpcServerUrl) throws IOException { List<JsonRpcResponse> responses = makeRpc(wavelet.getOperationQueue(), rpcServerUrl); wavelet.getOperationQueue().clear(); return responses; }
public void testSetRobotAddress() throws Exception { assertNull(wavelet.getRobotAddress()); wavelet.setRobotAddress("foo@appspot.com"); assertEquals("foo@appspot.com", wavelet.getRobotAddress()); try { wavelet.setRobotAddress("bar@appspot.com"); fail("Should have failed when trying to call Wavelet.setRobotAddress() for the second time"); } catch (IllegalStateException e) { assertEquals("Robot address has been set previously to foo@appspot.com", e.getMessage()); } }
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 refactor_testSerializeAndDeserializeWaveletEvent() throws Exception { List<String> participantsAdded = new ArrayList<String>(); participantsAdded.add("foo@google.com"); participantsAdded.add("bar@google.com"); List<String> participantsRemoved = new ArrayList<String>(); participantsRemoved.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); Map<String, Blip> blips = Maps.newHashMap(); blips.put("blip123", blip); when(wavelet.getThread(anyString())).thenReturn(new BlipThread("rootThread", -1, Lists.<String>newArrayList("blip123"), blips)); EventMessageBundle bundle = new EventMessageBundle("http://10.1.1.1", "http://wave-active-api.example.com"); WaveletParticipantsChangedEvent expected = new WaveletParticipantsChangedEvent(wavelet, bundle, "mprasetya@google.com", 1l, "blip123", participantsAdded, participantsRemoved); Context context = new Context(); Event actualEvent = EventSerializer.deserialize(wavelet, bundle, EventSerializer.serialize(expected, context), context); WaveletParticipantsChangedEvent actual = WaveletParticipantsChangedEvent.as(actualEvent); assertEquals(expected, actual); assertEquals(expected.getParticipantsAdded(), actual.getParticipantsAdded()); assertEquals(expected.getParticipantsRemoved(), actual.getParticipantsRemoved()); }
/** * Returns the parent blip. * * @return the parent of this blip. */ public Blip getParentBlip() { if (parentBlipId == null) { return null; } return wavelet.getBlips().get(parentBlipId); }
Map<String, Blip> blips = new HashMap<String, Blip>(); Map<String, BlipThread> threads = new HashMap<String, BlipThread>(); Wavelet wavelet = Wavelet.deserialize(operationQueue, blips, threads, waveletData); wavelet.setRobotAddress(robotAddress); result.setWavelet(wavelet);
public void testSubmitWith() throws Exception { OperationQueue otherOpQueue = mock(OperationQueue.class); 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 other = new Wavelet(WAVE_ID, WAVELET_ID, "foo@bar.com", 1l, 1l, "Hello world", "blip1", null, roles, participants, new HashMap<String, String>(), Collections.<String>emptySet(), new HashMap<String, Blip>(), threads, otherOpQueue); wavelet.submitWith(other); verify(opQueue).submitWith(otherOpQueue); }
public void testProxiedBlindWavelet() throws Exception { AbstractRobot robot = new MockRobot(); Wavelet blindWavelet = robot.blindWavelet(WAVE_1, WAVELET_1, "proxyid"); assertEquals(0, blindWavelet.getOperationQueue().getPendingOperations().size()); blindWavelet.reply("\n"); List<OperationRequest> ops = blindWavelet.getOperationQueue().getPendingOperations(); assertEquals(1, ops.size()); assertEquals(OperationType.WAVELET_APPEND_BLIP.method(), ops.get(0).getMethod()); assertEquals("proxyid", ops.get(0).getParameter(ParamsProperty.PROXYING_FOR)); // Assert that proxy id should be valid. try { robot.blindWavelet(WAVE_1, WAVELET_1, "foo@bar.com"); fail("Should have failed since proxy id is not valid."); } catch (IllegalArgumentException e) { // Expected. } }