private void updateView (Map<String, String> renamedClasses, Map<String, String> renamedFields) throws PathException { for (String viewPath : pathQuery.getView()) { viewPath = getPathUpdated(viewPath, renamedClasses, renamedFields); newPathQuery.addView(viewPath); } }
private void updateView (Map<String, String> renamedClasses, Map<String, String> renamedFields) throws PathException { for (String viewPath : pathQuery.getView()) { viewPath = getPathUpdated(viewPath, renamedClasses, renamedFields); newPathQuery.addView(viewPath); } }
public void testCreatePathQueryView() { PathQuery pathQuery = new PathQuery(os.getModel()); pathQuery.addView("Employee.name"); pathQuery.addView("Employee.age"); pathQuery.addView("Employee.fullTime"); pathQuery.addView("Employee.department.name"); assertEquals(pathQuery, widget.createPathQueryView(os, webConfig.getWidgets().get(("age_groups")))); }
public void testCreatePathQueryView() { PathQuery pathQuery = new PathQuery(os.getModel()); pathQuery.addView("Employee.name"); pathQuery.addView("Employee.age"); pathQuery.addView("Employee.department.name"); assertEquals(pathQuery, widget.createPathQueryView(os, webConfig.getWidgets().get(("contractor_enrichment")))); } }
public void testCandidateLoopsOneViewNoOuterJoins() throws Exception { Model model = Model.getInstanceByName("testmodel"); PathQuery q = new PathQuery(model); q.addView("Employee.age"); assertEquals("A rooted query will report candidate loops", new HashSet<String>(Arrays.asList("Employee", "Employee.department.employees")), q.getCandidateLoops("Employee.department.employees.department.employees")); }
public void testGetPathQuery() { PathQuery q = new PathQuery(os.getModel()); q.addView("Employee.name"); q.addView("Employee.age"); q.addView("Employee.department.name"); // bag constraint q.addConstraint(Constraints.in(config.getStartClass(), bag.getName())); assertEquals(q, widget.getPathQuery()); }
private PathQuery getQuery1(Model model) { PathQuery q = new PathQuery(model); q.addView("Employee.name"); q.addConstraint(new PathConstraintAttribute("Employee.age", ConstraintOp.LESS_THAN, "50")); return q; }
public void testGetPathQuery() { PathQuery q = new PathQuery(os.getModel()); q.addView("Employee.name"); q.addView("Employee.age"); q.addView("Employee.fullTime"); q.addView("Employee.department.name"); // bag constraint q.addConstraint(Constraints.in(config.getStartClass(), bag.getName())); q.addConstraint(Constraints.eq("Employee.age", "%category")); q.addConstraint(Constraints.neq("Employee.age", "40")); PathQuery widgetPathQuery = widget.getPathQuery(); assertEquals(q, widgetPathQuery); }
private int runQuery(ConstraintOp op, Collection<String> types) throws ObjectStoreException { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Employable.name"); pq.addConstraint(new PathConstraintMultitype("Employable", op, types)); Query q = MainHelper.makeQuery( pq, new HashMap(), new HashMap(), null, new HashMap()); Results res = osw.execute(q, 50000, true, false, true); return res.size(); }
public void testGetPathQueryForMatches() { Model model = os.getModel(); PathQuery pathQuery = new PathQuery(model); pathQuery.addView("Employee.department.company.contractors.name"); pathQuery.addView("Employee.name"); pathQuery.addOrderBy("Employee.department.company.contractors.name", OrderDirection.ASC); pathQuery.addConstraint(Constraints.in(config.getStartClass(), bag.getName())); assertEquals(pathQuery, widget.getPathQueryForMatches()); }
@Test public void isntOnRef() throws ObjectStoreException { Collection<String> types = Arrays.asList("CEO", "Contractor"); PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.employees.name"); pq.addConstraint(Constraints.eq("Department.name", tempDepartment.getName())); PathQuery all = pq.clone(); pq.addConstraint(new PathConstraintMultitype("Department.employees", ConstraintOp.ISNT, Arrays.asList("Manager", "CEO"))); Query q = MainHelper.makeQuery( pq, new HashMap(), new HashMap(), null, new HashMap()); Query qall = MainHelper.makeQuery( all, new HashMap(), new HashMap(), null, new HashMap()); Results res = osw.execute(q, 50000, true, false, true); Results resall = osw.execute(qall, 50000, true, false, true); assertEquals(res.size(), resall.size() - (types.size() * SET_SIZE)); } }
public void testSubclassConstraint() throws Exception { Model model = Model.getInstanceByName("testmodel"); PathQuery q = new PathQuery(model); q.addView("Department.name"); q.addView("Department.employees.name"); q.addView("Department.employees.title"); assertNull(q.addConstraint(new PathConstraintSubclass("Department.employees", "Manager"))); assertEquals(Collections.EMPTY_LIST, q.verifyQuery()); assertEquals("<query name=\"test\" model=\"testmodel\" view=\"Department.name Department.employees.name Department.employees.title\" longDescription=\"\"><constraint path=\"Department.employees\" type=\"Manager\"/></query>", PathQueryBinding.marshal(q, "test", "testmodel", 1)); q.clearConstraints(); try { q.addConstraint(new PathConstraintSubclass("Department.employees", "Manager"), "A"); fail("Expected exception"); } catch (IllegalArgumentException e) { assertEquals("Cannot associate a code with a subclass constraint. Use the addConstraint(PathConstraint) method instead", e.getMessage()); } }
private PathQuery getQuery2(Model model) { PathQuery q = new PathQuery(model); q.addView("Employee.name"); q.addView("Employee.department.name"); q.addOrderBy("Employee.age", OrderDirection.ASC); q.addConstraint(new PathConstraintAttribute("Employee.age", ConstraintOp.LESS_THAN, "50")); q.addConstraint(new PathConstraintAttribute("Employee.department.name", ConstraintOp.EQUALS, "Fred")); q.setConstraintLogic("A or B"); q.setOuterJoinStatus("Employee.department", OuterJoinStatus.INNER); q.setDescription("Flibble"); q.setDescription("Employee.name", "Albert"); return q; }
public void testRemoveSubclass() throws Exception { Model model = Model.getInstanceByName("testmodel"); PathQuery q = PathQueryBinding.unmarshalPathQuery(new StringReader("<query name=\"\" model=\"testmodel\" view=\"Department.name Department.employees.name Department.employees.company.name Department.employees.title Department.employees.company.departments.name\" sortOrder=\"Department.employees.company.name asc Department.name asc\" constraintLogic=\"A and B and C and D\"><join path=\"Department.employees.address\" style=\"INNER\"/><join path=\"Department.employees\" style=\"INNER\"/><join path=\"Department.employees.company\" style=\"INNER\"/><pathDescription pathString=\"Department\" description=\"wurble\"/><pathDescription pathString=\"Department.employees.company\" description=\"flibble\"/><constraint path=\"Department.employees.address.address\" code=\"A\" op=\"=\" value=\"sdfsg\"/><constraint path=\"Department.employees\" type=\"CEO\"/><constraint path=\"Department.employees.company.vatNumber\" code=\"B\" op=\"=\" value=\"435\"/><constraint path=\"Department\" code=\"C\" op=\"=\" loopPath=\"Department.employees.company.departments\"/><constraint path=\"Department\" code=\"D\" op=\"=\" loopPath=\"Department.company.departments\"/></query>"), 1); List<String> messages = Arrays.asList("Removed path Department.employees.company.name from view, because you removed the subclass constraint that it depended on.", "Removed path Department.employees.title from view, because you removed the subclass constraint that it depended on.", "Removed path Department.employees.company.departments.name from view, because you removed the subclass constraint that it depended on.", "Removed constraint Department.employees.company.vatNumber = 435 because you removed the subclass constraint it depended on.", "Removed constraint Department = Department.employees.company.departments because you removed the subclass constraint it depended on.", "Removed path Department.employees.company.name from ORDER BY, because you removed the subclass constraint it depended on.", "Removed description on path Department.employees.company, because you removed the subclass constraint it depended on."); assertEquals(messages, q.removeSubclassAndFixUp("Department.employees")); assertEquals("<query name=\"\" model=\"testmodel\" view=\"Department.name Department.employees.name\" longDescription=\"\" sortOrder=\"Department.name asc\" constraintLogic=\"A and D\"><join path=\"Department.employees.address\" style=\"INNER\"/><join path=\"Department.employees\" style=\"INNER\"/><pathDescription pathString=\"Department\" description=\"wurble\"/><constraint path=\"Department.employees.address.address\" code=\"A\" op=\"=\" value=\"sdfsg\"/><constraint path=\"Department\" code=\"D\" op=\"=\" loopPath=\"Department.company.departments\"/></query>", PathQueryBinding.marshal(q, "", "testmodel", 1)); assertEquals(Collections.emptyList(), q.removeSubclassAndFixUp("Department.employees")); assertEquals("<query name=\"\" model=\"testmodel\" view=\"Department.name Department.employees.name\" longDescription=\"\" sortOrder=\"Department.name asc\" constraintLogic=\"A and D\"><join path=\"Department.employees.address\" style=\"INNER\"/><join path=\"Department.employees\" style=\"INNER\"/><pathDescription pathString=\"Department\" description=\"wurble\"/><constraint path=\"Department.employees.address.address\" code=\"A\" op=\"=\" value=\"sdfsg\"/><constraint path=\"Department\" code=\"D\" op=\"=\" loopPath=\"Department.company.departments\"/></query>", PathQueryBinding.marshal(q, "", "testmodel", 1)); q = new PathQuery(model); q.addView("asdkfgh"); try { q.removeSubclassAndFixUp("Department.employees"); fail("Expected exception"); } catch (PathException e) { } }
@Test public void testPQSanity() { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.name"); pq.addConstraint(Constraints.eq("Department.name", "temp-*")); Query q = makeQuery(pq); doSanityTest(q); }
@Test public void nullPathQueryCollections() { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.name"); pq.addConstraint(Constraints.eq("Department.name", "temp-*")); pq.addConstraint(Constraints.isNull("Department.employees")); Query q = makeQuery(pq); System.out.println(q.toString()); doNullCollectionTests(q); }
@Test public void nullPathQueryCollectionsSynonyms() { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.name"); pq.addConstraint(Constraints.eq("Department.name", "temp-*")); pq.addConstraint(new PathConstraintNull("Department.employees", ConstraintOp.IS_EMPTY)); Query q = makeQuery(pq); System.out.println(q.toString()); doNullCollectionTests(q); }
@Test public void nonNullPathQueryCollections() { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.name"); pq.addConstraint(Constraints.eq("Department.name", "temp-*")); pq.addConstraint(Constraints.isNotNull("Department.employees")); Query q = makeQuery(pq); System.out.println(q.toString()); doNonNullCollectionTests(q); }
@Test public void pathQueryNullRefs() { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.name"); pq.addConstraint(Constraints.eq("Department.name", "temp-*")); pq.addConstraint(Constraints.isNull("Department.company")); Query q = makeQuery(pq); doNullRefTests(q); }
@Test public void pathQueryNonNullRefs() { PathQuery pq = new PathQuery(osw.getModel()); pq.addView("Department.name"); pq.addConstraint(Constraints.eq("Department.name", "temp-*")); pq.addConstraint(Constraints.isNotNull("Department.company")); Query q = makeQuery(pq); doNonNullRefTests(q); }