| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.internal.event; |
| 21 |
|
|
| 22 |
|
import org.junit.Before; |
| 23 |
|
import org.junit.Rule; |
| 24 |
|
import org.junit.Test; |
| 25 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 26 |
|
import org.xwiki.model.internal.DefaultModelConfiguration; |
| 27 |
|
import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider; |
| 28 |
|
import org.xwiki.model.internal.reference.DefaultStringDocumentReferenceResolver; |
| 29 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceResolver; |
| 30 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer; |
| 31 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
| 32 |
|
import org.xwiki.model.reference.DocumentReference; |
| 33 |
|
import org.xwiki.observation.ObservationManager; |
| 34 |
|
import org.xwiki.observation.event.Event; |
| 35 |
|
import org.xwiki.test.annotation.ComponentList; |
| 36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 37 |
|
|
| 38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 39 |
|
import com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceProvider; |
| 40 |
|
import com.xpn.xwiki.internal.model.reference.CurrentReferenceDocumentReferenceResolver; |
| 41 |
|
import com.xpn.xwiki.internal.model.reference.CurrentReferenceEntityReferenceResolver; |
| 42 |
|
import com.xpn.xwiki.objects.BaseObject; |
| 43 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 44 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
| 45 |
|
|
| 46 |
|
import static org.mockito.ArgumentMatchers.any; |
| 47 |
|
import static org.mockito.ArgumentMatchers.same; |
| 48 |
|
import static org.mockito.Mockito.verify; |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@link |
| 52 |
|
|
| 53 |
|
@version |
| 54 |
|
|
| 55 |
|
@ComponentList({ |
| 56 |
|
CurrentReferenceDocumentReferenceResolver.class, |
| 57 |
|
CurrentReferenceEntityReferenceResolver.class, |
| 58 |
|
CurrentEntityReferenceProvider.class, |
| 59 |
|
DefaultModelConfiguration.class, |
| 60 |
|
DefaultStringEntityReferenceSerializer.class, |
| 61 |
|
DefaultStringDocumentReferenceResolver.class, |
| 62 |
|
DefaultStringEntityReferenceResolver.class, |
| 63 |
|
DefaultEntityReferenceProvider.class, |
| 64 |
|
DefaultSymbolScheme.class |
| 65 |
|
}) |
| |
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 4 |
Complexity Density: 0.17 |
|
| 66 |
|
public class CommentEventGeneratorListenerTest |
| 67 |
|
{ |
| 68 |
|
public MockitoComponentMockingRule<CommentEventGeneratorListener> mocker = |
| 69 |
|
new MockitoComponentMockingRule<CommentEventGeneratorListener>(CommentEventGeneratorListener.class); |
| 70 |
|
|
| 71 |
|
@Rule |
| 72 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(mocker); |
| 73 |
|
|
| 74 |
|
private ObservationManager mockObservation; |
| 75 |
|
|
| 76 |
|
private XWikiDocument commentXClassDocument; |
| 77 |
|
|
| 78 |
|
private BaseClass commentXClass; |
| 79 |
|
|
| 80 |
|
private BaseObject commentXObject; |
| 81 |
|
|
| 82 |
|
private XWikiDocument document; |
| 83 |
|
|
| 84 |
|
private XWikiDocument documentOrigin; |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 86 |
3 |
@Before... |
| 87 |
|
public void before() throws Exception |
| 88 |
|
{ |
| 89 |
3 |
this.commentXClassDocument = new XWikiDocument(new DocumentReference("wiki", "XWiki", "XWikiComments")); |
| 90 |
3 |
this.commentXClass = this.commentXClassDocument.getXClass(); |
| 91 |
3 |
this.commentXClass.addTextAreaField("comment", "comment", 60, 20); |
| 92 |
|
|
| 93 |
3 |
this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
| 94 |
3 |
this.documentOrigin = new XWikiDocument(this.document.getDocumentReference()); |
| 95 |
3 |
this.document.setOriginalDocument(this.documentOrigin); |
| 96 |
|
|
| 97 |
3 |
this.commentXObject = new BaseObject(); |
| 98 |
3 |
this.commentXObject.setXClassReference(this.commentXClass.getDocumentReference()); |
| 99 |
|
|
| 100 |
3 |
this.mockObservation = this.mocker.getInstance(ObservationManager.class); |
| 101 |
|
} |
| 102 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 103 |
1 |
@Test... |
| 104 |
|
public void testAddComment() throws ComponentLookupException |
| 105 |
|
{ |
| 106 |
1 |
this.document.addXObject(this.commentXObject); |
| 107 |
|
|
| 108 |
1 |
final Event event = new CommentAddedEvent("wiki:space.page", "0"); |
| 109 |
|
|
| 110 |
1 |
this.mocker.getComponentUnderTest().onEvent(new XObjectAddedEvent(this.commentXObject.getReference()), this.document, |
| 111 |
|
this.oldcore.getXWikiContext()); |
| 112 |
|
|
| 113 |
|
|
| 114 |
1 |
verify(this.mockObservation) |
| 115 |
|
.notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext())); |
| 116 |
|
} |
| 117 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 118 |
1 |
@Test... |
| 119 |
|
public void testDeleteComment() throws ComponentLookupException |
| 120 |
|
{ |
| 121 |
1 |
this.documentOrigin.addXObject(this.commentXObject); |
| 122 |
|
|
| 123 |
1 |
final Event event = new CommentDeletedEvent("wiki:space.page", "0"); |
| 124 |
|
|
| 125 |
1 |
this.mocker.getComponentUnderTest().onEvent(new XObjectDeletedEvent(this.commentXObject.getReference()), |
| 126 |
|
this.document, this.oldcore.getXWikiContext()); |
| 127 |
|
|
| 128 |
|
|
| 129 |
1 |
verify(this.mockObservation) |
| 130 |
|
.notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext())); |
| 131 |
|
} |
| 132 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 133 |
1 |
@Test... |
| 134 |
|
public void testModifiedComment() throws ComponentLookupException |
| 135 |
|
{ |
| 136 |
1 |
this.document.addXObject(this.commentXObject); |
| 137 |
1 |
this.documentOrigin.addXObject(this.commentXObject.clone()); |
| 138 |
|
|
| 139 |
1 |
this.commentXObject.setStringValue("comment", "comment"); |
| 140 |
|
|
| 141 |
1 |
final Event event = new CommentUpdatedEvent("wiki:space.page", "0"); |
| 142 |
|
|
| 143 |
1 |
this.mocker.getComponentUnderTest().onEvent(new XObjectUpdatedEvent(this.commentXObject.getReference()), |
| 144 |
|
this.document, this.oldcore.getXWikiContext()); |
| 145 |
|
|
| 146 |
|
|
| 147 |
1 |
verify(this.mockObservation) |
| 148 |
|
.notify(any(event.getClass()), same(document), same(this.oldcore.getXWikiContext())); |
| 149 |
|
} |
| 150 |
|
} |