Search in sources :

Example 1 with LinkState

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

the class LinkCheckerEventListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    DocumentModelBridge doc = (DocumentModelBridge) source;
    final String reference = this.serializer.serialize(doc.getDocumentReference());
    Map<String, Map<String, LinkState>> states = this.linkStateManager.getLinkStates();
    for (Map.Entry<String, Map<String, LinkState>> entry : states.entrySet()) {
        Map<String, LinkState> state = entry.getValue();
        state.remove(reference);
        if (state.size() == 0) {
            states.remove(entry.getKey());
        }
    }
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Map(java.util.Map) LinkState(org.xwiki.rendering.transformation.linkchecker.LinkState)

Example 2 with LinkState

use of org.xwiki.rendering.transformation.linkchecker.LinkState 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

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