Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 63683de

Browse files
committed
copied test cases from master to ci branch
1 parent 6fe570e commit 63683de

23 files changed

+1048
-388
lines changed

school/org.eclipse.incquery.runtime.base.test/META-INF/MANIFEST.MF

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Require-Bundle: org.eclipse.emf.ecore;bundle-version="2.7.0",
1212
org.eclipse.emf.ecore.xmi;bundle-version="2.7.0",
1313
com.google.guava;bundle-version="10.0.1",
1414
org.eclipse.emf.transaction;bundle-version="1.4.0",
15-
school;bundle-version="0.7.0"
15+
school;bundle-version="0.7.0",
16+
org.eclipse.incquery.runtime.base.itc;bundle-version="0.7.0"
1617

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<school:School xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:school="http://school.ecore" name="University">
3+
<teachers name="External teacher">
4+
<courses href="BUTE.school#//@courses.6"/>
5+
</teachers>
6+
</school:School>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.eclipse.incquery.runtime.base.test;
2+
3+
import java.util.Arrays;
4+
import java.util.Collection;
5+
6+
import org.eclipse.emf.common.notify.Notifier;
7+
import org.eclipse.incquery.runtime.base.api.IncQueryBaseFactory;
8+
import org.eclipse.incquery.runtime.base.api.NavigationHelper;
9+
import org.eclipse.incquery.runtime.base.exception.IncQueryBaseException;
10+
import org.eclipse.incquery.runtime.base.test.util.ResourceAccess;
11+
import org.junit.After;
12+
import org.junit.Before;
13+
import org.junit.runner.RunWith;
14+
import org.junit.runners.Parameterized;
15+
import org.junit.runners.Parameterized.Parameters;
16+
17+
@RunWith(Parameterized.class)
18+
public abstract class IncQueryBaseTest {
19+
20+
protected NavigationHelper navigationHelper;
21+
protected Notifier notifier;
22+
protected boolean wildcardMode;
23+
24+
public IncQueryBaseTest(Notifier notifier) {
25+
this.notifier = notifier;
26+
this.wildcardMode = true;
27+
}
28+
29+
public IncQueryBaseTest(Notifier notifier, boolean wildcardMode) {
30+
this.notifier = notifier;
31+
this.wildcardMode = wildcardMode;
32+
}
33+
34+
@After
35+
public void dispose() {
36+
navigationHelper.dispose();
37+
}
38+
39+
@Before
40+
public void init() {
41+
try {
42+
navigationHelper = IncQueryBaseFactory.getInstance().createNavigationHelper(notifier, wildcardMode, null);
43+
}
44+
catch (IncQueryBaseException e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
49+
@Parameters
50+
public static Collection<Notifier[]> getNotifiers() {
51+
return Arrays.asList(new Notifier[][] {
52+
{ ResourceAccess.getResourceSet() },
53+
{ ResourceAccess.getResource() },
54+
{ ResourceAccess.getEObject() }
55+
});
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.eclipse.incquery.runtime.base.test;
2+
3+
import org.eclipse.incquery.runtime.base.test.attribute.AttributeValueTest;
4+
import org.eclipse.incquery.runtime.base.test.datatype.DataTypeTest;
5+
import org.eclipse.incquery.runtime.base.test.feature.FeatureTest;
6+
import org.eclipse.incquery.runtime.base.test.instance.InstanceTest;
7+
import org.eclipse.incquery.runtime.base.test.inverseref.InverseReferenceTest;
8+
import org.eclipse.incquery.runtime.base.test.listener.DataTypeListenerTest;
9+
import org.eclipse.incquery.runtime.base.test.listener.FeatureListenerTest;
10+
import org.eclipse.incquery.runtime.base.test.listener.InstanceListenerTest;
11+
import org.eclipse.incquery.runtime.base.test.tc.TransitiveClosureHelperTest;
12+
import org.junit.runner.RunWith;
13+
import org.junit.runners.Suite;
14+
import org.junit.runners.Suite.SuiteClasses;
15+
16+
@RunWith(Suite.class)
17+
@SuiteClasses({
18+
InverseReferenceTest.class,
19+
AttributeValueTest.class,
20+
InstanceTest.class,
21+
FeatureTest.class,
22+
DataTypeTest.class,
23+
FeatureListenerTest.class,
24+
DataTypeListenerTest.class,
25+
InstanceListenerTest.class,
26+
TransitiveClosureHelperTest.class
27+
})
28+
public class IncQueryBaseTestSuite {
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.eclipse.incquery.runtime.base.test.attribute;
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.notify.Notifier;
10+
import org.eclipse.emf.ecore.EAttribute;
11+
import org.eclipse.emf.ecore.EObject;
12+
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
13+
import org.eclipse.incquery.runtime.base.test.IncQueryBaseTest;
14+
import org.junit.Test;
15+
16+
import school.SchoolFactory;
17+
18+
/**
19+
* Test cases used to test the {@link EAttribute} related getters of EMF-IncQuery Base.
20+
*
21+
* @author Tamas Szabo
22+
*
23+
*/
24+
public class AttributeValueTest extends IncQueryBaseTest {
25+
26+
private static final String SCHOOL_NAME = "Budapest University of Technology and Economics";
27+
28+
public AttributeValueTest(Notifier notifier) {
29+
super(notifier);
30+
}
31+
32+
/**
33+
* String based {@link EAttribute} holder finding
34+
*/
35+
@Test
36+
public void valueTest() {
37+
Collection<Setting> result = navigationHelper.findByAttributeValue(SCHOOL_NAME);
38+
assertTrue(result.size() == 1);
39+
}
40+
41+
/**
42+
* String based {@link EAttribute} holder finding with fixed {@link EAttribute} instance
43+
*/
44+
@Test
45+
public void valueAndAttributeTest() {
46+
Collection<EObject> result = navigationHelper.findByAttributeValue(SCHOOL_NAME, SchoolFactory.eINSTANCE.getSchoolPackage().getSchool_Name());
47+
assertTrue(result.size() == 1);
48+
}
49+
50+
/**
51+
* String based {@link EAttribute} holder finding with fixed collection of {@link EAttribute} instances
52+
*/
53+
@Test
54+
public void valueAndAttributesTest() {
55+
List<EAttribute> attributes = new ArrayList<EAttribute>();
56+
attributes.add(SchoolFactory.eINSTANCE.getSchoolPackage().getSchool_Name());
57+
attributes.add(SchoolFactory.eINSTANCE.getSchoolPackage().getCourse_Subject());
58+
Collection<Setting> result = navigationHelper.findByAttributeValue("Graph transformations", attributes);
59+
assertTrue(result.size() == 1);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.eclipse.incquery.runtime.base.test.feature;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.util.Collection;
6+
7+
import org.eclipse.emf.common.command.Command;
8+
import org.eclipse.emf.common.notify.Notifier;
9+
import org.eclipse.emf.ecore.EObject;
10+
import org.eclipse.emf.ecore.EStructuralFeature;
11+
import org.eclipse.emf.transaction.RecordingCommand;
12+
import org.eclipse.incquery.runtime.base.test.IncQueryBaseTest;
13+
import org.eclipse.incquery.runtime.base.test.util.ResourceAccess;
14+
import org.junit.Test;
15+
16+
import school.SchoolPackage;
17+
import school.Student;
18+
19+
/**
20+
* Test cases used to test the {@link EStructuralFeature} related getters of EMF-IncQuery Base.
21+
*
22+
* @author Tamas Szabo
23+
*
24+
*/
25+
public class FeatureTest extends IncQueryBaseTest {
26+
27+
public FeatureTest(Notifier notifier) {
28+
super(notifier);
29+
}
30+
31+
/**
32+
* Finding all students in the model
33+
*/
34+
@Test
35+
public void holderTest() {
36+
Collection<EObject> result = navigationHelper.getHoldersOfFeature(SchoolPackage.eINSTANCE.getStudent_Name());
37+
for (EObject obj : ResourceAccess.getAllContents()) {
38+
if (obj instanceof Student) {
39+
assertTrue(result.contains(obj));
40+
}
41+
}
42+
}
43+
44+
/**
45+
* Removing all students from the model and resolving feature holders after that
46+
*/
47+
@Test
48+
public void holderModTest() {
49+
try {
50+
final Command command = new RecordingCommand(ResourceAccess.getTransactionalEditingDomain()) {
51+
@Override
52+
protected void doExecute() {
53+
//years and courses have references to students
54+
ResourceAccess.getEObject().getCourses().clear();
55+
ResourceAccess.getEObject().getYears().clear();
56+
}
57+
};
58+
ResourceAccess.getTransactionalEditingDomain().getCommandStack().execute(command);
59+
Collection<EObject> result = navigationHelper.getHoldersOfFeature(SchoolPackage.eINSTANCE.getStudent_Name());
60+
assertTrue(result.isEmpty());
61+
}
62+
finally {
63+
ResourceAccess.getTransactionalEditingDomain().getCommandStack().undo();
64+
}
65+
}
66+
67+
private static final String SCHOOL_NAME = "Budapest University of Technology and Economics";
68+
69+
/**
70+
* Feature holder resolving based on String literal
71+
*/
72+
@Test
73+
public void stringValueTest() {
74+
Collection<EObject> result = navigationHelper.findByFeatureValue(SCHOOL_NAME, SchoolPackage.Literals.SCHOOL__NAME);
75+
assertTrue(result.size() == 1);
76+
}
77+
78+
/**
79+
* Feature holder resolving based on Integer value
80+
*/
81+
@Test
82+
public void integerValueTest() {
83+
Collection<EObject> result = navigationHelper.findByFeatureValue(2011, SchoolPackage.Literals.YEAR__STARTING_DATE);
84+
assertTrue(result.size() == 1);
85+
}
86+
}

0 commit comments

Comments
 (0)