-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: UseModelApi: Lacks of self for attributes in OCL Expression
- Now the correct context for pre and postconditions is created - This includes the automatically provided variable result for postconditions - Code is similar to the code in ASTPrePostCondition
- Loading branch information
Showing
2 changed files
with
86 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
use-core/src/test/java/org/tzi/use/uml/mm/ModelAPITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.tzi.use.uml.mm; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.tzi.use.api.UseApiException; | ||
import org.tzi.use.api.UseModelApi; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ModelAPITest { | ||
@Test | ||
public void testConstraintCreation() throws UseApiException { | ||
UseModelApi api = new UseModelApi("UnitTest"); | ||
MPrePostCondition ppc; | ||
|
||
api.createClass("A", false); | ||
api.createAttribute("A", "foo", "String"); | ||
api.createOperation("A", "bar", new String[0][0], "String"); | ||
ppc = api.createPrePostCondition("A", "bar", "self.foo is defined", "self.foo.isDefined()", true); | ||
assertEquals("self.foo is defined", ppc.name()); | ||
|
||
ppc = api.createPrePostCondition("A", "bar", "foo without self is defined", "foo.isDefined()", true); | ||
assertEquals("foo without self is defined", ppc.name()); | ||
|
||
assertEquals(2, api.getClass("A").operation("bar", true).preConditions().size()); | ||
|
||
api.createPrePostCondition("A", "bar", "result can be checked", "result.isDefined()", false); | ||
|
||
assertEquals(1, api.getClass("A").operation("bar", true).postConditions().size()); | ||
|
||
Exception ex = assertThrows(UseApiException.class, () | ||
-> api.createPrePostCondition("B", "", "", "", true)); | ||
|
||
assertTrue(ex.getMessage().contains("Unknown")); | ||
} | ||
} |