public void testWaveletRoundtrip() throws Exception { WaveletData expected = TestDataUtil.createSimpleWaveletData(); WaveletName name = WaveletName.of(expected.getWaveId(), expected.getWaveletId()); HashedVersion version = HASH_FACTORY.createVersionZero(name); WaveletSnapshot snapshot = SnapshotSerializer.serializeWavelet(expected, version); WaveletData actual = SnapshotSerializer.deserializeWavelet(snapshot, expected.getWaveId()); TestDataUtil.checkSerializedWavelet(expected, actual); } }
private static void addDocumentSnapshotToWavelet( DocumentSnapshot snapshot, WaveletData container) throws InvalidParticipantAddress { DocOp op = CoreWaveletOperationSerializer.deserialize(snapshot.getDocumentOperation()); DocInitialization docInit = DocOpUtil.asInitialization(op); Collection<ParticipantId> contributors = CollectionUtils.newArrayList(); for (String p : snapshot.getContributorList()) { contributors.add(getParticipantId(p)); } container.createDocument( snapshot.getDocumentId(), getParticipantId(snapshot.getAuthor()), contributors, docInit, snapshot.getLastModifiedTime(), snapshot.getLastModifiedVersion()); } }
for (String docId : snapshot.getDocumentIds()) { if (docId.equals(waveref.getDocumentId())) { docSnapshot = SnapshotSerializer.serializeDocument(snapshot.getDocument(docId)); break; } else if (waveref.hasWaveletId()) { serializeObjectToServlet(SnapshotSerializer.serializeWavelet(snapshot, snapshot.getHashedVersion()), dest); } else { .addWavelet(SnapshotSerializer.serializeWavelet(snapshot, snapshot.getHashedVersion())) .build(); serializeObjectToServlet(waveSnapshot, dest);
/** * The fetch servlet also exposes document snapshots through a longer url * (/fetch/domain/waveid/domain/waveletid/docid). * * @throws Exception */ public void testGetDocument() throws Exception { WaveletData wavelet = waveletProvider.getHostedWavelet(); for (String docId : wavelet.getDocumentIds()) { // We currently have no way to deserialize a document. Instead, we'll // serialize the expected document and compare with what we get from the // fetch servlet. StringWriter writer = new StringWriter(); BlipData expectedDoc = wavelet.getDocument(docId); writer.append("" + protoSerializer.toJson(SnapshotSerializer.serializeDocument(expectedDoc))); String expectedResult = writer.toString(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId(), docId); String actualResult = fetchWaveRef(waveref); assertEquals(expectedResult, actualResult); } }
"Mismatched commit versions, snapshot: " + snapshot.committedVersion + " expected: " + committedVersion); builder.setSnapshot(SnapshotSerializer.serializeWavelet(snapshot.snapshot, snapshot.committedVersion)); builder.setResultingVersion(CoreWaveletOperationSerializer.serialize(
/** * Round-trip a wavelet and make sure all the fields match. * We only check the fields that WaveletSnapshot serializes. * @throws Exception */ public void testGetWavelet() throws Exception { WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId()); WaveletSnapshot snapshot = fetchWaverRefAndParse(waveref, WaveletSnapshot.class); WaveletData roundtripped = SnapshotSerializer.deserializeWavelet(snapshot, waveref.getWaveId()); // We have just round-tripped wavelet through the servlet. wavelet and // roundtripped should be identical in all the fields that get serialized. TestDataUtil.checkSerializedWavelet(wavelet, roundtripped); // TODO(josephg): Enable this test when the persistence store is in place. // assertEquals(snapshot.getVersion(), waveletProvider.getCommittedVersion()); }
wavelet.addParticipant(getParticipantId(participant)); addDocumentSnapshotToWavelet(document, wavelet);
/** * The fetch servlet also exposes document snapshots through a longer url * (/fetch/domain/waveid/domain/waveletid/docid). * * @throws Exception */ public void testGetDocument() throws Exception { WaveletData wavelet = waveletProvider.getHostedWavelet(); for (String docId : wavelet.getDocumentIds()) { // We currently have no way to deserialize a document. Instead, we'll // serialize the expected document and compare with what we get from the // fetch servlet. StringWriter writer = new StringWriter(); BlipData expectedDoc = wavelet.getDocument(docId); writer.append("" + protoSerializer.toJson(SnapshotSerializer.serializeDocument(expectedDoc))); String expectedResult = writer.toString(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId(), docId); String actualResult = fetchWaveRef(waveref); assertEquals(expectedResult, actualResult); } }
@Override public void execute(OperationRequest operation, OperationContext context, ParticipantId participant) throws InvalidRequestException { WaveId waveId; WaveletId waveletId; try { waveId = ApiIdSerializer.instance().deserialiseWaveId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID)); waveletId = ApiIdSerializer.instance().deserialiseWaveletId( OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID)); } catch (InvalidIdException ex) { throw new InvalidRequestException("Invalid id", operation, ex); } WaveletName waveletName = WaveletName.of(waveId, waveletId); CommittedWaveletSnapshot snapshot = context.getWaveletSnapshot(waveletName, participant); WaveletSnapshot protoSnapshot = SnapshotSerializer.serializeWavelet(snapshot.snapshot, snapshot.snapshot.getHashedVersion()); WaveletSnapshotProtoImpl protoSnapshotImpl = new WaveletSnapshotProtoImpl(protoSnapshot); String jsonSnapshot = gson.toJson(protoSnapshotImpl.toGson(null, gson)); Map<ParamsProperty, Object> data = ImmutableMap.<ParamsProperty, Object> of(ParamsProperty.RAW_SNAPSHOT, jsonSnapshot); context.constructResponse(operation, data); }
/** * Round-trip a wavelet and make sure all the fields match. * We only check the fields that WaveletSnapshot serializes. * @throws Exception */ public void testGetWavelet() throws Exception { WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId()); WaveletSnapshot snapshot = fetchWaverRefAndParse(waveref, WaveletSnapshot.class); WaveletData roundtripped = SnapshotSerializer.deserializeWavelet(snapshot, waveref.getWaveId()); // We have just round-tripped wavelet through the servlet. wavelet and // roundtripped should be identical in all the fields that get serialized. TestDataUtil.checkSerializedWavelet(wavelet, roundtripped); // TODO(josephg): Enable this test when the persistence store is in place. // assertEquals(snapshot.getVersion(), waveletProvider.getCommittedVersion()); }
public void testWaveletRoundtrip() throws Exception { WaveletData expected = TestDataUtil.createSimpleWaveletData(); WaveletName name = WaveletName.of(expected.getWaveId(), expected.getWaveletId()); HashedVersion version = HASH_FACTORY.createVersionZero(name); WaveletSnapshot snapshot = SnapshotSerializer.serializeWavelet(expected, version); WaveletData actual = SnapshotSerializer.deserializeWavelet(snapshot, expected.getWaveId()); TestDataUtil.checkSerializedWavelet(expected, actual); } }
/** * Serializes a snapshot for a wavelet. * * @param wavelet wavelet to snapshot * @param hashedVersion hashed version of the wavelet * @return a wavelet snapshot that contains all the information in the * original wavelet. */ public static WaveletSnapshot serializeWavelet(ReadableWaveletData wavelet, HashedVersion hashedVersion) { WaveletSnapshot.Builder builder = WaveletSnapshot.newBuilder(); builder.setWaveletId(ModernIdSerialiser.INSTANCE.serialiseWaveletId(wavelet.getWaveletId())); for (ParticipantId participant : wavelet.getParticipants()) { builder.addParticipantId(participant.toString()); } for (String id : wavelet.getDocumentIds()) { ReadableBlipData data = wavelet.getDocument(id); builder.addDocument(serializeDocument(data)); } builder.setVersion(CoreWaveletOperationSerializer.serialize(hashedVersion)); builder.setLastModifiedTime(wavelet.getLastModifiedTime()); builder.setCreator(wavelet.getCreator().getAddress()); builder.setCreationTime(wavelet.getCreationTime()); return builder.build(); }