1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.search.solr.internal

File SolrIndexEventListenerTest.java

 

Code metrics

0
25
4
1
110
68
4
0.16
6.25
4
1

Classes

Class Line # Actions
SolrIndexEventListenerTest 50 25 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.search.solr.internal;
21   
22    import java.util.Arrays;
23    import java.util.Locale;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.bridge.event.DocumentDeletedEvent;
29    import org.xwiki.bridge.event.DocumentUpdatedEvent;
30    import org.xwiki.model.reference.DocumentReference;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.observation.EventListener;
33    import org.xwiki.search.solr.internal.api.SolrIndexer;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import com.xpn.xwiki.XWikiContext;
37    import com.xpn.xwiki.doc.XWikiDocument;
38   
39    import static org.mockito.ArgumentMatchers.any;
40    import static org.mockito.Mockito.mock;
41    import static org.mockito.Mockito.times;
42    import static org.mockito.Mockito.verify;
43    import static org.mockito.Mockito.when;
44   
45    /**
46    * Unit tests for {@link SolrIndexEventListener}.
47    *
48    * @version $Id: 9b27d89d8e73c85bba90a867ff10d5f555c75b3e $
49    */
 
50    public class SolrIndexEventListenerTest
51    {
52    @Rule
53    public MockitoComponentMockingRule<EventListener> mocker =
54    new MockitoComponentMockingRule<EventListener>(SolrIndexEventListener.class);
55   
56    private SolrIndexer indexer;
57   
 
58  3 toggle @Before
59    public void setUp() throws Exception
60    {
61  3 indexer = mocker.registerMockComponent(SolrIndexer.class);
62    }
63   
 
64  1 toggle @Test
65    public void onDocumentDeleted() throws Exception
66    {
67  1 DocumentReference documentReference = new DocumentReference("aWiki", "aSpace", "aPage");
68  1 XWikiDocument document = mock(XWikiDocument.class);
69  1 when(document.getOriginalDocument()).thenReturn(document);
70  1 when(document.getDocumentReference()).thenReturn(documentReference);
71  1 when(document.getRealLocale()).thenReturn(Locale.FRENCH);
72   
73  1 mocker.getComponentUnderTest().onEvent(new DocumentDeletedEvent(), document, null);
74   
75  1 verify(indexer).delete(new DocumentReference(documentReference, Locale.FRENCH), false);
76    }
77   
 
78  1 toggle @Test
79    public void onDocumentTranslationUpdated() throws Exception
80    {
81  1 XWikiDocument translation = mock(XWikiDocument.class);
82  1 DocumentReference translationReference = new DocumentReference("wiki", "Path", "Page", Locale.FRENCH);
83  1 when(translation.getDocumentReferenceWithLocale()).thenReturn(translationReference);
84   
85  1 this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), translation, null);
86   
87  1 verify(this.indexer).index(translationReference, false);
88  1 verify(this.indexer, times(1)).index(any(EntityReference.class), any(Boolean.class));
89    }
90   
 
91  1 toggle @Test
92    public void onDocumentDefaultTranslationUpdated() throws Exception
93    {
94  1 XWikiContext xcontext = mock(XWikiContext.class);
95   
96  1 XWikiDocument document = mock(XWikiDocument.class);
97  1 when(document.getLocale()).thenReturn(Locale.ROOT);
98  1 when(document.getTranslationLocales(xcontext)).thenReturn(Arrays.asList(Locale.FRENCH, Locale.GERMAN));
99   
100  1 DocumentReference documentReference = new DocumentReference("wiki", "Path", "Page");
101  1 when(document.getDocumentReference()).thenReturn(documentReference);
102   
103  1 this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), document, xcontext);
104   
105  1 verify(this.indexer, times(3)).index(any(EntityReference.class), any(Boolean.class));
106  1 verify(this.indexer).index(documentReference, false);
107  1 verify(this.indexer).index(new DocumentReference(documentReference, Locale.FRENCH), false);
108  1 verify(this.indexer).index(new DocumentReference(documentReference, Locale.GERMAN), false);
109    }
110    }