Search in sources :

Example 1 with LinkStateManager

use of org.xwiki.rendering.transformation.linkchecker.LinkStateManager in project xwiki-platform by xwiki.

the class LinkCheckerEventListenerTest method testOnEvent.

@Test
public void testOnEvent() throws Exception {
    final DocumentModelBridge documentModelBridge = getMockery().mock(DocumentModelBridge.class);
    final EntityReferenceSerializer serializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
    final DocumentReference reference = new DocumentReference("wiki", "space", "page");
    final LinkStateManager linkStateManager = getComponentManager().getInstance(LinkStateManager.class);
    final Map<String, Map<String, LinkState>> states = new HashMap<String, Map<String, LinkState>>();
    Map<String, LinkState> referenceStates1 = new HashMap<String, LinkState>();
    referenceStates1.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis()));
    referenceStates1.put("wiki2:space2.page2", new LinkState(200, System.currentTimeMillis()));
    states.put("url1", referenceStates1);
    Map<String, LinkState> referenceStates2 = new HashMap<String, LinkState>();
    referenceStates2.put("wiki1:space1.page1", new LinkState(200, System.currentTimeMillis()));
    states.put("url2", referenceStates2);
    getMockery().checking(new Expectations() {

        {
            oneOf(documentModelBridge).getDocumentReference();
            will(returnValue(reference));
            oneOf(serializer).serialize(reference);
            will(returnValue("wiki1:space1.page1"));
            oneOf(linkStateManager).getLinkStates();
            will(returnValue(states));
        }
    });
    this.listener.onEvent(new DocumentUpdatingEvent(), documentModelBridge, null);
    Assert.assertEquals(1, states.size());
    Assert.assertEquals(1, states.get("url1").size());
    Assert.assertNull(states.get("url2"));
}
Also used : EntityReferenceSerializer(org.xwiki.model.reference.EntityReferenceSerializer) Expectations(org.jmock.Expectations) DocumentUpdatingEvent(org.xwiki.bridge.event.DocumentUpdatingEvent) LinkStateManager(org.xwiki.rendering.transformation.linkchecker.LinkStateManager) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) LinkState(org.xwiki.rendering.transformation.linkchecker.LinkState) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)1 DocumentUpdatingEvent (org.xwiki.bridge.event.DocumentUpdatingEvent)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReferenceSerializer (org.xwiki.model.reference.EntityReferenceSerializer)1 LinkState (org.xwiki.rendering.transformation.linkchecker.LinkState)1 LinkStateManager (org.xwiki.rendering.transformation.linkchecker.LinkStateManager)1