use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.
the class DatabaseComparisonTest method testDatabaseComparison.
@SuppressWarnings("unchecked")
@Test
public void testDatabaseComparison() {
Comparison expected = (Comparison) this.expectedResourceWrapper.getResource().getContents().get(0);
Comparison actual = (Comparison) this.actualResourceWrapper.getResource().getContents().get(0);
try {
// Comparing Comparisons using EMFCompare does not seem to do well.
// We thus compare the Comparisons in a rough way manually, errors
// can
// be caught in later stages.
DatabaseComparisonTestSuite.INSTANCE.compareComparisons(expected, actual);
// Only check for the same number of matches... :-/
assertEquals(EMFUtils.getAllContentsOfType(ComparePackage.Literals.MATCH, expected).size(), EMFUtils.getAllContentsOfType(ComparePackage.Literals.MATCH, actual).size());
} catch (AssertionError e) {
System.out.println("Actual model being used for comparison:");
try {
this.actualResourceWrapper.getResource().save(System.out, null);
} catch (final IOException ex) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Expected model being used for comparison: (from: " + this.expectedResourceWrapper.toString() + ")");
try {
this.expectedResourceWrapper.getResource().save(System.out, null);
} catch (final IOException ex) {
// TODO Auto-generated catch block
e.printStackTrace();
}
throw e;
}
}
use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.
the class DatabaseComparisonTestSuite method loadAndProcessInputs.
/**
* Loads the input models found at the given URIs. Then processes their
* contents and places the result in a new Resource with the given desired
* URI. That URI is the same as the URI of the expected output model, so
* that EMF Compare has no problem matching the resources. This method
* <i>does not</i> modify the input models.
*
* @param inputURI
* the URI of the input model.
* @param desiredSynchronizedInputURI
* the desired URI for the result of the processing of the inputs
* of this test suite. Should be the same as that of the expected
* output.
* @return the resource containing the result of processing the inputs of
* this test suite.
*/
public Resource loadAndProcessInputs(List<URI> inputURIs, URI desiredProcessedInputURI) {
// Load input data for the test
final Resource leftDatabaseResource = DatabaseCompareAbstractTestSuite.loadResource(inputURIs.get(0));
final Resource rightDatabaseResource = DatabaseCompareAbstractTestSuite.loadResource(inputURIs.get(1));
// Compare the Database models
final DataBase leftDatabase = (DataBase) leftDatabaseResource.getContents().get(0);
final DataBase rightDatabase = (DataBase) rightDatabaseResource.getContents().get(0);
final Comparison comparison = EMFCompareUtils.compare(leftDatabase, rightDatabase);
// Store the resulting Comparison into an EMF Resource
final Resource comparisonResource = DatabaseCompareAbstractTestSuite.createResourceSet().createResource(desiredProcessedInputURI);
comparisonResource.getContents().add(comparison);
return comparisonResource;
}
use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.
the class AbtractTest method diff.
protected Comparison diff(TableContainer left, TableContainer right) throws Exception {
Comparison comparison = DatabaseCompareService.compare(left, right);
assertNotNull(comparison);
// DatabaseChangeSet databaseChangeSet = null;
// if (comparison instanceof DatabaseChangeSet) {
// databaseChangeSet = (DatabaseChangeSet) comparison;
// }
// assertNotNull(databaseChangeSet);
DiffContentService DiffContentService = new DiffContentService();
System.out.println("---- Print ChangeSet -----");
for (Diff element : comparison.getDifferences()) {
System.out.println("\t" + element.eClass().getName());
List<Diff> subDiffs = DiffContentService.getSubDiffs(element, comparison);
if (!subDiffs.isEmpty()) {
for (Diff e : subDiffs) {
System.out.println("\t\t" + e.eClass().getName() + "(" + e + ")");
}
}
}
return comparison;
}
use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.
the class AbstractSQLGenerationTest method assertGenerationEquals.
public void assertGenerationEquals(TableContainer source, TableContainer target, String expectationsFolderPath) {
File targetFolder = createTargetFolder();
File expectationsFolder = createExpectationsFolder(expectationsFolderPath);
try {
// Compare
Comparison comparison = DatabaseCompareService.compare(source, target);
// and generate sql scripts based on the comparison
DatabaseGen generator = new DatabaseGen(comparison, targetFolder, Collections.emptyList());
generator.doGenerate(new BasicMonitor());
} catch (Exception e) {
deleteFile(targetFolder);
deleteFile(expectationsFolder);
fail("Comparison failed with an exception : " + e.getMessage());
}
compareFolders(targetFolder, expectationsFolder);
// Delete targetFolder and expectationsFolder
deleteFile(targetFolder);
deleteFile(expectationsFolder);
}
use of org.eclipse.emf.compare.Comparison in project InformationSystem by ObeoNetwork.
the class AbtractGeneratorTest method assertGen.
protected void assertGen(String testCase, GeneratedFile... generatedFiles) throws Exception {
Comparison databaseChangeSet = diff(testCase + "/v2.database", testCase + "/v1.database");
File folder = new File("testFolder");
AcceleoTextGenerationListener acceleoTextGenerationListener = generate(databaseChangeSet, folder);
assertSQL(acceleoTextGenerationListener, generatedFiles);
}
Aggregations