private <T extends Message> T fetchWaverRefAndParse(WaveRef waveref, Class<T> klass) throws Exception { String message = fetchWaveRef(waveref); JsonElement json = new JsonParser().parse(message); return protoSerializer.fromJson(json, klass); } }
private void verifyServletReturnsForbiddenForWaveref(WaveRef waveref) throws Exception { HttpServletResponse response = mock(HttpServletResponse.class); requestWaveRef(waveref, response); verify(response).sendError(HttpServletResponse.SC_FORBIDDEN); }
/** * 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 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); }
/** * 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()); }
/** * 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 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); }
/** * 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 testDisallowedUserReturnsForbidden() throws Exception { waveletProvider.setAllowsAccess(false); WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId()); verifyServletReturnsForbiddenForWaveref(waveref); }
private void verifyServletReturnsForbiddenForWaveref(WaveRef waveref) throws Exception { HttpServletResponse response = mock(HttpServletResponse.class); requestWaveRef(waveref, response); verify(response).sendError(HttpServletResponse.SC_FORBIDDEN); }
private <T extends Message> T fetchWaverRefAndParse(WaveRef waveref, Class<T> klass) throws Exception { String message = fetchWaveRef(waveref); JsonElement json = new JsonParser().parse(message); return protoSerializer.fromJson(json, klass); } }
public void testDisallowedUserReturnsForbidden() throws Exception { waveletProvider.setAllowsAccess(false); WaveletData wavelet = waveletProvider.getHostedWavelet(); WaveRef waveref = WaveRef.of(wavelet.getWaveId(), wavelet.getWaveletId()); verifyServletReturnsForbiddenForWaveref(waveref); }
private String fetchWaveRef(WaveRef waveref) throws Exception { HttpServletResponse response = mock(HttpServletResponse.class); StringWriter writer = new StringWriter(); when(response.getWriter()).thenReturn(new PrintWriter(writer)); requestWaveRef(waveref, response); verify(response).getWriter(); verify(response, never()).sendError(anyInt()); return writer.toString(); }
private String fetchWaveRef(WaveRef waveref) throws Exception { HttpServletResponse response = mock(HttpServletResponse.class); StringWriter writer = new StringWriter(); when(response.getWriter()).thenReturn(new PrintWriter(writer)); requestWaveRef(waveref, response); verify(response).getWriter(); verify(response, never()).sendError(anyInt()); return writer.toString(); }