예제 #1
0
 protected InterMineBag createEmployeeList() throws Exception {
   ObjectStoreWriter osw = null;
   try {
     Profile superUser = im.getProfileManager().getSuperuserProfile();
     osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest");
     Employee e1 = new Employee();
     e1.setName("Employee1");
     Employee e2 = new Employee();
     e2.setName("Employee2");
     Department d1 = new Department();
     d1.setName("department");
     Company company = new CompanyShadow();
     company.setName("company");
     Contractor contractor = new Contractor();
     contractor.setName("contractor");
     osw.store(contractor);
     company.addContractors(contractor);
     osw.store(company);
     d1.setCompany(company);
     osw.store(d1);
     e1.setDepartment(d1);
     e2.setDepartment(d1);
     osw.store(e1);
     osw.store(e2);
     InterMineBag list = superUser.createBag("employeeList", "Employee", "", im.getClassKeys());
     Collection<Integer> ids = new ArrayList<Integer>();
     ids.add(e1.getId());
     ids.add(e2.getId());
     list.addIdsToBag(ids, "Employee");
     return list;
   } finally {
     osw.close();
   }
 }
예제 #2
0
  // Test with a PathQuery and some dummy results, call method with a made up row,
  // create expected ResultElements.  Doesn't need too much testing as Path.resolve() is tested.
  public void testTranslateRow() throws Exception {
    PathQuery pq = new PathQuery(model);
    pq.addViews("Department.name", "Department.company.name", "Department.manager.name");
    Map<String, QuerySelectable> pathToQueryNode = new HashMap();
    Query query = MainHelper.makeQuery(pq, new HashMap(), pathToQueryNode, null, null);
    Results results = osd.execute(query);
    WebResults webResults = new WebResults(im, pq, results, pathToQueryNode, classKeys);
    List row1 = webResults.getResultElements(0);

    Department dept1 = new Department();
    dept1.setId(new Integer(4));
    dept1.setName("Department1");
    ResultElement res1 = new ResultElement(dept1, new Path(model, "Department.name"), false);

    Company c1 =
        (Company) DynamicUtil.instantiateObject("org.intermine.model.testmodel.Company", null);
    c1.setId(new Integer(1));
    c1.setName("Company1");
    ResultElement res2 = new ResultElement(c1, new Path(model, "Department.company.name"), false);

    Manager m1 = new Manager();
    m1.setId(new Integer(1));
    m1.setSeniority(new Integer(100));
    m1.setName("Manager1");
    ResultElement res3 = new ResultElement(m1, new Path(model, "Department.manager.name"), false);

    ResultsRow expected = new ResultsRow();
    expected.add(new MultiRowFirstValue(res1, 1));
    expected.add(new MultiRowFirstValue(res2, 1));
    expected.add(new MultiRowFirstValue(res3, 1));
    assertEquals(new MultiRow(Collections.singletonList(expected)), row1);
  }
예제 #3
0
  public void testAddToCollection() throws Exception {
    Company c1 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    Contractor c2 = new Contractor();
    c1.setName("Michael");
    c2.setName("Albert");

    try {
      writer.store(c1);
      writer.store(c2);

      Company c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(0, c3.getContractors().size());

      writer.addToCollection(c1.getId(), Company.class, "contractors", c2.getId());

      c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(1, c3.getContractors().size());
      assertTrue(c3.getContractors().iterator().next() instanceof Contractor);
      assertEquals(c2.getId(), ((Contractor) c3.getContractors().iterator().next()).getId());
    } finally {
      writer.delete(c1);
      writer.delete(c2);
    }
  }
예제 #4
0
 protected InterMineBag createCompanyList() throws Exception {
   ObjectStoreWriter osw = null;
   try {
     osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest");
     Profile superUser = im.getProfileManager().getSuperuserProfile();
     Company c1 = new CompanyShadow();
     c1.setName("CompanyA");
     Company c2 = new CompanyShadow();
     c2.setName("CompanyB");
     osw.store(c1);
     osw.store(c2);
     InterMineBag list = superUser.createBag("companyList", "Company", "", im.getClassKeys());
     Collection<Integer> ids = new ArrayList<Integer>();
     ids.add(c1.getId());
     ids.add(c2.getId());
     list.addIdsToBag(ids, "Company");
     return list;
   } finally {
     osw.close();
   }
 }
예제 #5
0
  public void setUp() throws Exception {
    super.setUp();
    osd = new ObjectStoreDummyImpl();
    osd.setResultsSize(15);

    // Set up some known objects in the first 3 results rows
    department1 = new Department();
    department1.setName("Department1");
    department1.setId(new Integer(4));
    department2 = new Department();
    department2.setName("Department2");
    department2.setId(new Integer(5));
    department3 = new Department();
    department3.setName("Department3");
    department3.setId(new Integer(6));

    company1 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    company1.setName("Company1");
    company1.setVatNumber(101);
    company1.setId(new Integer(1));
    company2 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    company2.setName("Company2");
    company2.setVatNumber(102);
    company2.setId(new Integer(2));
    company3 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    company3.setName("Company3");
    company3.setVatNumber(103);
    company3.setId(new Integer(3));

    man1 = (Manager) DynamicUtil.createObject(Collections.singleton(Manager.class));
    man1.setName("Manager1");
    man1.setSeniority(new Integer(100));
    man1.setId(new Integer(1));
    man2 = (Manager) DynamicUtil.createObject(Collections.singleton(Manager.class));
    man2.setName("Manager2");
    man2.setSeniority(new Integer(200));
    man2.setId(new Integer(2));
    man3 = (CEO) DynamicUtil.createObject(Collections.singleton(CEO.class));
    man3.setName("Manager3");
    man3.setSeniority(new Integer(300));
    man3.setId(new Integer(3));
    man3.setCompany(company3);

    ResultsRow row = new ResultsRow();
    row.add(department1);
    row.add(company1);
    row.add(man1);
    osd.addRow(row);
    row = new ResultsRow();
    row.add(department2);
    row.add(company2);
    row.add(man2);
    osd.addRow(row);
    row = new ResultsRow();
    row.add(department3);
    row.add(company3);
    row.add(man3);
    osd.addRow(row);
    classKeys = new HashMap();
    FieldDescriptor fd =
        model
            .getClassDescriptorByName("org.intermine.model.testmodel.Company")
            .getFieldDescriptorByName("name");
    ArrayList<FieldDescriptor> keys = new ArrayList();
    keys.add(fd);
    classKeys.put("Company", keys);
  }
예제 #6
0
  public void testCreateBagTable() throws Exception {
    Collection bag = new HashSet();

    bag.add(new Integer(-10000));
    bag.add(new Integer(0));
    bag.add(new Integer(10000));
    bag.add(new Long(-10000));
    bag.add(new Long(0));
    bag.add(new Long(10000));
    bag.add(new Short((short) -10000));
    bag.add(new Short((short) 0));
    bag.add(new Short((short) 10000));
    bag.add(new BigDecimal(-10000.0));
    bag.add(new BigDecimal(0.0));
    bag.add(new BigDecimal(10000.0));
    bag.add(new Float(-10000.0));
    bag.add(new Float(0.0));
    bag.add(new Float(10000.0));
    bag.add(new Double(-10000.0));
    bag.add(new Double(0.0));
    bag.add(new Double(10000.0));
    bag.add(new String());
    bag.add(new String("a String with spaces"));
    bag.add(new String("123456"));
    bag.add(new String("123456.7"));
    bag.add(new Boolean(true));
    bag.add(new Boolean(false));
    bag.add(new Date(999999));
    bag.add(new Date(100));
    Employee employee = (Employee) DynamicUtil.createObject(Collections.singleton(Employee.class));
    employee.setId(new Integer(5000));
    bag.add(employee);
    Manager manager = (Manager) DynamicUtil.createObject(Collections.singleton(Manager.class));
    manager.setId(new Integer(5001));
    bag.add(manager);
    Company company = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    company.setId(new Integer(6000));
    bag.add(company);

    // this shouldn't appear in any table
    bag.add(BigInteger.ONE);

    DatabaseUtil.createBagTable(db, con, "integer_table", bag, Integer.class);
    DatabaseUtil.createBagTable(db, con, "long_table", bag, Long.class);
    DatabaseUtil.createBagTable(db, con, "short_table", bag, Short.class);
    DatabaseUtil.createBagTable(db, con, "bigdecimal_table", bag, BigDecimal.class);
    DatabaseUtil.createBagTable(db, con, "float_table", bag, Float.class);
    DatabaseUtil.createBagTable(db, con, "double_table", bag, Double.class);
    DatabaseUtil.createBagTable(db, con, "string_table", bag, String.class);
    DatabaseUtil.createBagTable(db, con, "boolean_table", bag, Boolean.class);
    DatabaseUtil.createBagTable(db, con, "date_table", bag, Date.class);
    DatabaseUtil.createBagTable(db, con, "intermineobject_table", bag, InterMineObject.class);
    DatabaseUtil.createBagTable(db, con, "employee_table", bag, Employee.class);

    Statement s = con.createStatement();
    ResultSet r = s.executeQuery("SELECT value FROM integer_table");
    Set result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    Set expected = new HashSet();
    expected.add(new Integer(-10000));
    expected.add(new Integer(0));
    expected.add(new Integer(10000));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM long_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Long(-10000));
    expected.add(new Long(0));
    expected.add(new Long(10000));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM short_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Integer((short) -10000));
    expected.add(new Integer((short) 0));
    expected.add(new Integer((short) 10000));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM double_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Double(-10000.0));
    expected.add(new Double(0.));
    expected.add(new Double(10000.0));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM float_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Float(-10000.0));
    expected.add(new Float(0.));
    expected.add(new Float(10000.0));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM string_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new String());
    expected.add(new String("a String with spaces"));
    expected.add(new String("123456"));
    expected.add(new String("123456.7"));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM boolean_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Boolean(true));
    expected.add(new Boolean(false));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM date_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(new Long(999999));
    expected.add(new Long(100));

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM intermineobject_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(employee.getId());
    expected.add(manager.getId());
    expected.add(company.getId());

    assertEquals(expected, result);

    r = s.executeQuery("SELECT value FROM employee_table");
    result = new HashSet();
    while (r.next()) {
      result.add(r.getObject(1));
    }

    expected = new HashSet();
    expected.add(employee.getId());
    expected.add(manager.getId());

    assertEquals(expected, result);
  }