|
| 1 | +package org.eclipse.incquery.runtime.base.test.datatype; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | + |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.Collection; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import org.eclipse.emf.common.command.Command; |
| 10 | +import org.eclipse.emf.common.notify.Notifier; |
| 11 | +import org.eclipse.emf.ecore.EDataType; |
| 12 | +import org.eclipse.emf.transaction.RecordingCommand; |
| 13 | +import org.eclipse.incquery.runtime.base.test.IncQueryBaseTest; |
| 14 | +import org.eclipse.incquery.runtime.base.test.util.ResourceAccess; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +import school.Course; |
| 18 | +import school.SchoolPackage; |
| 19 | +import school.Teacher; |
| 20 | +import school.Year; |
| 21 | + |
| 22 | +/** |
| 23 | + * Test cases used to test the {@link EDataType} related getters of EMF-IncQuery Base. |
| 24 | + * |
| 25 | + * @author Tamas Szabo |
| 26 | + * |
| 27 | + */ |
| 28 | +public class DataTypeTest extends IncQueryBaseTest { |
| 29 | + |
| 30 | + public DataTypeTest(Notifier notifier) { |
| 31 | + super(notifier); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Data type test for EInt |
| 36 | + */ |
| 37 | + @Test |
| 38 | + public void integerTest() { |
| 39 | + //these integers are present in the model , the EAttribute will be EInt |
| 40 | + Integer[] expectedNumbers = new Integer[] {0, 17, 20, 23, 37, 2011, 2012, 30}; |
| 41 | + List<Object> result = new ArrayList<Object>(navigationHelper.getDataTypeInstances(SchoolPackage.Literals.YEAR__STARTING_DATE.getEAttributeType())); |
| 42 | + |
| 43 | + for (Integer i : expectedNumbers) { |
| 44 | + assertTrue(result.contains(i)); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Data type test for EChar |
| 50 | + */ |
| 51 | + @Test |
| 52 | + public void charTest() { |
| 53 | + Character[] expectedChars = new Character[] {'A','B','C','D'}; |
| 54 | + Collection<Object> result = navigationHelper.getDataTypeInstances(SchoolPackage.Literals.SCHOOL_CLASS__CODE.getEAttributeType()); |
| 55 | + for (Character c : expectedChars) { |
| 56 | + assertTrue(result.contains(c)); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Data type test for EChar with modification |
| 62 | + */ |
| 63 | + @Test |
| 64 | + public void charModTest() { |
| 65 | + try { |
| 66 | + //the command removes any reference to schools thus no EChar will be present in the model |
| 67 | + final Command command = new RecordingCommand(ResourceAccess.getTransactionalEditingDomain()) { |
| 68 | + @Override |
| 69 | + protected void doExecute() { |
| 70 | + |
| 71 | + List<Course> courses = new ArrayList<Course>(ResourceAccess.getEObject().getCourses()); |
| 72 | + for (Course c : courses) { |
| 73 | + c.setSchool(null); |
| 74 | + } |
| 75 | + |
| 76 | + List<Teacher> teachers = new ArrayList<Teacher>(ResourceAccess.getEObject().getTeachers()); |
| 77 | + for (Teacher t : teachers) { |
| 78 | + t.setSchool(null); |
| 79 | + } |
| 80 | + |
| 81 | + List<Year> years = new ArrayList<Year>(ResourceAccess.getEObject().getYears()); |
| 82 | + for (Year y : years) { |
| 83 | + y.setSchool(null); |
| 84 | + } |
| 85 | + } |
| 86 | + }; |
| 87 | + ResourceAccess.getTransactionalEditingDomain().getCommandStack().execute(command); |
| 88 | + Collection<Object> result = navigationHelper.getDataTypeInstances(SchoolPackage.Literals.SCHOOL_CLASS__CODE.getEAttributeType()); |
| 89 | + assertTrue(result.isEmpty()); |
| 90 | + } |
| 91 | + finally { |
| 92 | + ResourceAccess.getTransactionalEditingDomain().getCommandStack().undo(); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments