use of com.day.cq.search.QueryBuilder in project acs-aem-commons by Adobe-Consulting-Services.
the class OnDeployScriptBaseTest method setup.
@Before
public void setup() throws Exception {
resourceResolver = spy(context.resourceResolver());
Session session = resourceResolver.adaptTo(Session.class);
Node nodeContent = session.getRootNode().addNode("content", "nt:resource");
nodeContent.addNode("to-delete");
Node nodeContentResType1 = nodeContent.addNode("resource-type-update1");
nodeContentResType1.setProperty("sling:resourceType", "test/component/comp1");
nodeContentResType1.setProperty("text", "hello world");
Node nodeContentResType2 = nodeContent.addNode("resource-type-update2");
nodeContentResType2.setProperty("sling:resourceType", "test/component/comp2");
nodeContent.addNode("resource-type-missing");
// Create the test class instance
onDeployScript = new OnDeployScriptBaseExt();
queryBuilder = mock(QueryBuilder.class);
doReturn(queryBuilder).when(resourceResolver).adaptTo(QueryBuilder.class);
onDeployScript.execute(resourceResolver);
// Reset the LogTester
LogTester.reset();
}
use of com.day.cq.search.QueryBuilder in project acs-aem-commons by Adobe-Consulting-Services.
the class QueryBuilderBindingsValuesProviderTest method test.
@Test
public void test() throws Exception {
QueryBuilderBindingsValuesProvider provider = new QueryBuilderBindingsValuesProvider();
QueryBuilder qb = mock(QueryBuilder.class);
PrivateAccessor.setField(provider, "queryBuilder", qb);
Bindings bindings = mock(Bindings.class);
provider.addBindings(bindings);
verify(bindings).put("queryBuilder", qb);
}
use of com.day.cq.search.QueryBuilder in project acs-aem-commons by Adobe-Consulting-Services.
the class TwitterFeedUpdaterImpl method findTwitterResources.
private List<Resource> findTwitterResources(ResourceResolver resourceResolver) {
List<Resource> twitterResources = new ArrayList<>();
Map<String, String> predicateMap = new HashMap<>();
predicateMap.put("path", "/content");
predicateMap.put("property", "sling:resourceType");
int counter = 1;
for (String path : twitterComponentPaths) {
predicateMap.put("property." + (counter++) + "_value", path);
}
predicateMap.put("p.limit", "-1");
QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
Session session = resourceResolver.adaptTo(Session.class);
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);
SearchResult result = query.getResult();
Iterator<Resource> resources = result.getResources();
while (resources.hasNext()) {
twitterResources.add(resources.next());
}
return twitterResources;
}
use of com.day.cq.search.QueryBuilder in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ModelDataSourceServletTest method verifyDataSource.
@Test
public void verifyDataSource() throws Exception {
// GIVEN
context.load().json(getClass().getResourceAsStream("test-content.json"), "/conf/foobar/settings/dam/cfm/models/yetanothercfmodel");
ResourceResolver resourceResolver = Mockito.spy(context.resourceResolver());
Resource resource = resourceResolver.getResource("/conf/foobar/settings/dam/cfm/models/yetanothercfmodel");
Resource leakingResource = Mockito.spy(resource);
QueryBuilder queryBuilder = Mockito.mock(QueryBuilder.class);
Query query = Mockito.mock(Query.class);
SearchResult searchResult = Mockito.mock(SearchResult.class);
Iterator<Resource> iterator = Mockito.mock(Iterator.class);
ResourceResolver leakingResourceResolver = Mockito.mock(ResourceResolver.class);
Mockito.doReturn(leakingResourceResolver).when(leakingResource).getResourceResolver();
Mockito.doReturn(queryBuilder).when(resourceResolver).adaptTo(Mockito.eq(QueryBuilder.class));
Mockito.when(queryBuilder.createQuery(Mockito.any(), Mockito.any())).thenReturn(query);
Mockito.when(query.getResult()).thenReturn(searchResult);
Mockito.when(searchResult.getResources()).thenReturn(iterator);
Mockito.when(iterator.hasNext()).thenReturn(true, false);
Mockito.when(iterator.next()).thenReturn(leakingResource);
SlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver, context.bundleContext());
// WHEN
modelDatasourceServlet.doGet(request, context.response());
// THEN
SimpleDataSource simpleDataSource = (SimpleDataSource) request.getAttribute(DataSource.class.getName());
assertThat(simpleDataSource.iterator().hasNext(), CoreMatchers.is(true));
ValueMap valueMap = simpleDataSource.iterator().next().getValueMap();
assertThat(valueMap.get("text"), CoreMatchers.is("YetAnotherCFModel"));
assertThat(valueMap.get("value"), CoreMatchers.is("/conf/foobar/settings/dam/cfm/models/yetanothercfmodel"));
}
use of com.day.cq.search.QueryBuilder in project acs-aem-commons by Adobe-Consulting-Services.
the class QueryBuilderViewHandler method createQuery.
@Override
protected ViewQuery createQuery(SlingHttpServletRequest slingRequest, Session session, String queryString) throws Exception {
final ResourceResolver resolver = slingRequest.getResourceResolver();
final QueryBuilder qb = resolver.adaptTo(QueryBuilder.class);
Map<String, String> map;
if (GQLToQueryBuilderConverter.convertToQueryBuilder(slingRequest)) {
map = this.convertToQueryBuilderParams(slingRequest, queryString);
log.debug("Forced QueryBuilder Parameter Map: {}", map);
} else {
map = this.getQueryBuilderParams(slingRequest, queryString);
log.debug("Converted QueryBuilder Parameter Map: {}", map);
}
final Query query = qb.createQuery(PredicateGroup.create(map), session);
return new QueryBuilderViewQuery(query);
}
Aggregations