| 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.BaseObject; |
| 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 (57) |
Complexity: 9 |
Complexity Density: 0.19 |
|
| 74 |
|
public class XObjectEventGeneratorListenerTest |
| 75 |
|
{ |
| 76 |
|
public MockitoComponentMockingRule<XObjectEventGeneratorListener> mocker = |
| 77 |
|
new MockitoComponentMockingRule<XObjectEventGeneratorListener>(XObjectEventGeneratorListener.class); |
| 78 |
|
|
| 79 |
|
@Rule |
| 80 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(mocker); |
| 81 |
|
|
| 82 |
|
private ObservationManager mockObservation; |
| 83 |
|
|
| 84 |
|
private XWikiDocument document; |
| 85 |
|
|
| 86 |
|
private XWikiDocument documentOrigin; |
| 87 |
|
|
| 88 |
|
private BaseObject xobject; |
| 89 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 90 |
8 |
@Before... |
| 91 |
|
public void before() throws Exception |
| 92 |
|
{ |
| 93 |
8 |
this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
| 94 |
8 |
this.documentOrigin = new XWikiDocument(this.document.getDocumentReference()); |
| 95 |
8 |
this.document.setOriginalDocument(this.documentOrigin); |
| 96 |
|
|
| 97 |
8 |
this.xobject = new BaseObject(); |
| 98 |
8 |
this.xobject.setXClassReference(this.document.getDocumentReference()); |
| 99 |
|
|
| 100 |
8 |
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 testAddDocument() throws ComponentLookupException |
| 105 |
|
{ |
| 106 |
1 |
this.document.addXObject(this.xobject); |
| 107 |
|
|
| 108 |
1 |
final Event event = new XObjectAddedEvent(this.xobject.getReference()); |
| 109 |
|
|
| 110 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(this.document.getDocumentReference()), |
| 111 |
|
this.document, this.oldcore.getXWikiContext()); |
| 112 |
|
|
| 113 |
|
|
| 114 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 115 |
|
} |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 117 |
1 |
@Test... |
| 118 |
|
public void testDeleteDocument() throws ComponentLookupException |
| 119 |
|
{ |
| 120 |
1 |
this.documentOrigin.addXObject(this.xobject); |
| 121 |
|
|
| 122 |
1 |
final Event event = new XObjectDeletedEvent(this.xobject.getReference()); |
| 123 |
|
|
| 124 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentDeletedEvent(this.document.getDocumentReference()), |
| 125 |
|
this.document, this.oldcore.getXWikiContext()); |
| 126 |
|
|
| 127 |
|
|
| 128 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 129 |
|
} |
| 130 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 131 |
1 |
@Test... |
| 132 |
|
public void testModifiedDocumentXObjectAdded() throws ComponentLookupException |
| 133 |
|
{ |
| 134 |
1 |
this.document.addXObject(this.xobject); |
| 135 |
|
|
| 136 |
1 |
final Event event = new XObjectAddedEvent(this.xobject.getReference()); |
| 137 |
|
|
| 138 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 139 |
|
this.document, this.oldcore.getXWikiContext()); |
| 140 |
|
|
| 141 |
|
|
| 142 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 143 |
|
} |
| 144 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 145 |
1 |
@Test... |
| 146 |
|
public void testModifiedDocumentXObjectDeleted() throws ComponentLookupException |
| 147 |
|
{ |
| 148 |
1 |
this.documentOrigin.addXObject(this.xobject); |
| 149 |
|
|
| 150 |
1 |
final Event event = new XObjectDeletedEvent(this.xobject.getReference()); |
| 151 |
|
|
| 152 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 153 |
|
this.document, this.oldcore.getXWikiContext()); |
| 154 |
|
|
| 155 |
|
|
| 156 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 157 |
|
} |
| 158 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 159 |
1 |
@Test... |
| 160 |
|
public void testModifiedDocumentXObjectModified() throws ComponentLookupException |
| 161 |
|
{ |
| 162 |
1 |
this.document.addXObject(this.xobject); |
| 163 |
1 |
this.documentOrigin.addXObject(this.xobject.clone()); |
| 164 |
|
|
| 165 |
1 |
this.xobject.setStringValue("newproperty", "newvalue"); |
| 166 |
|
|
| 167 |
1 |
final Event event = new XObjectUpdatedEvent(this.xobject.getReference()); |
| 168 |
|
|
| 169 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 170 |
|
this.document, this.oldcore.getXWikiContext()); |
| 171 |
|
|
| 172 |
|
|
| 173 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 174 |
|
} |
| 175 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 176 |
1 |
@Test... |
| 177 |
|
public void testModifiedDocumentXObjectPropertyAdded() throws ComponentLookupException |
| 178 |
|
{ |
| 179 |
1 |
this.document.addXObject(this.xobject); |
| 180 |
1 |
this.documentOrigin.addXObject(this.xobject.clone()); |
| 181 |
|
|
| 182 |
1 |
this.xobject.setStringValue("newproperty", "newvalue"); |
| 183 |
|
|
| 184 |
1 |
final Event event = new XObjectPropertyAddedEvent(this.xobject.getField("newproperty").getReference()); |
| 185 |
|
|
| 186 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 187 |
|
this.document, this.oldcore.getXWikiContext()); |
| 188 |
|
|
| 189 |
|
|
| 190 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 191 |
|
} |
| 192 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 193 |
1 |
@Test... |
| 194 |
|
public void testModifiedDocumentXObjectPropertyDeleted() throws ComponentLookupException |
| 195 |
|
{ |
| 196 |
1 |
this.document.addXObject(this.xobject.clone()); |
| 197 |
1 |
this.documentOrigin.addXObject(this.xobject); |
| 198 |
|
|
| 199 |
1 |
this.xobject.setStringValue("deletedproperty", "deletedvalue"); |
| 200 |
|
|
| 201 |
1 |
final Event event = new XObjectPropertyDeletedEvent(this.xobject.getField("deletedproperty").getReference()); |
| 202 |
|
|
| 203 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 204 |
|
this.document, this.oldcore.getXWikiContext()); |
| 205 |
|
|
| 206 |
|
|
| 207 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 208 |
|
} |
| 209 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 210 |
1 |
@Test... |
| 211 |
|
public void testModifiedDocumentXObjectPropertyModified() throws ComponentLookupException |
| 212 |
|
{ |
| 213 |
1 |
this.xobject.setStringValue("updatedproperty", "propertyvalue"); |
| 214 |
|
|
| 215 |
1 |
BaseObject xobjectModified = this.xobject.clone(); |
| 216 |
1 |
xobjectModified.setStringValue("updatedproperty", "propertyvaluemodified"); |
| 217 |
|
|
| 218 |
1 |
this.document.addXObject(this.xobject); |
| 219 |
1 |
this.documentOrigin.addXObject(xobjectModified); |
| 220 |
|
|
| 221 |
1 |
final Event event = new XObjectPropertyUpdatedEvent(this.xobject.getField("updatedproperty").getReference()); |
| 222 |
|
|
| 223 |
1 |
this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()), |
| 224 |
|
this.document, this.oldcore.getXWikiContext()); |
| 225 |
|
|
| 226 |
|
|
| 227 |
1 |
verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext())); |
| 228 |
|
} |
| 229 |
|
} |