use of org.xwiki.search.solr.internal.api.SolrFieldNameEncoder in project xwiki-platform by xwiki.
the class DocumentSolrMetadataExtractorTest method setUp.
@Before
public void setUp() throws Exception {
this.mocker.registerMockComponent(SolrReferenceResolver.class, "document");
// XWikiContext Provider
Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xcontextProvider.get()).thenReturn(this.xcontext);
// XWikiContext trough Execution
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.xcontext);
Execution execution = this.mocker.registerMockComponent(Execution.class);
when(execution.getContext()).thenReturn(executionContext);
// XWiki
XWiki wiki = mock(XWiki.class);
when(this.xcontext.getWiki()).thenReturn(wiki);
// XWikiDocument
when(wiki.getDocument(this.documentReference, this.xcontext)).thenReturn(this.document);
when(this.document.getDocumentReference()).thenReturn(this.documentReference);
when(this.document.isHidden()).thenReturn(false);
when(this.document.getLocale()).thenReturn(Locale.ROOT);
when(this.document.getRealLocale()).thenReturn(Locale.US);
when(this.document.getTranslatedDocument(Locale.FRENCH, this.xcontext)).thenReturn(this.translatedDocument);
when(this.translatedDocument.getRealLocale()).thenReturn(Locale.FRENCH);
when(this.translatedDocument.getLocale()).thenReturn(Locale.FRENCH);
when(this.translatedDocument.getDocumentReference()).thenReturn(this.frenchDocumentReference);
// Field Name Serializer
EntityReferenceSerializer<String> fieldNameSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "solr");
when(fieldNameSerializer.serialize(any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
EntityReference reference = (EntityReference) invocation.getArguments()[0];
StringBuilder result = new StringBuilder();
for (EntityReference parent : reference.getReversedReferenceChain()) {
result.append('.').append(parent.getName());
}
return result.substring(1);
}
});
// Field Name Encoder
SolrFieldNameEncoder fieldNameEncoder = this.mocker.getInstance(SolrFieldNameEncoder.class);
when(fieldNameEncoder.encode(any())).then(AdditionalAnswers.returnsFirstArg());
}
Aggregations