use of difflib.Patch in project midpoint by Evolveum.
the class TestMigrator method assertSimpleMigration.
private <O extends ObjectType> void assertSimpleMigration(File fileOld, File fileNew) throws SchemaException, IOException {
// GIVEN
Migrator migrator = createMigrator();
PrismContext prismContext = PrismTestUtil.getPrismContext();
PrismObject<O> objectOld = prismContext.parseObject(fileOld);
// WHEN
PrismObject<O> objectNew = migrator.migrate(objectOld);
// THEN
IntegrationTestTools.display("Migrated object " + fileOld.getName(), objectNew);
assertNotNull("No migrated object " + fileOld.getName(), objectNew);
IntegrationTestTools.display("Migrated object " + fileOld.getName(), objectNew);
String migratedXml = PrismTestUtil.serializeObjectToString(objectNew, PrismContext.LANG_XML);
IntegrationTestTools.display("Migrated object XML " + fileOld.getName(), migratedXml);
PrismObject<O> expectedObject = prismContext.parseObject(fileNew);
IntegrationTestTools.display("Expected object " + fileOld.getName(), expectedObject);
String expectedXml = PrismTestUtil.serializeObjectToString(expectedObject, PrismContext.LANG_XML);
IntegrationTestTools.display("Expected object XML " + fileOld.getName(), expectedXml);
List<String> expectedXmlLines = MiscUtil.splitLines(expectedXml);
Patch patch = DiffUtils.diff(expectedXmlLines, MiscUtil.splitLines(migratedXml));
List<String> diffLines = DiffUtils.generateUnifiedDiff(fileOld.getPath(), fileNew.getPath(), expectedXmlLines, patch, 3);
IntegrationTestTools.display("XML textual diff", StringUtils.join(diffLines, '\n'));
PrismAsserts.assertEquivalent("Unexpected migration result for " + fileOld.getName(), expectedObject, objectNew);
assertEquals("Unexpected element name for " + fileOld.getName(), expectedObject.getElementName(), objectNew.getElementName());
}
use of difflib.Patch in project Gargoyle by callakrsos.
the class TextBaseComparator method getDeltas.
/**
* 비교결과 리턴
*
* @return
* @throws Exception
*/
private CompareResult getDeltas() throws Exception {
CompareResult result = new CompareResult();
List<String> originalFileLines = fileToLines(original);
List<String> revisedFileLines = fileToLines(revised);
result.setOriginalFileLines(originalFileLines);
result.setRevisedFileLines(revisedFileLines);
final Patch patch = DiffUtils.diff(originalFileLines, revisedFileLines);
List<Delta> deltas = patch.getDeltas();
result.setDeltas(deltas);
return result;
}
use of difflib.Patch in project Gargoyle by callakrsos.
the class FileBaseComparator method getDeltas.
/**
* 비교결과 리턴
*
* @return
* @throws IOException
*/
private CompareResult getDeltas() throws IOException {
CompareResult result = new CompareResult();
List<String> originalFileLines = fileToLines(original);
List<String> revisedFileLines = fileToLines(revised);
result.setOriginalFileLines(originalFileLines);
result.setRevisedFileLines(revisedFileLines);
final Patch patch = DiffUtils.diff(originalFileLines, revisedFileLines);
List<Delta> deltas = patch.getDeltas();
result.setDeltas(deltas);
return result;
}
use of difflib.Patch in project Gargoyle by callakrsos.
the class DiffPathText method diffPathTest.
@Test
public void diffPathTest() throws IOException, URISyntaxException, PatchFailedException {
URL test1 = ClassLoader.getSystemClassLoader().getResource("compare/Test1");
URL test2 = ClassLoader.getSystemClassLoader().getResource("compare/Test2");
List<String> test1List = Files.readAllLines(new File(test1.toURI()).toPath());
List<String> test2List = Files.readAllLines(new File(test2.toURI()).toPath());
Patch diff = DiffUtils.diff(test1List, test2List);
List<Delta> deltas = diff.getDeltas();
deltas.stream().forEach(d -> {
Chunk original = d.getOriginal();
List<?> lines = original.getLines();
lines.stream().forEach(System.out::println);
});
// List<?> patch = DiffUtils.patch(test1List, diff);
// patch.stream().forEach(System.out::println);
//
// List<?> unpatch = DiffUtils.unpatch(test2List, diff);
// unpatch.stream().forEach(System.out::println);
}
use of difflib.Patch in project Gargoyle by callakrsos.
the class DiffPathText method patchTest.
@Test
public void patchTest() throws IOException, URISyntaxException, PatchFailedException {
URL test1 = ClassLoader.getSystemClassLoader().getResource("compare/Test1");
URL test2 = ClassLoader.getSystemClassLoader().getResource("compare/Test2");
// 원본데이터 리스트
List<String> test1List = Files.readAllLines(new File(test1.toURI()).toPath());
List<String> test2List = Files.readAllLines(new File(test2.toURI()).toPath());
List<String> tmpOrigin = new LinkedList<String>();
test1List.forEach(str -> {
tmpOrigin.add(str);
});
List<String> tmpRevice = new LinkedList<String>();
test2List.forEach(str -> {
tmpRevice.add(str);
});
Patch diff = DiffUtils.diff(test1List, test2List);
System.out.println(diff.getDeltas());
List<Delta> deltas = diff.getDeltas();
Collections.reverse(deltas);
System.out.println("before");
System.out.println(tmpOrigin);
// 공백 작업pos
deltas.forEach(d -> {
Chunk original = d.getOriginal();
Chunk revised = d.getRevised();
int position = original.getPosition();
switch(d.getType()) {
case INSERT:
{
List<String> lines = (List<String>) original.getLines();
List<String> lines2 = (List<String>) revised.getLines();
tmpOrigin.addAll(position, lines2);
tmpRevice.addAll(position, lines);
}
break;
}
});
System.out.println("origin");
System.out.println(tmpOrigin);
System.out.println("revice");
System.out.println(tmpRevice);
// tmpOrigin.forEach(System.out::println);
}
Aggregations