// 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); }
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); }