[MAGNOLIA-4460] Improve MockQuery Created: 28/Jun/12  Updated: 20/Oct/20  Resolved: 20/Oct/20

Status: Closed
Project: Magnolia
Component/s: testing
Affects Version/s: 4.5
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Jan Haderka Assignee: Unassigned
Resolution: Outdated Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)

 Description   

Current mock API doesn't implement real Query, but instead advices anyone to override QueryResult if necessary. Overriding is however non trivial and requires lots of boiler plate code:

            final MockSession websiteSession = (MockSession) getCtx().getJCRSession(workspaceName);
            websiteSession.setWorkspace(new MockWorkspace(workspaceName) {
                @Override
                public QueryManager getQueryManager() {
                    return new MockQueryManager(websiteSession) {
                        @Override
                        public Query createQuery(final String statement, final String language) throws InvalidQueryException, RepositoryException {
                            return new MockQuery(websiteSession, statement, language) {
                                @Override
                                public QueryResult execute() throws InvalidQueryException, RepositoryException {
                                    return new MockQueryResult(websiteSession, statement, language) {
                                        @Override
                                        public NodeIterator getNodes() throws RepositoryException {
                                            return websiteSession.getNode("/demo-project/news-and-events/news-overview").getNodes("news*");
                                        }
                                    };
                                }
                            };
                        }
                    };
                }
            });

There should be a simpler way.


Generated at Mon Feb 12 03:56:00 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.