Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-4460

Improve MockQuery

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.5
    • Fix Version/s: None
    • Component/s: testing
    • Labels:
      None

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            had Jan Haderka
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated: