Package org.waveprotocol.wave.model.document.operation

Examples of org.waveprotocol.wave.model.document.operation.DocOp$IsDocOp


  /**
   * Applies an insertion to the document.
   */
  public void doInsert(int offset, String chars) throws OperationException {
    Nindo nindo = Nindo.insertCharacters(offset, chars);
    DocOp op = doc.consumeAndReturnInvertible(nindo);

    BlipContentOperation blipOp = new BlipContentOperation(
        new WaveletOperationContext(participantId, 0L, 1), op);
    WaveletBlipOperation wop = new WaveletBlipOperation("blip id", blipOp);
    clientOperations.add(wop);
View Full Code Here


      checkDoc = indexedDoc;
      checkAuto = Automatons.fromReadable(indexedDoc);
    }

    for (int i = 0; i < NUM_INITIAL_MUTATIONS; i++) {
      DocOp op = RandomDocOpGenerator.generate(random, params,
          // FIXME(ohler): Add back schema constraints
          // DocumentOperationValidator.DEFAULT_BLIP_SCHEMA_CONSTRAINTS,
          autoDoc);
      doc.consume(op);
      checkDoc.consume(op);
    }

    String originalXml = DocOpUtil.toXmlString(doc.asOperation());

    for (int i = 0; i < NUM_REVERSED_MUTATIONS_PER_RUN; i++) {

      // Apply random mutation and revert it.
      DocOp op = RandomDocOpGenerator.generate(random, params,
          // FIXME(ohler): Add back schema constraints
          // DocumentOperationValidator.DEFAULT_BLIP_SCHEMA_CONSTRAINTS,
          autoDoc);

      Nindo nindo = null;
      String finalXml = null;
      DocOp docOpCopy = null;
      DocInitialization docAsOp = null;

      try {

        //System.out.println("  " + i);
        //System.out.println("\n===" + iteration + "." + i + "===============================");

        docAsOp = doc.asOperation();
        validate(DocOpAutomaton.EMPTY_DOCUMENT, docAsOp);
        IndexedDocument<Node, Element, Text> copy = DocProviders.POJO.build(docAsOp,
            DocumentSchema.NO_SCHEMA_CONSTRAINTS);
        BootstrapDocument copy2 = new BootstrapDocument();
        copy2.consume(docAsOp);

        // CONSUME
        doc.consume(op);
        checkDoc.consume(op);

        finalXml = DocOpUtil.toXmlString(checkDocOpProvider.asOperation());

        assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));

        // UNDO
        DocOp inverted1 = DocOpInverter.invert(op);
        validate(autoDoc, inverted1);
        doc.consume(inverted1);
        assertEquals(originalXml, DocOpUtil.toXmlString(doc.asOperation()));

        // CONSUME NINDO
        // TODO(danilatos): Both remove and don't remove the trailing skip, randomly
        nindo = Nindo.fromDocOp(op, true);
        docOpCopy = doc.consumeAndReturnInvertible(nindo);
        assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));

        validate(Automatons.fromReadable(copy), docOpCopy);
        validate(copy2, docOpCopy);
        copy2.consume(docOpCopy);
        assertEquals(finalXml, DocOpUtil.toXmlString(copy2.asOperation()));

        // UNDO NINDO
        DocOp inverted2 = DocOpInverter.invert(docOpCopy);
        validate(checkAuto, inverted2);
        validate(autoDoc, inverted2);
        doc.consume(inverted2);
        assertEquals(originalXml, DocOpUtil.toXmlString(doc.asOperation()));
        checkDoc.consume(inverted2);
View Full Code Here

    for (int i = 0; i < NUM_OPS; i++) {
      System.out.print(".");
      if (testAsOperation) {
        Nindo nindo = RandomNindoGenerator.generate(random, params, constraints, doc);
        DocOp docOp = doc.consumeAndReturnInvertible(nindo);
        docs[i] = DocProviders.POJO.build(doc.asOperation(), constraints);
      } else if (testNindos) {
        Nindo nindo = RandomNindoGenerator.generate(random, params, constraints, doc);
        DocOp docOp = doc.consumeAndReturnInvertible(nindo);
        nindos[i] = nindo;
        nindos[NUM_OPS * 2 - i - 1] = Nindo.fromDocOp(DocOpInverter.invert(docOp), true);
      } else {
        DocOp docOp = RandomDocOpGenerator.generate(random, params, //constraints,
            Automatons.fromReadable(doc));
        doc.consume(docOp);
        docOps[i] = docOp;
        docOps[NUM_OPS * 2 - i - 1] =DocOpInverter.invert(docOp);
      }
View Full Code Here

    }

    <D extends NindoSink & ModifiableDocument> void run(D document, DocumentParser<D> parser) {
      String initialState = parser.asString(document);
      D copy = parser.copyDocument(document);
      DocOp docOp = null;

      Assert.assertEquals("Copy did not work",
          initialState, parser.asString(copy));

      try {
View Full Code Here

  private void restore(Document doc) {
    // No comment.
    UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer();
    doc.toInitialization().apply(builder);
    DocOp state = builder.finish();
    DocOp erasure = DocOpInverter.invert(state);
    DocOp restoration;
    try {
      restoration = Composer.compose(erasure, state);
    } catch (OperationException e) {
      // If the code above fails, then there is a bug in the operation code, not
      // these tests.  Fail with an exception, not with a JUnit fail().
View Full Code Here

      copy.consume(indexedDoc.asOperation());

      for (int i = 0; i < testConfiguration.numInitialMutations; i++) {
        Nindo nindo = RandomNindoGenerator.generate(random, STRUCT_PARAMS,
            ConversationSchemas.BLIP_SCHEMA_CONSTRAINTS, copy);
        DocOp op = indexedDoc.consumeAndReturnInvertible(nindo);
        copy.consume(op);
      }

      for (int i = 0; i < testConfiguration.numAnnotationMutations; i++) {
        try {
          Nindo nindo = RandomNindoGenerator.generate(random, ANNO_PARAMS,
              ConversationSchemas.BLIP_SCHEMA_CONSTRAINTS, copy);
          DocOp op = indexedDoc.consumeAndReturnInvertible(nindo);
//          System.out.println("\n\n");
//          System.out.println(nindo);
//          System.out.println(op);
//          System.out.println(copy);
//          System.out.println(CollectionUtils.join('\n', "INLINE: ",
//              DocOpUtil.visualiseOpWithDocument(copy.asOperation(), op)));
          copy.consume(op);
          checkRender(cxt);
        } catch (RuntimeException e) {
          System.out.println("During annotation mutations: " + i + " " + e);
          throw e;
        }
      }

      for (int i = 0; i < testConfiguration.numGeneralMutations; i++) {
        try {
          Nindo nindo = RandomNindoGenerator.generate(random, GENERAL_PARAMS,
              ConversationSchemas.BLIP_SCHEMA_CONSTRAINTS, copy);
          DocOp op = indexedDoc.consumeAndReturnInvertible(nindo);
          copy.consume(op);
          checkRender(cxt);
        } catch (RuntimeException e) {
          System.out.println("During structural+annotation mutations: " + i + " " + e);
          System.out.println(DocOpUtil.toXmlString(indexedDoc.asOperation()));
View Full Code Here

    assertEquals(new FocusedRange(6), selectionHelper.getSelectionRange());
    assertEquals("<doc>aaahello</doc>", XmlStringBuilder.innerXml(doc).toString());
  }

  private void insert(int location, int size) {
    DocOp op = new DocOpBuilder()
        .retain(location)
        .characters("a")
        .retain(size - location)
        .build();
    silentOperationSink.consume(op);
View Full Code Here

    // Update metadata
    UpdateContributorMethod reverseMethod = update(blip, method);

    blip.getContent().consume(contentOp);

    DocOp reverseContentOp = DocOpInverter.invert(contentOp);

    BlipContentOperation reverseOp =
        new BlipContentOperation(reverseContext, reverseContentOp, reverseMethod);
    return Collections.singletonList(reverseOp);
  }
View Full Code Here

  public static OperationPair<BlipOperation> transform(BlipOperation clientOp,
      BlipOperation serverOp) throws TransformException {
    if (clientOp instanceof BlipContentOperation && serverOp instanceof BlipContentOperation) {
      BlipContentOperation clientBlipContentOp = (BlipContentOperation) clientOp;
      BlipContentOperation serverBlipContentOp = (BlipContentOperation) serverOp;
      DocOp clientContentOp = clientBlipContentOp.getContentOp();
      DocOp serverContentOp = serverBlipContentOp.getContentOp();
      OperationPair<? extends DocOp> transformedDocOps =
          Transformer.transform(clientContentOp, serverContentOp);
      clientOp = new BlipContentOperation(clientBlipContentOp.getContext(),
          transformedDocOps.clientOp());
      serverOp = new BlipContentOperation(serverBlipContentOp.getContext(),
View Full Code Here

    if (size() == 0) {
      return EmptyDocument.EMPTY_DOCUMENT;
    }

    DocOp domOp = serializeDom();

    DocOp annotationsOp = serializeAnnotations();

    try {
      final DocOp bothOps;
      if (performValidation) {
        bothOps = Composer.compose(domOp, annotationsOp);
      } else {
        bothOps = Composer.composeUnchecked(domOp, annotationsOp);
      }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.DocOp$IsDocOp

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.