Search in sources :

Example 81 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultWikiMacroTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // Script setup.
    ScriptMockSetup scriptMockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
    final DocumentAccessBridge mockDocBridge = scriptMockSetup.bridge;
    this.mockWikiModel = scriptMockSetup.wikiModel;
    this.wikiMacroDocumentReference = new DocumentReference("wiki", "space", "macroPage");
    this.wikiMacroManager = getComponentManager().getInstance(WikiMacroManager.class);
    // Make sure the old XWiki Context is set up in the Execution Context since it's used in
    // DefaultWikiMacro.execute().
    this.xcontext = new HashMap<String, Object>();
    Execution execution = getComponentManager().getInstance(Execution.class);
    execution.getContext().setProperty("xwikicontext", this.xcontext);
    ScriptContextManager scm = getComponentManager().getInstance(ScriptContextManager.class);
    scm.getCurrentScriptContext().setAttribute("xcontext", this.xcontext, ScriptContext.ENGINE_SCOPE);
    getMockery().checking(new Expectations() {

        {
            allowing(mockWikiDescriptorManager).getCurrentWikiId();
            will(returnValue("wiki"));
            allowing(mockCurrentDocumentReferenceProvider).get();
            will(returnValue(new DocumentReference("wiki", "space", "document")));
            allowing(mockCurrentSpaceReferenceProvider).get();
            will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
            allowing(mockDocBridge).getCurrentUser();
            will(returnValue("dummy"));
            allowing(mockDocBridge).setCurrentUser(with(any(String.class)));
            allowing(mockDocBridge).getCurrentUserReference();
            will(returnValue(new DocumentReference("wiki", "XWiki", "dummy")));
            allowing(mockWikiMacroFactory).isAllowed(with(any(DocumentReference.class)), with(any(WikiMacroVisibility.class)));
            will(returnValue(true));
            // This is the document containing the wiki macro that will be put in the context available in the macro
            // Since we're not testing it here, it can be null.
            allowing(mockDocBridge).getDocumentInstance(wikiMacroDocumentReference);
            will(returnValue(null));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) ScriptMockSetup(org.xwiki.rendering.macro.script.ScriptMockSetup) SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ScriptContextManager(org.xwiki.script.ScriptContextManager) WikiMacroManager(org.xwiki.rendering.macro.wikibridge.WikiMacroManager) Execution(org.xwiki.context.Execution) WikiReference(org.xwiki.model.reference.WikiReference) WikiMacroVisibility(org.xwiki.rendering.macro.wikibridge.WikiMacroVisibility) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 82 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class SolrDocumentIteratorTest method iterate.

@Test
public void iterate() throws Exception {
    SolrDocumentList firstResults = new SolrDocumentList();
    firstResults.add(createSolrDocument("chess", Arrays.asList("A", "B"), "C", "", "1.3"));
    firstResults.add(createSolrDocument("chess", Arrays.asList("M"), "N", "en", "2.4"));
    QueryResponse firstResponse = mock(QueryResponse.class);
    when(firstResponse.getNextCursorMark()).thenReturn("foo");
    when(firstResponse.getResults()).thenReturn(firstResults);
    SolrDocumentList secondResults = new SolrDocumentList();
    secondResults.add(createSolrDocument("tennis", Arrays.asList("X", "Y", "Z"), "V", "fr", "1.1"));
    QueryResponse secondResponse = mock(QueryResponse.class);
    when(secondResponse.getNextCursorMark()).thenReturn("bar");
    when(secondResponse.getResults()).thenReturn(secondResults);
    when(solr.query(any(SolrQuery.class))).thenReturn(firstResponse, secondResponse, secondResponse);
    DocumentIterator<String> iterator = mocker.getComponentUnderTest();
    WikiReference rootReference = new WikiReference("wiki");
    iterator.setRootReference(rootReference);
    List<Pair<DocumentReference, String>> actualResult = new ArrayList<Pair<DocumentReference, String>>();
    while (iterator.hasNext()) {
        actualResult.add(iterator.next());
    }
    SolrReferenceResolver resolver = mocker.getInstance(SolrReferenceResolver.class);
    verify(resolver).getQuery(rootReference);
    List<Pair<DocumentReference, String>> expectedResult = new ArrayList<Pair<DocumentReference, String>>();
    DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("A", "B"), "C");
    expectedResult.add(new ImmutablePair<DocumentReference, String>(documentReference, "1.3"));
    documentReference = new DocumentReference("chess", Arrays.asList("M"), "N", Locale.ENGLISH);
    expectedResult.add(new ImmutablePair<DocumentReference, String>(documentReference, "2.4"));
    documentReference = new DocumentReference("tennis", Arrays.asList("X", "Y", "Z"), "V", Locale.FRENCH);
    expectedResult.add(new ImmutablePair<DocumentReference, String>(documentReference, "1.1"));
    assertEquals(expectedResult, actualResult);
}
Also used : SolrReferenceResolver(org.xwiki.search.solr.internal.reference.SolrReferenceResolver) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) WikiReference(org.xwiki.model.reference.WikiReference) SolrQuery(org.apache.solr.client.solrj.SolrQuery) DocumentReference(org.xwiki.model.reference.DocumentReference) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Test(org.junit.Test)

Example 83 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class SolrDocumentIteratorTest method size.

@Test
public void size() throws Exception {
    SolrDocumentList results = mock(SolrDocumentList.class);
    when(results.getNumFound()).thenReturn(12L);
    QueryResponse response = mock(QueryResponse.class);
    when(response.getResults()).thenReturn(results);
    when(solr.query(any(SolrQuery.class))).thenReturn(response);
    DocumentIterator<String> iterator = mocker.getComponentUnderTest();
    WikiReference rootReference = new WikiReference("wiki");
    iterator.setRootReference(rootReference);
    assertEquals(12, iterator.size());
    SolrReferenceResolver resolver = mocker.getInstance(SolrReferenceResolver.class);
    verify(resolver).getQuery(rootReference);
}
Also used : SolrReferenceResolver(org.xwiki.search.solr.internal.reference.SolrReferenceResolver) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) WikiReference(org.xwiki.model.reference.WikiReference) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 84 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class SolrEntityReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    WikiReference wikiReference = new WikiReference("chess");
    assertReference(wikiReference);
    assertReference(new SpaceReference("Success", new SpaceReference("To", new SpaceReference("Path", wikiReference))));
    DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("Path", "To", "Success"), "WebHome", Locale.FRENCH);
    assertReference(documentReference);
    assertReference(new AttachmentReference("image.png", documentReference));
    ObjectReference objectReference = new ObjectReference("App.Code.PlayerClass[13]", documentReference);
    assertReference(objectReference);
    assertReference(new ObjectPropertyReference("age", objectReference));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 85 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class SolrIndexScriptServiceTest method indexSingleReferenceChecksRights.

@Test
public void indexSingleReferenceChecksRights() throws Exception {
    EntityReference wikiReference = new WikiReference("someWiki");
    // Call
    this.service.index(wikiReference);
    // Assert and verify
    // Actual rights check
    verify(this.mockAuthorization).hasAccess(Right.ADMIN, this.userReference, wikiReference);
    verify(this.mockAuthorization).hasAccess(Right.PROGRAM, this.contentAuthorReference, wikiReference);
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8