Skip to content

Instantly share code, notes, and snippets.

@louismrose
Created October 2, 2013 10:58
Show Gist options
  • Save louismrose/6792033 to your computer and use it in GitHub Desktop.
Save louismrose/6792033 to your computer and use it in GitHub Desktop.
Design for @cascade delete type mappings in Flock (bug 418494).
public class DeleteCascade extends FlockAcceptanceTest {
private static final String strategy = "@cascade" + "\n" +
"delete Family";
private static final String originalModel = "Families {" +
" Family {" +
" name: \"The Smiths\"" +
" members: Person { " +
" name: \"John\"" +
" }" +
" }" +
" Person {" +
" name: \"Jane\"" +
" }" +
"}";
@BeforeClass
public static void setup() throws Exception {
migrateFamiliesToFamilies(strategy, originalModel);
}
@Test
public void migratedShouldContainOnePerson() {
migrated.assertEquals(1, "Person.all.size()");
}
@Test
public void migratedPersonShouldBeJaneNotJohn() {
migrated.assertEquals("Jane", "Person.all.first.name");
}
}
public class DeleteCascadeToGrandchildren extends FlockAcceptanceTest {
private static final String strategy = "@cascade" + "\n" +
"delete Model";
private static final String originalModel = "Families {" +
" Model {" +
" contents: Family {" +
" name: \"The Smiths\"" +
" members: Person { " +
" name: \"John\"" +
" }" +
" }" +
" }" +
" Person {" +
" name: \"Jane\"" +
" }" +
"}";
@BeforeClass
public static void setup() throws Exception {
migrateFamiliesToFamilies(strategy, originalModel);
}
@Test
public void migratedShouldContainOnePerson() {
migrated.assertEquals(1, "Person.all.size()");
}
@Test
public void migratedPersonShouldBeJaneNotJohn() {
migrated.assertEquals("Jane", "Person.all.first.name");
}
}
public class DeleteCascadeWithGuard extends FlockAcceptanceTest {
private static final String strategy = "@cascade" + "\n" +
"delete Family when: original.name == \"The Smiths\"";
private static final String originalModel = "Families {" +
" Family {" +
" name: \"The Smiths\"" +
" members: Person { " +
" name: \"John\"" +
" }" +
" }" +
" Family {" +
" name: \"The Does\"" +
" members: Person { " +
" name: \"Jane\"" +
" }" +
" }" +
"}";
@BeforeClass
public static void setup() throws Exception {
migrateFamiliesToFamilies(strategy, originalModel);
}
@Test
public void migratedShouldContainOneFamily() {
migrated.assertEquals(1, "Family.all.size()");
}
@Test
public void migratedPersonShouldBeTheDoesNotTheSmiths() {
migrated.assertEquals("The Does", "Family.all.first.name");
}
@Test
public void migratedShouldContainOnePerson() {
migrated.assertEquals(1, "Person.all.size()");
}
@Test
public void migratedPersonShouldBeJaneNotJohn() {
migrated.assertEquals("Jane", "Person.all.first.name");
}
}
@namespace(uri="families", prefix="families")
package families;
import "platform:/resource/org.eclipse.epsilon.hutn.test.dependencies.model/models/org/eclipse/epsilon/hutn/test/models/BankAccounts.ecore";
abstract class NamedElement {
attr String name;
}
class Family extends NamedElement {
attr String[*] address;
ref Pet[*] pets;
attr int numberOfChildren;
val Person[*] members;
attr String ~id;
attr boolean nuclear;
attr float averageAge;
readonly derived ref Dog[+] dogs;
ref District#families district;
attr int[*] lotteryNumbers;
attr double averageAgePrecise;
}
class Pet extends NamedElement {
attr boolean male;
}
class Person extends NamedElement {
ref bankAccounts.Account[*] sharedAccounts;
val bankAccounts.Account[*] accounts;
ref Person[*] friends;
ref Person[0..2] parents;
ref Person[0..4] allParents;
}
class Dog extends Pet {
attr boolean loud;
attr DogBreed[1] breed;
ref District#dogs district;
}
enum DogBreed {
poodle = 1;
labrador = 2;
}
class District {
val Family[+]#district families;
val Dog[+]#district dogs;
}
class Suburb extends District {
}
class Model extends NamedElement {
val NamedElement[*] contents;
val NamedElement[*] contents2;
}
class Bike {
val Person rider;
ref Family owner;
}
class Band {
ref Person[3..*] members;
}
public class StrictDeleteCascade extends FlockAcceptanceTest {
private static final String strategy = "@cascade" + "\n" +
"@strict" + "\n" +
"delete District";
private static final String originalModel = "Families {" +
" District {" +
" families: Family {" +
" name: \"The Smiths\"" +
" }" +
" dogs: Dog {" +
" name: \"Fido\"" +
" }" +
" }" +
" Suburb {" +
" families: Family {" +
" name: \"The Does\"" +
" }" +
" dogs: Dog {" +
" name: \"Rex\"" +
" }" +
" }" +
"}";
@BeforeClass
public static void setup() throws Exception {
migrateFamiliesToFamilies(strategy, originalModel);
}
@Test
public void migratedShouldContainOneSuburb() {
migrated.assertEquals(1, "Suburb.all.size()");
}
@Test
public void migratedShouldContainOneFamily() {
migrated.assertEquals(1, "Family.all.size()");
}
@Test
public void migratedFamilyShouldBeTheDoesNotTheSmiths() {
migrated.assertEquals("The Does", "Family.all.first.name");
}
@Test
public void migratedShouldContainOneDog() {
migrated.assertEquals(1, "Dog.all.size()");
}
public void migratedDogShouldBeRexNotFido() {
migrated.assertEquals("Rex", "Dog.all.first.name");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment