Package org.waveprotocol.wave.model.wave.data.core

Examples of org.waveprotocol.wave.model.wave.data.core.CoreWaveletData


  private static final ParticipantId LIZ = new ParticipantId("liz@example.com");
  HashedVersion VERSION = HashedVersion.of(42L, new byte[] {1, 2, 3, 4});

  public void testFromCoreWaveletData() throws Exception {
    Map<String, DocOp> docs = createDocuments("b+", CONTENTS);
    CoreWaveletData core = createCoreWaveletData(WAVELET_NAME, docs, BOB, JOE);
    // sanity checks
    assertEquals(WAVELET_NAME, core.getWaveletName());
    assertEquals(CONTENTS.length, core.getDocuments().size());
    assertOpEquals(CONTENTS[0], core.getDocuments().get("b+0"));
    assertEquals(CollectionUtils.newArrayList(BOB, JOE), core.getParticipants());

    ObservableWaveletData obs =
        DataUtil.fromCoreWaveletData(core, VERSION, SchemaCollection.empty());
    assertEquals(BOB, obs.getCreator());
    assertEquals(0L, obs.getCreationTime());
    assertEquals(0L, obs.getLastModifiedTime());
    assertEquals(VERSION, obs.getHashedVersion());
    assertEquals(VERSION.getVersion(), obs.getVersion());
    assertEquals(WAVELET_NAME.waveId, obs.getWaveId());
    assertEquals(WAVELET_NAME.waveletId, obs.getWaveletId());
    assertEquals(CollectionUtils.immutableSet(BOB, JOE), obs.getParticipants());

    assertEquals(docs.keySet(), obs.getDocumentIds());
    for (Map.Entry<String, DocOp> d : docs.entrySet()) {
      BlipData blip = obs.getDocument(d.getKey());
      WaveletData wavelet = blip.getWavelet();
      assertEquals(WAVELET_NAME.waveId, wavelet.getWaveId());
      assertEquals(WAVELET_NAME.waveletId, wavelet.getWaveletId());
      assertEquals(d.getKey(), blip.getId());
      assertNotNull(blip.getAuthor());
      assertEquals(0L, blip.getLastModifiedTime());
      assertEquals(-1, blip.getLastModifiedVersion());
      assertTrue(blip.getContributors().isEmpty());
      assertOpEquals(d.getValue(), blip.getContent().asOperation());

      try {
        blip.addContributor(JOE);
        fail("blips from DataUtil.fromCoreWaveletData() are immutable");
      } catch (UnsupportedOperationException expected) {
      }
    }

    try {
      obs.addParticipant(LIZ);
      fail("wavelets from DataUtil.fromCoreWaveletData() are immutable");
    } catch (UnsupportedOperationException expected) {
    }

    // test that changes to core are reflected in data
    core.addParticipant(LIZ);
    assertEquals(CollectionUtils.newArrayList(BOB, JOE, LIZ), core.getParticipants());
    assertEquals(CollectionUtils.immutableSet(BOB, JOE, LIZ), obs.getParticipants());
  }
View Full Code Here


    // edited.

    // Creating a CoreWaveletData because the current protocol lacks the
    // meta-data required to construct an ObservableWaveletData directly.
    // But this results in unnecessary object creation and copies.
    CoreWaveletData coreWavelet =
        new CoreWaveletDataImpl(waveletName.waveId, waveletName.waveletId);

    Preconditions.checkArgument(snapshot.getParticipantIdCount() > 0);
    // Have to add a single participant for the copying to complete without a
    // NPE.
    coreWavelet.addParticipant(ParticipantId.ofUnsafe(snapshot.getParticipantId(0)));

    for (DocumentSnapshot document : snapshot.getDocumentList()) {
      DocOp op =
          CoreWaveletOperationSerializer.deserialize(document.getDocumentOperation());
      coreWavelet.modifyDocument(document.getDocumentId(), op);
    }

    HashedVersion hashedVersion = CoreWaveletOperationSerializer.deserialize(version);
    ObservableWaveletData immutableWaveletData =
        DataUtil.fromCoreWaveletData(coreWavelet, hashedVersion, SchemaCollection.empty());
View Full Code Here

    // edited.

    // Creating a CoreWaveletData because the current protocol lacks the
    // meta-data required to construct an ObservableWaveletData directly.
    // But this results in unnecessary object creation and copies.
    CoreWaveletData coreWavelet =
        new CoreWaveletDataImpl(waveletName.waveId, waveletName.waveletId);

    Preconditions.checkArgument(snapshot.getParticipantIdCount() > 0);
    // Have to add a single participant for the copying to complete without a
    // NPE.
    coreWavelet.addParticipant(ParticipantId.ofUnsafe(snapshot.getParticipantId(0)));

    for (DocumentSnapshot document : snapshot.getDocumentList()) {
      DocOp op =
          CoreWaveletOperationSerializer.deserialize(document.getDocumentOperation());
      coreWavelet.modifyDocument(document.getDocumentId(), op);
    }

    HashedVersion hashedVersion = CoreWaveletOperationSerializer.deserialize(version);
    ObservableWaveletData immutableWaveletData =
        DataUtil.fromCoreWaveletData(coreWavelet, hashedVersion, SchemaCollection.empty());
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.wave.data.core.CoreWaveletData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.