| 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.bridge.event.DocumentCreatedEvent; |
| 26 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
| 27 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
| 28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 29 |
|
import org.xwiki.model.internal.DefaultModelConfiguration; |
| 30 |
|
import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider; |
| 31 |
|
import org.xwiki.model.internal.reference.DefaultStringDocumentReferenceResolver; |
| 32 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceResolver; |
| 33 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer; |
| 34 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
| 35 |
|
import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer; |
| 36 |
|
import org.xwiki.model.reference.DocumentReference; |
| 37 |
|
import org.xwiki.observation.ObservationManager; |
| 38 |
|
import org.xwiki.observation.event.Event; |
| 39 |
|
import org.xwiki.test.annotation.ComponentList; |
| 40 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 41 |
|
|
| 42 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 43 |
|
import com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceProvider; |
| 44 |
|
import com.xpn.xwiki.internal.model.reference.CurrentReferenceDocumentReferenceResolver; |
| 45 |
|
import com.xpn.xwiki.internal.model.reference.CurrentReferenceEntityReferenceResolver; |
| 46 |
|
import com.xpn.xwiki.internal.model.reference.CurrentStringDocumentReferenceResolver; |
| 47 |
|
import com.xpn.xwiki.internal.model.reference.CurrentStringEntityReferenceResolver; |
| 48 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
| 49 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
| 50 |
|
|
| 51 |
|
import static org.mockito.ArgumentMatchers.eq; |
| 52 |
|
import static org.mockito.ArgumentMatchers.same; |
| 53 |
|
import static org.mockito.Mockito.verify; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@link |
| 57 |
|
|
| 58 |
|
@version |
| 59 |
|
|
| 60 |
|
@ComponentList({ |
| 61 |
|
CurrentReferenceDocumentReferenceResolver.class, |
| 62 |
|
CurrentReferenceEntityReferenceResolver.class, |
| 63 |
|
CurrentEntityReferenceProvider.class, |
| 64 |
|
DefaultModelConfiguration.class, |
| 65 |
|
DefaultStringEntityReferenceSerializer.class, |
| 66 |
|
DefaultStringDocumentReferenceResolver.class, |
| 67 |
|
DefaultStringEntityReferenceResolver.class, |
| 68 |
|
DefaultEntityReferenceProvider.class, |
| 69 |
|
CurrentStringDocumentReferenceResolver.class, |
| 70 |
|
CurrentStringEntityReferenceResolver.class, |
| 71 |
|
LocalStringEntityReferenceSerializer.class, |
| 72 |
|
DefaultSymbolScheme.class |
| 73 |
|
}) |
| |
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 6 |
Complexity Density: 0.22 |
|
| 74 |
|
public class XClassPropertyEventGeneratorListenerTest |
| 75 |
|
{ |
| 76 |
|
public MockitoComponentMockingRule<XClassPropertyEventGeneratorListener> mocker = |
| 77 |
|
new MockitoComponentMockingRule<XClassPropertyEventGeneratorListener>( |
| 78 |
|
XClassPropertyEventGeneratorListener.class); |
| 79 |
|
|
| 80 |
|
@Rule |
| 81 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(mocker); |
| 82 |
|
|
| 83 |
|
private ObservationManager mockObservation; |
| 84 |
|
|
| 85 |
|
private XWikiDocument document; |
| 86 |
|
|
| 87 |
|
private XWikiDocument documentOrigin; |
| 88 |
|
|
| 89 |
|
private BaseClass xclass; |
| 90 |
|
|
| 91 |
|
private BaseClass xclassOrigin; |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 93 |
5 |
@Before... |
| 94 |
|
public void before() throws Exception |
| 95 |
|
{ |
| 96 |
5 |
this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
| 97 |
5 |
this.documentOrigin = new XWikiDocument(this.document.getDocumentReference()); |
| 98 |
5 |
this.document.setOriginalDocument(this.documentOrigin); |
| 99 |
|
|
| 100 |
5 |
this.xclass = this.document.getXClass(); |
| 101 |
5 |
this.xclassOrigin = this.documentOrigin.getXClass(); |
| 102 |
|
|
| 103 |
5 |
this.mockObservation = this.mocker.getInstance(ObservationManager.class); |
| 104 |
|
} |
| 105 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 106 |
1 |
@Test... |
| 107 |
|
public void testAddDocument() throws ComponentLookupException |
| 108 |
|
{ |
| 109 |
1 |
this.xclass.addTextField("property", "Property", 30); |
| 110 |
|
|
| 111 |
1 |
final Event event = new XClassPropertyAddedEvent(this.xclass.getField("property").getReference()); |
| 112 |
|
|
| 113 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(this.document.getDocumentReference()), |
| 114 |
|
this.document, this.oldcore.getXWikiContext()); |
| 115 |
|
|
| 116 |
|
|
| 117 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 120 |
1 |
@Test... |
| 121 |
|
public void testDeleteDocument() throws ComponentLookupException |
| 122 |
|
{ |
| 123 |
1 |
this.xclassOrigin.addTextField("property", "Property", 30); |
| 124 |
|
|
| 125 |
1 |
final Event event = new XClassPropertyDeletedEvent(this.xclassOrigin.getField("property").getReference()); |
| 126 |
|
|
| 127 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentDeletedEvent(this.document.getDocumentReference()), |
| 128 |
|
this.document, this.oldcore.getXWikiContext()); |
| 129 |
|
|
| 130 |
|
|
| 131 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 134 |
1 |
@Test... |
| 135 |
|
public void testModifiedDocumentXClassPropertyAdded() throws ComponentLookupException |
| 136 |
|
{ |
| 137 |
1 |
this.xclass.addTextField("property", "Property", 30); |
| 138 |
|
|
| 139 |
1 |
final Event event = new XClassPropertyAddedEvent(this.xclass.getField("property").getReference()); |
| 140 |
|
|
| 141 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 142 |
|
this.document, this.oldcore.getXWikiContext()); |
| 143 |
|
|
| 144 |
|
|
| 145 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 146 |
|
} |
| 147 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 148 |
1 |
@Test... |
| 149 |
|
public void testModifiedDocumentXClassPropertyDeleted() throws ComponentLookupException |
| 150 |
|
{ |
| 151 |
1 |
this.xclassOrigin.addTextField("property", "Property", 30); |
| 152 |
|
|
| 153 |
1 |
final Event event = new XClassPropertyDeletedEvent(this.xclassOrigin.getField("property").getReference()); |
| 154 |
|
|
| 155 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 156 |
|
this.document, this.oldcore.getXWikiContext()); |
| 157 |
|
|
| 158 |
|
|
| 159 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 160 |
|
} |
| 161 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 162 |
1 |
@Test... |
| 163 |
|
public void testModifiedDocumentXClassPropertyModified() throws ComponentLookupException |
| 164 |
|
{ |
| 165 |
1 |
this.xclassOrigin.addTextField("property", "Property", 30); |
| 166 |
1 |
this.xclass.addTextField("property", "New Property", 30); |
| 167 |
|
|
| 168 |
1 |
final Event event = new XClassPropertyUpdatedEvent(this.xclassOrigin.getField("property").getReference()); |
| 169 |
|
|
| 170 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 171 |
|
this.document, this.oldcore.getXWikiContext()); |
| 172 |
|
|
| 173 |
|
|
| 174 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 175 |
|
} |
| 176 |
|
} |