1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.search.solr.internal

File SolrIndexEventListenerTest.java

 

Code metrics

0
8
2
1
71
37
2
0.25
4
2
1

Classes

Class Line # Actions
SolrIndexEventListenerTest 44 8 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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 static org.mockito.Mockito.mock;
23    import static org.mockito.Mockito.verify;
24    import static org.mockito.Mockito.when;
25   
26    import java.util.Locale;
27   
28    import org.junit.Before;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xwiki.bridge.event.DocumentDeletedEvent;
32    import org.xwiki.model.reference.DocumentReference;
33    import org.xwiki.observation.EventListener;
34    import org.xwiki.search.solr.internal.api.SolrIndexer;
35    import org.xwiki.test.mockito.MockitoComponentMockingRule;
36   
37    import com.xpn.xwiki.doc.XWikiDocument;
38   
39    /**
40    * Unit tests for {@link SolrIndexEventListener}.
41    *
42    * @version $Id: 0e83ac6ebbc3d480f209cc6bea0a9d7eb1306000 $
43    */
 
44    public class SolrIndexEventListenerTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<EventListener> mocker = new MockitoComponentMockingRule<EventListener>(
48    SolrIndexEventListener.class);
49   
50    private SolrIndexer indexer;
51   
 
52  1 toggle @Before
53    public void setUp() throws Exception
54    {
55  1 indexer = mocker.registerMockComponent(SolrIndexer.class);
56    }
57   
 
58  1 toggle @Test
59    public void onDocumentDeleted() throws Exception
60    {
61  1 DocumentReference documentReference = new DocumentReference("aWiki", "aSpace", "aPage");
62  1 XWikiDocument document = mock(XWikiDocument.class);
63  1 when(document.getOriginalDocument()).thenReturn(document);
64  1 when(document.getDocumentReference()).thenReturn(documentReference);
65  1 when(document.getRealLocale()).thenReturn(Locale.FRENCH);
66   
67  1 mocker.getComponentUnderTest().onEvent(new DocumentDeletedEvent(), document, null);
68   
69  1 verify(indexer).delete(new DocumentReference(documentReference, Locale.FRENCH), false);
70    }
71    }