Search in sources :

Example 6 with SearchResults

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);
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 7 with SearchResults

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());
}
Also used : WikiSearchQueryResource(org.xwiki.rest.resources.wikis.WikiSearchQueryResource) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 8 with SearchResults

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());
}
Also used : WikiSearchQueryResource(org.xwiki.rest.resources.wikis.WikiSearchQueryResource) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 9 with SearchResults

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);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 10 with SearchResults

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);
    }
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResult(org.xwiki.rest.model.jaxb.SearchResult) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) DocumentReference(org.xwiki.model.reference.DocumentReference) SpaceSearchResource(org.xwiki.rest.resources.spaces.SpaceSearchResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Aggregations

SearchResults (org.xwiki.rest.model.jaxb.SearchResults)14 GetMethod (org.apache.commons.httpclient.methods.GetMethod)10 Test (org.junit.Test)10 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)9 WikiSearchQueryResource (org.xwiki.rest.resources.wikis.WikiSearchQueryResource)5 XWikiRestException (org.xwiki.rest.XWikiRestException)4 SearchResult (org.xwiki.rest.model.jaxb.SearchResult)3 SpaceSearchResource (org.xwiki.rest.resources.spaces.SpaceSearchResource)2 WikiSearchResource (org.xwiki.rest.resources.wikis.WikiSearchResource)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 Ignore (org.junit.Ignore)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 Page (org.xwiki.rest.model.jaxb.Page)1 Wiki (org.xwiki.rest.model.jaxb.Wiki)1 PageResource (org.xwiki.rest.resources.pages.PageResource)1 WikisSearchQueryResource (org.xwiki.rest.resources.wikis.WikisSearchQueryResource)1 WikiManagerREST (org.xwiki.wiki.rest.WikiManagerREST)1