use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testObjectSearchNotAuthenticated.
@Test
public void testObjectSearchNotAuthenticated() throws Exception {
/* Check search for an object containing XWiki.Admin (i.e., the admin profile) */
GetMethod getMethod = executeGet(String.format("%s?q=XWiki.Admin&scope=objects", buildURI(WikiSearchResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int resultSize = searchResults.getSearchResults().size();
Assert.assertTrue(String.format("Found %s results", resultSize), resultSize == 0);
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testHQLQuerySearch.
@Test
public void testHQLQuerySearch() throws Exception {
this.testUtils.rest().delete(this.reference);
this.testUtils.rest().savePage(this.reference);
GetMethod getMethod = executeGet(URIUtil.encodeQuery(String.format("%s?q=where doc.name='" + this.pageName + "' order by doc.space desc&type=hql", buildURI(WikiSearchQueryResource.class, getWiki()))));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
Assert.assertEquals(this.fullName, searchResults.getSearchResults().get(0).getPageFullName());
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testHQLQuerySearchWithClassnameAuthenticated.
@Test
public void testHQLQuerySearchWithClassnameAuthenticated() throws Exception {
GetMethod getMethod = executeGet(URIUtil.encodeQuery(String.format("%s?q=where doc.space='XWiki' and doc.name='XWikiPreferences'&type=hql&className=XWiki.XWikiGlobalRights", buildURI(WikiSearchQueryResource.class, getWiki()))), TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
assertNotNull(searchResults.getSearchResults().get(0).getObject());
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisSearchQueryResourceImpl method search.
@Override
public SearchResults search(String query, Integer number, Integer start, Boolean distinct, String searchWikis, String orderField, String order, Boolean withPrettyNames, String className) throws XWikiRestException {
try {
SearchResults searchResults = objectFactory.createSearchResults();
searchResults.setTemplate(String.format("%s?%s", uriInfo.getBaseUri().toString(), MULTIWIKI_QUERY_TEMPLATE_INFO));
searchResults.getSearchResults().addAll(this.solrSearch.search(query, getXWikiContext().getWikiId(), searchWikis, Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), orderField, order, distinct, number, start, withPrettyNames, className, uriInfo));
return searchResults;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class SpacesResourceTest method testSearch.
@Test
public void testSearch() throws Exception {
DocumentReference reference = new DocumentReference(getWiki(), getTestClassName(), getTestMethodName());
this.testUtils.rest().delete(reference);
this.testUtils.rest().savePage(reference, "content " + getTestMethodName(), "title " + getTestMethodName());
GetMethod getMethod = executeGet(String.format("%s?q=somethingthatcannotpossiblyexist", buildURI(SpaceSearchResource.class, getWiki(), Arrays.asList(getTestClassName()))));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(0, searchResults.getSearchResults().size());
getMethod = executeGet(String.format("%s?q=%s", buildURI(SpaceSearchResource.class, getWiki(), Arrays.asList(getTestClassName())), getTestMethodName()));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int resultSize = searchResults.getSearchResults().size();
Assert.assertTrue("Found " + resultSize + " result", resultSize == 1);
for (SearchResult searchResult : searchResults.getSearchResults()) {
checkLinks(searchResult);
}
}
Aggregations