Search in sources :

Example 1 with SolrFieldNameEncoder

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());
}
Also used : SolrFieldNameEncoder(org.xwiki.search.solr.internal.api.SolrFieldNameEncoder) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityReference(org.xwiki.model.reference.EntityReference) Before(org.junit.Before)

Aggregations

XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Execution (org.xwiki.context.Execution)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 EntityReference (org.xwiki.model.reference.EntityReference)1 SolrFieldNameEncoder (org.xwiki.search.solr.internal.api.SolrFieldNameEncoder)1