Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PALLADIO-539 Add method isAssignableFrom to Interface #35

Merged
merged 2 commits into from Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions bundles/org.palladiosimulator.pcm/model/pcm.ecore
Expand Up @@ -631,6 +631,7 @@
</eAnnotations>
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
<details key="validationDelegates" value="http://www.eclipse.org/emf/2002/Ecore/OCL"/>
<details key="invocationDelegates" value="http://www.eclipse.org/emf/2002/Ecore/OCL"/>
</eAnnotations>
<eClassifiers xsi:type="ecore:EClass" name="PassiveResource" eSuperTypes="#//core/entity/Entity">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
Expand Down Expand Up @@ -818,6 +819,15 @@
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL">
<details key="noProtocolTypeIDUsedTwice" value="self.protocols__Interface->forAll(p1, p2 |&#xD;&#xA;p1.protocolTypeID &lt;> p2.protocolTypeID)&#xD;&#xA;"/>
</eAnnotations>
<eOperations name="isAssignableFrom" lowerBound="1" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EBoolean">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore/OCL">
<details key="body" value="self->closure(i : Interface | i.parentInterfaces__Interface)->including(self)->includes(otherInterface)"/>
</eAnnotations>
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="The method tests if the interface given as parameter is the same as the called interface or is a transitive parent of the called interface."/>
</eAnnotations>
<eParameters name="otherInterface" lowerBound="1" eType="#//repository/Interface"/>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="parentInterfaces__Interface"
ordered="false" upperBound="-1" eType="#//repository/Interface">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
Expand Down
@@ -0,0 +1,94 @@
package org.palladiosimulator.pcm.repository.impl;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.palladiosimulator.pcm.repository.Interface;
import org.palladiosimulator.pcm.repository.RepositoryFactory;

import tools.mdsd.library.standalone.initialization.StandaloneInitializationException;
import tools.mdsd.library.standalone.initialization.StandaloneInitializerBuilder;

public class InterfaceTest {

@BeforeAll
public static void init() throws StandaloneInitializationException {
StandaloneInitializerBuilder.builder()
.build()
.init();
}

@Test
public void testIsAssignedFromNull() {
var i0 = createInterface();
assertFalse(i0.isAssignableFrom(null));
}

@Test
public void testIsAssignedFromUnrelatedInterface() {
var i0 = createInterface();
var i1 = createInterface();
assertFalse(i0.isAssignableFrom(i1));
}

@Test
public void testIsAssignedFromSameInterface() {
var i0 = createInterface();
assertTrue(i0.isAssignableFrom(i0));
}

@Test
public void testIsAssignedFromDirectParent() {
var i0 = createInterface();
var i0_0 = createInterface();
i0.getParentInterfaces__Interface().add(i0_0);
assertTrue(i0.isAssignableFrom(i0_0));
assertFalse(i0_0.isAssignableFrom(i0));
}

@Test
public void testIsAssignedFromDirectParentFromList() {
var i0 = createInterface();
var i0_0 = createInterface();
var i0_1 = createInterface();
i0.getParentInterfaces__Interface().add(i0_0);
i0.getParentInterfaces__Interface().add(i0_1);
assertTrue(i0.isAssignableFrom(i0_0));
assertTrue(i0.isAssignableFrom(i0_1));
assertFalse(i0_0.isAssignableFrom(i0));
assertFalse(i0_1.isAssignableFrom(i0));
}

@Test
public void testIsAssignedFromIndirectParent() {
var i0 = createInterface();
var i0_0 = createInterface();
i0.getParentInterfaces__Interface().add(i0_0);
var i0_0_0 = createInterface();
i0_0.getParentInterfaces__Interface().add(i0_0_0);
assertTrue(i0.isAssignableFrom(i0_0_0));
assertFalse(i0_0_0.isAssignableFrom(i0));
assertFalse(i0_0_0.isAssignableFrom(i0_0));
}

@Test
public void testIsAssignedFromIndirectParentInDiamond() {
var i0 = createInterface();
var i0_0 = createInterface();
var i0_1 = createInterface();
var i0_01_0 = createInterface();
i0.getParentInterfaces__Interface().add(i0_0);
i0.getParentInterfaces__Interface().add(i0_1);
i0_0.getParentInterfaces__Interface().add(i0_01_0);
i0_1.getParentInterfaces__Interface().add(i0_01_0);
assertTrue(i0.isAssignableFrom(i0_01_0));
assertFalse(i0_01_0.isAssignableFrom(i0));
}

protected static Interface createInterface() {
return RepositoryFactory.eINSTANCE.createOperationInterface();
}

}