Search in sources :

Example 6 with Comparison

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;
    }
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with Comparison

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;
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) Resource(org.eclipse.emf.ecore.resource.Resource) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 8 with Comparison

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;
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) Diff(org.eclipse.emf.compare.Diff) DiffContentService(org.obeonetwork.dsl.database.compare.extensions.services.DiffContentService)

Example 9 with 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);
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) DatabaseGen(org.obeonetwork.dsl.database.sqlgen.DatabaseGen) File(java.io.File) BasicMonitor(org.eclipse.emf.common.util.BasicMonitor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 10 with Comparison

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);
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) File(java.io.File)

Aggregations

Comparison (org.eclipse.emf.compare.Comparison)22 Diff (org.eclipse.emf.compare.Diff)7 DefaultComparisonScope (org.eclipse.emf.compare.scope.DefaultComparisonScope)7 IComparisonScope (org.eclipse.emf.compare.scope.IComparisonScope)7 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 EMFCompare (org.eclipse.emf.compare.EMFCompare)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 EObject (org.eclipse.emf.ecore.EObject)5 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 TableContainer (org.obeonetwork.dsl.database.TableContainer)4 ReferenceChange (org.eclipse.emf.compare.ReferenceChange)3 BasicMonitor (org.eclipse.emf.common.util.BasicMonitor)2 Match (org.eclipse.emf.compare.Match)2 Test (org.junit.Test)2 DataBase (org.obeonetwork.dsl.database.DataBase)2 URISyntaxException (java.net.URISyntaxException)1