Exemplo n.º 1
0
 private void doTransformations(MPatchModel mpatch) {
   final int deps = MPatchDependencyTransformation.calculateDependencies(mpatch);
   assertNull(
       MPatchConstants.MPATCH_SHORT_NAME + " is not valid!",
       CompareTestHelper.validateMPatch(mpatch));
   assertEquals("Dependencies were not calculated correctly!", 2, deps);
   final int refs = InternalReferencesTransformation.createInternalReferences(mpatch);
   assertNull(
       MPatchConstants.MPATCH_SHORT_NAME + " is not valid!",
       CompareTestHelper.validateMPatch(mpatch));
   assertEquals("Internal references were not created correctly!", 2, refs);
   final int card = GeneralizeTransformation.unboundSymbolicReferences(mpatch);
   assertNull(
       MPatchConstants.MPATCH_SHORT_NAME + " is not valid!",
       CompareTestHelper.validateMPatch(mpatch));
   assertEquals("Cardinality weakening was not performed correctly!", 8, card);
   final int str = GeneralizeTransformation.expandScope(mpatch);
   assertNull(
       MPatchConstants.MPATCH_SHORT_NAME + " is not valid!",
       CompareTestHelper.validateMPatch(mpatch));
   assertTrue("String weakening was not performed correctly!", str >= 3);
 }
Exemplo n.º 2
0
 private void testOCL(String unchangedUri, String changedUri) {
   for (ISymbolicReferenceCreator symrefCreator : TestConstants.SYM_REF_CREATORS) {
     for (IModelDescriptorCreator descriptorCreator : TestConstants.MODEL_DESCRIPTOR_CREATORS) {
       MPatchModel mpatch =
           CompareTestHelper.getMPatchFromUris(
               changedUri, unchangedUri, symrefCreator, descriptorCreator);
       assertNotNull(
           "Preceeding transformation emfdiff2mpatch failed with symrefCreator: "
               + symrefCreator.getLabel()
               + " and descriptorCreator: "
               + descriptorCreator.getLabel(),
           mpatch);
       CommonTestOperations.checkOclExpressions(mpatch);
     }
   }
 }
Exemplo n.º 3
0
  /** See test description here: {@link InternalRefTest}. */
  @Test
  public void testInternalRef() {
    // get creators
    final ISymbolicReferenceCreator symrefCreator =
        ExtensionManager.getAllSymbolicReferenceCreators().get("Condition-based");
    final IModelDescriptorCreator descriptorCreator =
        ExtensionManager.getAllModelDescriptorCreators().get("Default");
    final String info =
        "symrefCreator: "
            + symrefCreator.getLabel()
            + ", descriptorCreator: "
            + descriptorCreator.getLabel();

    // create mpatch
    final MPatchModel mpatch =
        CompareTestHelper.getMPatchFromUris(
            TestConstants.INTERNAL_REF_URI2,
            TestConstants.INTERNAL_REF_URI1,
            symrefCreator,
            descriptorCreator);

    doTransformations(mpatch);
    modifyDiff(mpatch);

    // resolve references to other model
    final EPackage applyModel =
        (EPackage)
            CompareTestHelper.loadModel(TestConstants.INTERNAL_REF_URI3, new ResourceSetImpl())
                .get(0);
    final ResolvedSymbolicReferences resolvedReferences =
        CompareTestHelper.resolveReferences(mpatch, applyModel, info);

    // apply differences
    final Map<Integer, Boolean> options = new HashMap<Integer, Boolean>();
    options.put(IMPatchApplication.OPTION_STORE_BINDING, true);
    final MPatchApplicationResult result =
        TestConstants.DIFF_APPLIER.applyMPatch(resolvedReferences, options);

    // check application status
    assertTrue("Some changes failed to apply: " + result.failed, result.failed.isEmpty());
    assertTrue(
        "Cross reference restoring failed for: " + result.crossReferences,
        result.crossReferences.isEmpty());
    assertEquals(
        "Application result was not successful!",
        MPatchApplicationResult.ApplicationStatus.SUCCESSFUL,
        result.status);

    // check model!
    assertEquals(
        "Different number of elements in root package than expected: "
            + applyModel.getEClassifiers(),
        3,
        applyModel.getEClassifiers().size());
    assertEquals(
        "Different number of elements in sub package than expected: "
            + applyModel.getESubpackages().get(0).getEClassifiers(),
        1,
        applyModel.getESubpackages().get(0).getEClassifiers().size());
    for (EClassifier classifier : applyModel.getEClassifiers()) {
      if (!classifier.getName().equals("C")) {
        final EClass aClass = (EClass) classifier;
        assertEquals(
            "Cross references (eSuperType) does not refer to the two new classes 'C', but: "
                + aClass.getESuperTypes(),
            2,
            aClass.getESuperTypes().size());
      }
    }
  }