/**
   * Writes out the current feature.
   *
   * @throws IOException
   * @see org.geotools.data.FeatureWriter#write()
   */
  public void write() throws IOException {
    // DJB: I modified this so it doesnt throw an error if you
    //     do an update and you didnt actually change anything.
    //     (We do the work)
    if ((live != null)) {
      // We have a modification to record!
      diff.modify(live.getID(), current);

      ReferencedEnvelope bounds = new ReferencedEnvelope((CoordinateReferenceSystem) null);
      bounds.include(live.getBounds());
      bounds.include(current.getBounds());
      fireNotification(FeatureEvent.FEATURES_CHANGED, bounds);
      live = null;
      current = null;
    } else if ((live == null) && (current != null)) {
      // We have new content to record
      //
      diff.add(current.getID(), current);
      fireNotification(
          FeatureEvent.FEATURES_ADDED, ReferencedEnvelope.reference(current.getBounds()));
      current = null;
    } else {
      throw new IOException("No feature available to write");
    }
  }
Example #2
0
  public ResultItem<T>[] getMergedResult() {
    Insertion[] insertedByA = new Insertion[base.length + 1];
    boolean[] deletedByA = new boolean[base.length];
    Insertion[] insertedByB = new Insertion[base.length + 1];
    boolean[] deletedByB = new boolean[base.length];

    Diff aDiff = new Diff(base, a);
    Diff.change aChanges = aDiff.diff_2(false);
    recordChanges(insertedByA, deletedByA, aChanges);

    Diff bDiff = new Diff(base, b);
    Diff.change bChanges = bDiff.diff_2(false);
    recordChanges(insertedByB, deletedByB, bChanges);

    List<ResultItem> result = new ArrayList<ResultItem>();
    InsertedItemFactory<T> aFactory = new InsertedItemFactoryA();
    InsertedItemFactory<T> bFactory = new InsertedItemFactoryB();
    int aPos = 0;
    int bPos = 0;

    for (int i = 0; i <= base.length; i++) {
      if (insertedByA[i] != null) aPos = addInsertions(result, insertedByA[i], aFactory);
      if (insertedByB[i] != null) bPos = addInsertions(result, insertedByB[i], bFactory);

      if (i < base.length) {
        ResultItem<T> item = new ResultItem<T>(base[i], i, -1, -1);
        if (deletedByA[i] == false) item.aPos = aPos++;
        if (deletedByB[i] == false) item.bPos = bPos++;
        result.add(item);
      }
    }

    return (ResultItem<T>[]) result.toArray(new ResultItem[result.size()]);
  }
Example #3
0
 public boolean compare(String baselinecontent, String testresult) throws Exception {
   StringReader baserdr = new StringReader(baselinecontent);
   StringReader resultrdr = new StringReader(testresult);
   // Diff the two files
   Diff diff = new Diff("Testing " + getTitle());
   boolean pass = !diff.doDiff(baserdr, resultrdr);
   baserdr.close();
   resultrdr.close();
   return pass;
 }
  @Test
  public void testAudioMD_noMD5() throws Exception {

    Fits fits = new Fits();

    // First generate the FITS output
    File input = new File("testfiles/test.wav");
    FitsOutput fitsOut = fits.examine(input);

    XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
    String actualXmlStr = serializer.outputString(fitsOut.getFitsXml());

    // Read in the expected XML file
    Scanner scan = new Scanner(new File("testfiles/output/FITS_test_wav_NO_MD5.xml"));
    String expectedXmlStr = scan.useDelimiter("\\Z").next();
    scan.close();

    // Set up XMLUnit
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setNormalizeWhitespace(true);

    Diff diff = new Diff(expectedXmlStr, actualXmlStr);

    // Initialize attributes or elements to ignore for difference checking
    diff.overrideDifferenceListener(
        new IgnoreNamedElementsDifferenceListener(
            "version",
            "toolversion",
            "dateModified",
            "fslastmodified",
            "lastmodified",
            "startDate",
            "startTime",
            "timestamp",
            "fitsExecutionTime",
            "executionTime",
            "filepath",
            "location"));

    DetailedDiff detailedDiff = new DetailedDiff(diff);

    // Display any Differences
    List<Difference> diffs = detailedDiff.getAllDifferences();
    if (!diff.identical()) {
      StringBuffer differenceDescription = new StringBuffer();
      differenceDescription.append(diffs.size()).append(" differences");

      System.out.println(differenceDescription.toString());
      for (Difference difference : diffs) {
        System.out.println(difference.toString());
      }
    }

    assertTrue("Differences in XML", diff.identical());
  }
Example #5
0
 @SuppressWarnings("unchecked")
 public FieldDiffs setDiff(
     String field, @Nullable Serializable oldValue, @Nullable Serializable newValue) {
   Diff diff = diffs.get(field);
   if (diff == null) {
     diff = new Diff(oldValue, newValue);
     diffs.put(field, diff);
   } else {
     diff.setNewValue(newValue);
   }
   return this;
 }
Example #6
0
 public static void main(final String[] argv) throws IOException {
   final String filea = argv[argv.length - 2];
   final String fileb = argv[argv.length - 1];
   final String[] a = DiffPrint.slurp(filea);
   final String[] b = DiffPrint.slurp(fileb);
   final Diff d = new Diff(a, b);
   char style = 'n';
   for (int i = 0; i < argv.length - 2; ++i) {
     final String f = argv[i];
     if (f.startsWith("-")) {
       for (int j = 1; j < f.length(); ++j) {
         switch (f.charAt(j)) {
           case 'e': // Ed style
             style = 'e';
             break;
           case 'c': // Context diff
             style = 'c';
             break;
           case 'u':
             style = 'u';
             break;
         }
       }
     }
   }
   final boolean reverse = style == 'e';
   final Diff.change script = d.diff_2(reverse);
   if (script == null) {
     System.err.println("No differences");
   } else {
     Base p;
     switch (style) {
       case 'e':
         p = new EdPrint(a, b);
         break;
       case 'c':
         p = new ContextPrint(a, b);
         break;
       case 'u':
         p = new UnifiedPrint(a, b);
         break;
       default:
         p = new NormalPrint(a, b);
     }
     p.print_header(filea, fileb);
     p.print_script(script);
   }
 }
Example #7
0
  protected Diff<Document, Diff<Fieldable, DocumentDiff>> compare(
      IndexReader reader1, IndexReader reader2, String keyFieldName)
      throws IOException, ParseException {
    Diff<Document, Diff<Fieldable, DocumentDiff>> result =
        new Diff<Document, Diff<Fieldable, DocumentDiff>>();
    for (int docId = 0; docId < reader1.numDocs(); docId++) {
      if (!reader1.isDeleted(docId)) {
        Document doc1 = reader1.document(docId);
        Field keyField = doc1.getField(keyFieldName);
        if (keyField == null) {
          throw new IllegalArgumentException(
              "Key field " + keyFieldName + " should be defined in all docs in the index");
        }

        Document doc2 = findByKey(reader2, keyField);
        if (doc2 == null) {
          result.addAdded(doc1);
        } else {
          Diff<Fieldable, DocumentDiff> diff =
              CompareUtils.diff(keyField.stringValue(), doc1, doc2);
          if (!diff.isEquals()) {
            result.addDiff(diff);
          }
        }
      }
    }

    for (int docId = 0; docId < reader2.numDocs(); docId++) {
      if (!reader2.isDeleted(docId)) {
        Document doc2 = reader2.document(docId);
        Field keyField = doc2.getField(keyFieldName);
        if (keyField == null) {
          throw new IllegalArgumentException(
              "Key field '" + keyFieldName + "' should be defined in all docs in the index");
        }

        Document doc1 = findByKey(reader1, keyField);
        if (doc1 == null) {
          result.addRemoved(doc2);
        }
      }
    }

    return result;
  }
Example #8
0
  public static <T> Diff<T> createDiff(List<T> existingElements, List<T> newElements) {
    if (existingElements == null) {
      existingElements = Collections.EMPTY_LIST;
    }
    if (newElements == null) {
      newElements = Collections.EMPTY_LIST;
    }

    Diff<T> diff = new Diff<T>();

    diff.elementsToRemove = new ArrayList<T>(existingElements);
    diff.elementsToRemove.removeAll(newElements);
    diff.elementsToAdd = new ArrayList<T>(newElements);
    diff.elementsToAdd.removeAll(existingElements);
    diff.intersectionElements = new ArrayList<T>(existingElements);
    diff.intersectionElements.removeAll(diff.elementsToRemove);

    return diff;
  }
 /** @see org.geotools.data.FeatureWriter#remove() */
 public void remove() throws IOException {
   if (live != null) {
     // mark live as removed
     diff.remove(live.getID());
     fireNotification(
         FeatureEvent.FEATURES_REMOVED, ReferencedEnvelope.reference(live.getBounds()));
     live = null;
     current = null;
   } else if (current != null) {
     // cancel additional content
     current = null;
   }
 }
 public File createDiff(File out, String dest) {
   File result = out;
   try {
     String[] a = DiffPrint.slurp(original);
     String[] b = DiffPrint.slurp(revised);
     Diff d = new Diff(a, b);
     Diff.change script = d.diff_2(false);
     if (script == null) {
       JOptionPane.showMessageDialog(null, "Error: No differences");
       result = null;
     } else {
       DiffPrint.Base p = new DiffPrint.UnifiedPrint(a, b);
       FileWriter fw = new FileWriter(result);
       p.setOutput(fw);
       p.print_header(".orig" + dest, dest);
       p.print_script(script);
       p.close();
       doubleCheckChunkHeaders(result);
     }
   } catch (Exception e) {
     result = null;
   }
   return result;
 }
Example #11
0
  public static void main(String[] args) {
    if (args.length < 1) {
      System.out.println("Please give the configuration file name as first argument");
      return;
    }

    Map<String, Long> executionTimes = new HashMap<String, Long>();

    InputSource inputSource = new InputSource(args[0]);

    List<Test> tests = getTests(inputSource);
    if (tests == null) return;

    Emailer emailer = parseEmailer(inputSource);
    if (emailer == null) return;

    List<List<String>> outputs = new ArrayList<List<String>>();

    for (Test test : tests) {
      try {
        System.out.println("Running test " + test.getName());
        long startTime = System.currentTimeMillis();
        BufferedReader bufferedReader = null;
        for (int i = 0; i < test.getNRuns(); i++) {
          Process process = Runtime.getRuntime().exec(test.getCommand());
          if (test.getOutput().equals("console")) {
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
          } else {
            bufferedReader = new BufferedReader(new FileReader(test.getOutput()));
          }
          process.waitFor();
        }
        executionTimes.put(test.getName(), System.currentTimeMillis() - startTime);
        outputs.add(getLines(bufferedReader));
        System.out.println("Test " + test.getName() + " executed");
      } catch (IOException e) {
        e.printStackTrace();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    String message = "";
    int size = tests.size();
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < i; j++) {
        String differences = Diff.diff(outputs.get(i), outputs.get(j));
        if (!differences.isEmpty()) {
          message +=
              "Differences between "
                  + tests.get(j).getName()
                  + " and "
                  + tests.get(i).getName()
                  + " tests\n";
          message += differences;
        }
      }
    }

    System.out.println("Sending e-mails");

    if (!message.isEmpty()) {
      message = "Some tests failed:\n" + message;
    } else {
      message = "Tests run successfully\n";
    }
    message += "Time of execution:\n";
    for (String name : executionTimes.keySet()) {
      message += name + " : " + executionTimes.get(name) + "ms\n";
    }
    emailer.send(message);
    System.out.println("E-mails sent");
  }
 public void testModified() throws Exception {
   Diff d = new Diff(doc1, doc2);
   d.overrideDifferenceListener(new ModifiedDifferenceListener());
   assertTrue(d.toString(), d.similar());
 }