package org.flymine.objectstore.query;

import junit.framework.TestCase;

import org.flymine.model.testmodel.Department;


public class ContainsConstraintTest extends TestCase {

    private ContainsConstraint constraint;
    private QueryCollectionReference collection;
    private QueryClass cls;

    public ContainsConstraintTest(String arg1) {
        super(arg1);
    }

    public void setUp() throws Exception {
        cls = new QueryClass(Department.class);
        collection = new QueryCollectionReference(cls, "employees");
    }

    public void testNullConstructor1() throws Exception {
        try {
            constraint = new ContainsConstraint(null, ContainsConstraint.CONTAINS, cls);
            fail("Expected: NullPointerException");
        } catch (NullPointerException e) {
        }
    }

    public void testNullConstructor2() throws Exception {
        try {
            constraint = new ContainsConstraint(collection, ContainsConstraint.CONTAINS, null);
            fail("Expected: NullPointerException");
        } catch (NullPointerException e) {
        }
    }

    public void testInvalidType() {
        try {
            constraint = new ContainsConstraint(collection, 234, cls);
            fail("An IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException e) {
        }
    }

}


@@ -114,16 +114,104 @@
 rtment;%0A
+import org.flymine.model.testmodel.Manager;%0Aimport org.flymine.model.testmodel.Employee;
 %0A%0Apublic
@@ -344,22 +344,60 @@
 nce coll
-ection
+Ref;%0A    private QueryObjectReference objRef
 ;%0A    pr
@@ -413,19 +413,29 @@
 ryClass 
-cls
+qc1, qc2, qc3
 ;%0A%0A    p
@@ -557,19 +557,19 @@
         
-cls
+qc1
  = new Q
@@ -605,26 +605,114 @@
         
-collection
+qc2 = new QueryClass(Manager.class);%0A        qc3 = new QueryClass(Employee.class);%0A        collRef
  = new Q
@@ -735,19 +735,19 @@
 ference(
-cls
+qc1
 , %22emplo
@@ -750,24 +750,83 @@
 mployees%22);%0A
+        objRef = new QueryObjectReference(qc1, %22manager%22);%0A
     %7D%0A%0A    p
@@ -975,19 +975,19 @@
 NTAINS, 
-cls
+qc3
 );%0A     
@@ -1217,22 +1217,19 @@
 int(coll
-ection
+Ref
 , Contai
@@ -1476,24 +1476,366 @@
 coll
-ection, 234, cls
+Ref, 234, qc3);%0A            fail(%22An IllegalArgumentException should have been thrown%22);%0A        %7D catch (IllegalArgumentException e) %7B%0A        %7D%0A    %7D%0A%0A    public void testIncompatibleTypesReference() throws Exception %7B%0A        try %7B%0A            // objRef has type Manager, qc3 is type Employee%0A            constraint = new ContainsConstraint(objRef, 1, qc3
 );%0A 

test that Exception is thrown if QueryObjectReference and QueryClass types differ