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

File LinkCheckerEventListenerTest.java

 

Code metrics

0
24
3
1
89
55
3
0.12
8
3
1

Classes

Class Line # Actions
LinkCheckerEventListenerTest 46 24 0% 3 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.linkchecker.internal;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.jmock.Expectations;
26    import org.junit.Assert;
27    import org.junit.Before;
28    import org.junit.Test;
29    import org.xwiki.bridge.DocumentModelBridge;
30    import org.xwiki.bridge.event.DocumentUpdatingEvent;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.EntityReferenceSerializer;
33    import org.xwiki.observation.EventListener;
34    import org.xwiki.rendering.transformation.linkchecker.LinkState;
35    import org.xwiki.rendering.transformation.linkchecker.LinkStateManager;
36    import org.xwiki.test.jmock.AbstractMockingComponentTestCase;
37    import org.xwiki.test.jmock.annotation.MockingRequirement;
38   
39    /**
40    * Unit tests for {@link LinkCheckerEventListener}.
41    *
42    * @version $Id: 65915a33b6a79e49f43ca1a8bbe215e22f8a49f0 $
43    * @since 3.3M1
44    */
45    @MockingRequirement(LinkCheckerEventListener.class)
 
46    public class LinkCheckerEventListenerTest extends AbstractMockingComponentTestCase
47    {
48    private EventListener listener;
49   
 
50  1 toggle @Before
51    public void configure() throws Exception
52    {
53  1 this.listener = getComponentManager().getInstance(EventListener.class, "linkchecker");
54    }
55   
 
56  1 toggle @Test
57    public void testOnEvent() throws Exception
58    {
59  1 final DocumentModelBridge documentModelBridge = getMockery().mock(DocumentModelBridge.class);
60  1 final EntityReferenceSerializer serializer = getComponentManager().getInstance(
61    EntityReferenceSerializer.TYPE_STRING);
62  1 final DocumentReference reference = new DocumentReference("wiki", "space", "page");
63  1 final LinkStateManager linkStateManager = getComponentManager().getInstance(LinkStateManager.class);
64   
65  1 final Map<String, Map<String, LinkState>> states = new HashMap<String, Map<String, LinkState>>();
66  1 Map<String, LinkState> referenceStates1 = new HashMap<String, LinkState>();
67  1 referenceStates1.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis()));
68  1 referenceStates1.put("wiki2:space2.page2", new LinkState(200, System.currentTimeMillis()));
69  1 states.put("url1", referenceStates1);
70  1 Map<String, LinkState> referenceStates2 = new HashMap<String, LinkState>();
71  1 referenceStates2.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis()));
72  1 states.put("url2", referenceStates2);
73   
 
74  1 toggle getMockery().checking(new Expectations() {{
75  1 oneOf(documentModelBridge).getDocumentReference();
76  1 will(returnValue(reference));
77  1 oneOf(serializer).serialize(reference);
78  1 will(returnValue("wiki1:space1.page1"));
79  1 oneOf(linkStateManager).getLinkStates();
80  1 will(returnValue(states));
81    }});
82   
83  1 this.listener.onEvent(new DocumentUpdatingEvent(), documentModelBridge, null);
84   
85  1 Assert.assertEquals(1, states.size());
86  1 Assert.assertEquals(1, states.get("url1").size());
87  1 Assert.assertNull(states.get("url2"));
88    }
89    }