Junit Test case - Query builder API | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

 

 

Map<String, String> map = new HashMap<>();
map.put("group.p.or", "true");
map.put("group.1_property", JcrConstants.JCR_TITLE);
map.put("group.1_property.value", "true");
map.put("group.1_property.operation", "exists");
map.put("group.2_property", MyConstants.TITLE);
map.put("group.2_property.value", "true");
map.put("group.2_property.operation", "exists");
query = mock(Query.class);
QueryBuilder queryBuilder = mock(QueryBuilder.class);
SlingRepository repository = mock(SlingRepository.class);
PrivateAccessor.setField(mySearchImpl, "queryBuilder", queryBuilder);
PrivateAccessor.setField(mySearchImpl, "repository", repository);
Mockito.when(queryBuilder.createQuery(Mockito.any(PredicateGroup.class), Mockito.any(Session.class))).thenReturn(query);
}

2 replies

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
January 20, 2020

 

 

Map<String, String> map = new HashMap<>();
map.put("group.p.or", "true");
map.put("group.1_property", JcrConstants.JCR_TITLE);
map.put("group.1_property.value", "true");
map.put("group.1_property.operation", "exists");
map.put("group.2_property", MyConstants.TITLE);
map.put("group.2_property.value", "true");
map.put("group.2_property.operation", "exists");
query = mock(Query.class);
QueryBuilder queryBuilder = mock(QueryBuilder.class);
SlingRepository repository = mock(SlingRepository.class);
PrivateAccessor.setField(mySearchImpl, "queryBuilder", queryBuilder);
PrivateAccessor.setField(mySearchImpl, "repository", repository);
Mockito.when(queryBuilder.createQuery(Mockito.any(PredicateGroup.class), Mockito.any(Session.class))).thenReturn(query);
}

Arun Patidar
Level 3
January 21, 2020
Thank you Arun for your reply. May i know what is exactly the variable "mySearchImpl" about?