| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.watchlist.internal; |
| 21 |
|
|
| 22 |
|
import org.junit.Before; |
| 23 |
|
import org.junit.Rule; |
| 24 |
|
import org.junit.Test; |
| 25 |
|
import org.xwiki.bridge.event.DocumentCreatedEvent; |
| 26 |
|
import org.xwiki.bridge.event.WikiCreatingEvent; |
| 27 |
|
import org.xwiki.context.Execution; |
| 28 |
|
import org.xwiki.context.ExecutionContext; |
| 29 |
|
import org.xwiki.context.internal.DefaultExecution; |
| 30 |
|
import org.xwiki.model.reference.DocumentReference; |
| 31 |
|
import org.xwiki.observation.EventListener; |
| 32 |
|
import org.xwiki.observation.internal.DefaultObservationContext; |
| 33 |
|
import org.xwiki.observation.internal.ObservationContextListener; |
| 34 |
|
import org.xwiki.test.annotation.ComponentList; |
| 35 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 36 |
|
import org.xwiki.watchlist.internal.api.AutomaticWatchMode; |
| 37 |
|
import org.xwiki.watchlist.internal.api.WatchListStore; |
| 38 |
|
import org.xwiki.watchlist.internal.api.WatchedElementType; |
| 39 |
|
|
| 40 |
|
import com.xpn.xwiki.XWiki; |
| 41 |
|
import com.xpn.xwiki.XWikiContext; |
| 42 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 43 |
|
import com.xpn.xwiki.internal.event.XARImportingEvent; |
| 44 |
|
|
| 45 |
|
import static org.mockito.ArgumentMatchers.any; |
| 46 |
|
import static org.mockito.Mockito.mock; |
| 47 |
|
import static org.mockito.Mockito.never; |
| 48 |
|
import static org.mockito.Mockito.verify; |
| 49 |
|
import static org.mockito.Mockito.when; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@link |
| 53 |
|
|
| 54 |
|
@version |
| 55 |
|
|
| 56 |
|
@ComponentList({ObservationContextListener.class, DefaultExecution.class, DefaultObservationContext.class}) |
| |
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 4 |
Complexity Density: 0.17 |
|
| 57 |
|
public class AutomaticWatchModeListenerTest |
| 58 |
|
{ |
| 59 |
|
private WatchListStore mockStore; |
| 60 |
|
|
| 61 |
|
private EventListener observationContextListener; |
| 62 |
|
|
| 63 |
|
@Rule |
| 64 |
|
public final MockitoComponentMockingRule<EventListener> mocker = new MockitoComponentMockingRule<EventListener>( |
| 65 |
|
AutomaticWatchModeListener.class); |
| 66 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 67 |
3 |
@Before... |
| 68 |
|
public void setUp() throws Exception |
| 69 |
|
{ |
| 70 |
3 |
this.mockStore = mocker.getInstance(WatchListStore.class); |
| 71 |
|
|
| 72 |
|
|
| 73 |
3 |
Execution execution = mocker.getInstance(Execution.class); |
| 74 |
3 |
execution.setContext(new ExecutionContext()); |
| 75 |
|
|
| 76 |
3 |
this.observationContextListener = mocker.getInstance(EventListener.class, "ObservationContextListener"); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 82 |
1 |
@Test... |
| 83 |
|
public void onEventWhenInContextOfWikiCreatingEvent() throws Exception |
| 84 |
|
{ |
| 85 |
|
|
| 86 |
1 |
this.observationContextListener.onEvent(new WikiCreatingEvent(), null, null); |
| 87 |
|
|
| 88 |
1 |
mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), null, null); |
| 89 |
|
|
| 90 |
1 |
verify(mockStore, never()).getAutomaticWatchMode(any()); |
| 91 |
1 |
verify(mockStore, never()).addWatchedElement(any(), any(), any(WatchedElementType.class)); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 97 |
1 |
@Test... |
| 98 |
|
public void onEventWhenInContextOXARImportingEvent() throws Exception |
| 99 |
|
{ |
| 100 |
|
|
| 101 |
1 |
this.observationContextListener.onEvent(new XARImportingEvent(), null, null); |
| 102 |
|
|
| 103 |
1 |
mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), null, null); |
| 104 |
|
|
| 105 |
1 |
verify(mockStore, never()).getAutomaticWatchMode(any()); |
| 106 |
1 |
verify(mockStore, never()).addWatchedElement(any(), any(), any(WatchedElementType.class)); |
| 107 |
|
} |
| 108 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 109 |
1 |
@Test... |
| 110 |
|
public void onEventWhenDocumentCreatedEvent() throws Exception |
| 111 |
|
{ |
| 112 |
1 |
XWikiContext context = mock(XWikiContext.class); |
| 113 |
|
|
| 114 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
| 115 |
1 |
DocumentReference documentReference = new DocumentReference("authorWiki", "authorSpace", "authorPage"); |
| 116 |
1 |
when(document.getContentAuthor()).thenReturn("content author"); |
| 117 |
1 |
when(document.getContentAuthorReference()).thenReturn(documentReference); |
| 118 |
1 |
when(document.getPrefixedFullName()).thenReturn("authorSpace.authorPage"); |
| 119 |
|
|
| 120 |
1 |
when(this.mockStore.getAutomaticWatchMode("content author")).thenReturn(AutomaticWatchMode.ALL); |
| 121 |
|
|
| 122 |
1 |
XWiki xwiki = mock(XWiki.class); |
| 123 |
1 |
when(xwiki.exists(documentReference, context)).thenReturn(true); |
| 124 |
|
|
| 125 |
1 |
when(context.getWiki()).thenReturn(xwiki); |
| 126 |
|
|
| 127 |
1 |
mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(), document, context); |
| 128 |
|
|
| 129 |
|
|
| 130 |
1 |
verify(this.mockStore).addWatchedElement("content author", "authorSpace.authorPage", |
| 131 |
|
org.xwiki.watchlist.internal.api.WatchedElementType.DOCUMENT); |
| 132 |
|
} |
| 133 |
|
} |