@Override protected void setUp() throws Exception { waveletProvider = new WaveletProviderStub(); AccountStore accountStore = new MemoryStore(); accountStore.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("fred@example.com"))); org.eclipse.jetty.server.SessionManager jettySessionManager = mock(org.eclipse.jetty.server.SessionManager.class); SessionManager sessionManager = new SessionManagerImpl(accountStore, jettySessionManager); session = mock(HttpSession.class); when(session.getAttribute(SessionManager.USER_FIELD)).thenReturn(ParticipantId.ofUnsafe("fred@example.com")); servlet = new FetchServlet(waveletProvider, protoSerializer, sessionManager); }
@Override public CommittedWaveletSnapshot getSnapshot(WaveletName waveletName) { final byte[] JUNK_BYTES = new byte[] {0, 1, 2, 3, 4, 5, -128, 127}; if (waveletName.waveId.equals(getHostedWavelet().getWaveId()) && waveletName.waveletId.equals(getHostedWavelet().getWaveletId())) { HashedVersion version = (currentVersionOverride != null) ? currentVersionOverride : HashedVersion.of( getHostedWavelet().getVersion(), JUNK_BYTES); return new CommittedWaveletSnapshot(getHostedWavelet(), getCommittedVersion()); } else { return null; } }
public void testDisallowedUserReturnsForbidden() throws Exception { waveletProvider.setAllowsAccess(false); WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId()); verifyServletReturnsForbiddenForWaveref(waveref); }
/** * 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); } }
public WaveletProviderStub() { wavelet = TestDataUtil.createSimpleWaveletData(); setCommittedVersion(HashedVersion.unsigned(0)); }
/** * 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); } }
public WaveletProviderStub() { wavelet = TestDataUtil.createSimpleWaveletData(); setCommittedVersion(HashedVersion.unsigned(0)); }
public void testDisallowedUserReturnsForbidden() throws Exception { waveletProvider.setAllowsAccess(false); WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId()); verifyServletReturnsForbiddenForWaveref(waveref); }
@Override public CommittedWaveletSnapshot getSnapshot(WaveletName waveletName) { final byte[] JUNK_BYTES = new byte[] {0, 1, 2, 3, 4, 5, -128, 127}; if (waveletName.waveId.equals(getHostedWavelet().getWaveId()) && waveletName.waveletId.equals(getHostedWavelet().getWaveletId())) { HashedVersion version = (currentVersionOverride != null) ? currentVersionOverride : HashedVersion.of( getHostedWavelet().getVersion(), JUNK_BYTES); return new CommittedWaveletSnapshot(getHostedWavelet(), getCommittedVersion()); } else { return null; } }
/** * 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()); }
@Override protected void setUp() throws Exception { waveletProvider = new WaveletProviderStub(); AccountStore accountStore = new MemoryStore(); accountStore.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("fred@example.com"))); org.eclipse.jetty.server.SessionManager jettySessionManager = mock(org.eclipse.jetty.server.SessionManager.class); SessionManager sessionManager = new SessionManagerImpl(accountStore, jettySessionManager); servlet = new FetchServlet(waveletProvider, protoSerializer, sessionManager); }
/** * 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 testGetMissingDataReturnsForbidden() throws Exception { WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveId waveId = wavelet.getWaveId(); WaveletId waveletId = wavelet.getWaveletId(); WaveRef unknownWave = WaveRef.of(WaveId.of(waveId.getDomain(), waveId.getId() + "junk")); verifyServletReturnsForbiddenForWaveref(unknownWave); WaveRef unknownWavelet = WaveRef.of(waveId, WaveletId.of(waveletId.getDomain(), waveletId.getId() + "junk")); verifyServletReturnsForbiddenForWaveref(unknownWavelet); WaveRef unknownDocument = WaveRef.of(waveId, waveletId, "madeupdocid"); verifyServletReturnsForbiddenForWaveref(unknownDocument); }
public void testGetMissingDataReturnsForbidden() throws Exception { WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveId waveId = wavelet.getWaveId(); WaveletId waveletId = wavelet.getWaveletId(); WaveRef unknownWave = WaveRef.of(WaveId.of(waveId.getDomain(), waveId.getId() + "junk")); verifyServletReturnsForbiddenForWaveref(unknownWave); WaveRef unknownWavelet = WaveRef.of(waveId, WaveletId.of(waveletId.getDomain(), waveletId.getId() + "junk")); verifyServletReturnsForbiddenForWaveref(unknownWavelet); WaveRef unknownDocument = WaveRef.of(waveId, waveletId, "madeupdocid"); verifyServletReturnsForbiddenForWaveref(unknownDocument); }