BagQueryRunner { public BagQueryResult searchForBag(String type, List<String> input, String extraFieldValue, boolean doWildcards) throws ClassNotFoundException, InterMineException { return search(type, input, extraFieldValue, doWildcards, false, false); } BagQueryRunner(ObjectStore os, Map<String, List<FieldDescriptor>> classKeys,
            BagQueryConfig bagQueryConfig, TemplateManager templateManager); BagQueryResult searchForBag(String type, List<String> input, String extraFieldValue,
            boolean doWildcards); BagQueryResult searchForBag(String type, List<String> input, String extraFieldValue,
            boolean doWildcards, boolean ignoreConfig); BagQueryResult search(String type, Collection<String> input, String extraFieldValue,
            boolean doWildcards, boolean caseSensitive, boolean ignoreConfig);  }
@Test public void testSearchForBagDuplicates1() throws Exception { List input = Arrays.asList(new Object[] {"EmployeeA1", "EmployeeA2", "EmployeeA1"}); BagQueryResult res = runner.searchForBag("Employee", input, null, true); Assert.assertEquals(2, res.getMatches().values().size()); Assert.assertTrue(res.getIssues().isEmpty()); Assert.assertTrue(res.getUnresolved().isEmpty()); }
@Test public void testSearchForBagDuplicates2() throws Exception { List input = Arrays.asList(new Object[] {"Mr."}); BagQueryResult res = runner.searchForBag("Manager", input, null, true); Assert.assertEquals(0, res.getMatches().size()); Map expected = new HashMap(); Map queries = new HashMap(); List ids = new ArrayList(Arrays.asList(new Object[] {eIds.get("EmployeeB1"), eIds.get("EmployeeB3")})); Map results = new HashMap(); results.put("Mr.", ids); queries.put(BagQueryHelper.DEFAULT_MESSAGE, results); expected.put(BagQueryResult.DUPLICATE, queries); Assert.assertEquals(expected, res.getIssues()); Assert.assertTrue(res.getUnresolved().isEmpty()); }
@Test public void testSearchForBagUnresolved() throws Exception { List input = Arrays.asList(new Object[] {"EmployeeA1", "rubbish"}); BagQueryResult res = runner.searchForBag("Employee", input, null, true); Assert.assertEquals(1, res.getMatches().values().size()); Assert.assertTrue(res.getIssues().isEmpty()); Assert.assertEquals(res.getUnresolved().size(), 1); }
@Test public void testSearchForBagDoubleInput1() throws Exception { List input = Arrays.asList(new Object[] {"EmployeeB1", "Mr."}); BagQueryResult res = runner.searchForBag("CEO", input, null, true); Assert.assertEquals(1, res.getMatches().size()); Assert.assertEquals(2, ((List) ((Collection) res.getMatches().values()).iterator().next()).size()); Assert.assertTrue(res.getIssues().isEmpty()); Assert.assertTrue(res.getUnresolved().isEmpty()); }
@Test public void testSearchForBagDoubleInput2() throws Exception { List input = Arrays.asList(new Object[] {"EmployeeB1", "Mr."}); BagQueryResult res = runner.searchForBag("Manager", input, null, true); Assert.assertEquals(1, res.getMatches().size()); Map expected = new HashMap(); Map queries = new HashMap(); List ids = new ArrayList(Arrays.asList(new Object[] {eIds.get("EmployeeB1"), eIds.get("EmployeeB3")})); Map results = new HashMap(); results.put("Mr.", ids); queries.put(BagQueryHelper.DEFAULT_MESSAGE, results); expected.put(BagQueryResult.DUPLICATE, queries); Assert.assertEquals(expected, res.getIssues()); Assert.assertTrue(res.getUnresolved().isEmpty()); }
@Test public void testSecondQueryIssue() throws Exception { List input = Arrays.asList(new Object[] {"1"}); BagQueryResult res = runner.searchForBag("Employee", input, null, true); Assert.assertEquals(0, res.getMatches().values().size()); Map expected = new HashMap(); Map queries = new HashMap(); List ids = new ArrayList(Arrays.asList(new Object[] {eIds.get("EmployeeA1")})); Map results = new HashMap(); results.put("1", ids); queries.put("employee end", results); expected.put(BagQueryResult.OTHER, queries); Assert.assertEquals(expected, res.getIssues()); Assert.assertTrue(res.getUnresolved().isEmpty()); }
@Test public void testObjectNotFound() throws Exception { String nonMatchingString = "non_matching_string"; List input = Arrays.asList(new Object[] {nonMatchingString}); BagQueryResult res = runner.searchForBag("Employee", input, null, true); Assert.assertEquals(0, res.getMatches().values().size()); Map<String, Object> resUnresolved = res.getUnresolved(); Assert.assertTrue(resUnresolved.size() == 1); Assert.assertTrue(resUnresolved.containsKey(nonMatchingString)); Assert.assertNull(resUnresolved.get(nonMatchingString)); }
@Test public void testObjectWrongType() throws Exception { String ceoName = "Tatjana Berkel"; List<String> input = Arrays.asList(ceoName); BagQueryResult res = runner.searchForBag("Contractor", input, null, true); Assert.assertEquals(0, res.getMatches().values().size()); Collection<String> resUnresolved = res.getUnresolvedIdentifiers(); Assert.assertEquals(1, resUnresolved.size()); Assert.assertTrue(resUnresolved.contains(ceoName)); Assert.assertEquals(ceoName, resUnresolved.iterator().next()); }
@Test public void testTypeConverted() throws Exception { String empName = "EmployeeA2"; List input = Arrays.asList(new Object[] {empName}); BagQueryResult res = runner.searchForBag("Manager", input, null, true); Assert.assertEquals(0, res.getMatches().values().size()); Map issues = res.getIssues(); Map translated = (Map) issues.get(BagQueryResult.TYPE_CONVERTED); Assert.assertEquals(1, translated.values().size()); Map resUnresolved = res.getUnresolved(); Assert.assertTrue(resUnresolved.size() == 0); }
@Test public void testTypeConvertedAndNotConverted() throws Exception { String empName1 = "EmployeeA1"; String empName2 = "EmployeeA2"; List input = Arrays.asList(new Object[] {empName1, empName2}); BagQueryResult res = runner.searchForBag("Manager", input, null, true); Assert.assertEquals(1, res.getMatches().values().size()); Assert.assertEquals(empName1, ((List) res.getMatches().values().iterator().next()).get(0)); Map issues = res.getIssues(); Map converted = (Map) issues.get(BagQueryResult.TYPE_CONVERTED); Assert.assertEquals(1, converted.values().size()); Map convertedInputToObjs = (Map) converted.values().iterator().next(); Assert.assertEquals(1, convertedInputToObjs.size()); Assert.assertEquals(empName2, convertedInputToObjs.keySet().iterator().next()); List convertedPairs = (List) convertedInputToObjs.values().iterator().next(); Assert.assertEquals(1, convertedPairs.size()); ConvertedObjectPair pair = (ConvertedObjectPair) convertedPairs.get(0); Assert.assertEquals("org.intermine.model.testmodel.Manager", pair.getNewObject().getClass().getName()); Assert.assertEquals("EmployeeA2", ((Employee) pair.getOldObject()).getName()); Assert.assertEquals("EmployeeA1", ((Manager) pair.getNewObject()).getName()); Map resUnresolved = res.getUnresolved(); Assert.assertTrue(resUnresolved.size() == 0); }
@Test public void testTypeConvertedMultipleResults() throws Exception { String managerName = "ContractorA"; List input = Arrays.asList(new Object[] {managerName}); BagQueryResult res = runner.searchForBag("Employee", input, null, true); Assert.assertEquals(0, res.getMatches().values().size()); Map issues = res.getIssues(); Map converted = (Map) issues.get(BagQueryResult.TYPE_CONVERTED); Assert.assertEquals(1, converted.size()); Map convertedObjectMap = (Map) converted.get("Employable by name found by converting from x"); Assert.assertEquals(1, convertedObjectMap.size()); List emps = (List) convertedObjectMap.get(managerName); Assert.assertEquals(6, emps.size()); }
@Test public void testGetMatchAndIssueIds() throws Exception { List<String> input = Arrays.asList("EmployeeA1", "Mr.", "gibbon"); BagQueryResult res = runner.searchForBag("Manager", input, null, true); Assert.assertEquals(1, res.getMatches().size()); Set<Integer> ids = new HashSet<Integer>(Arrays.asList(new Integer[] { eIds.get("EmployeeB1").getId(), eIds.get("EmployeeA1").getId(), eIds.get("EmployeeB3").getId()})); Assert.assertEquals(ids, res.getMatchAndIssueIds()); Assert.assertEquals(1, res.getUnresolvedIdentifiers().size()); Assert.assertEquals(Collections.singleton("gibbon"), res.getUnresolvedIdentifiers()); }
@Test public void testWildcards() throws Exception { List<String> input = Arrays.asList("EmployeeA*", "EmployeeB3"); BagQueryResult res = runner.searchForBag("Employee", input, null, true); Set<Integer> ids = new HashSet<Integer>(Arrays.asList(eIds.get("EmployeeA3").getId(), eIds.get("EmployeeA2").getId(), eIds.get("EmployeeA1").getId())); Assert.assertEquals(ids, new HashSet(res.getIssues().get(BagQueryResult.WILDCARD).get("searching key fields").get("EmployeeA*"))); }
@Test public void testSearchForBagMatchesMatchAll() throws Exception { List input = Arrays.asList(new Object[] {"EmployeeA1", "EmployeeA2"}); BagQueryResult res = runnerMatchAll.searchForBag("Employee", input, null, true); Assert.assertEquals(2, res.getMatches().values().size()); Assert.assertTrue("Should have issues", !res.getIssues().isEmpty()); Assert.assertTrue("Should have no unresolved identifiers", res.getUnresolved().isEmpty()); }