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));
}
});
}
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);
}
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);
}
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));
}
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);
}
Aggregations