1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.event

File XClassPropertyEventGeneratorListenerTest.java

 

Code metrics

0
27
6
1
151
89
6
0.22
4.5
6
1

Classes

Class Line # Actions
XClassPropertyEventGeneratorListenerTest 49 27 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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.reference.DocumentReference;
30    import org.xwiki.observation.ObservationManager;
31    import org.xwiki.observation.event.Event;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33   
34    import com.xpn.xwiki.doc.XWikiDocument;
35    import com.xpn.xwiki.objects.classes.BaseClass;
36    import com.xpn.xwiki.test.MockitoOldcoreRule;
37    import com.xpn.xwiki.test.reference.ReferenceComponentList;
38   
39    import static org.mockito.ArgumentMatchers.eq;
40    import static org.mockito.ArgumentMatchers.same;
41    import static org.mockito.Mockito.verify;
42   
43    /**
44    * Validate {@link XClassPropertyEventGeneratorListener}.
45    *
46    * @version $Id: 71efee07691d92fcfcb8de59ebcc46ac200f2820 $
47    */
48    @ReferenceComponentList
 
49    public class XClassPropertyEventGeneratorListenerTest
50    {
51    public MockitoComponentMockingRule<XClassPropertyEventGeneratorListener> mocker =
52    new MockitoComponentMockingRule<XClassPropertyEventGeneratorListener>(
53    XClassPropertyEventGeneratorListener.class);
54   
55    @Rule
56    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(mocker);
57   
58    private ObservationManager mockObservation;
59   
60    private XWikiDocument document;
61   
62    private XWikiDocument documentOrigin;
63   
64    private BaseClass xclass;
65   
66    private BaseClass xclassOrigin;
67   
 
68  5 toggle @Before
69    public void before() throws Exception
70    {
71  5 this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
72  5 this.documentOrigin = new XWikiDocument(this.document.getDocumentReference());
73  5 this.document.setOriginalDocument(this.documentOrigin);
74   
75  5 this.xclass = this.document.getXClass();
76  5 this.xclassOrigin = this.documentOrigin.getXClass();
77   
78  5 this.mockObservation = this.mocker.getInstance(ObservationManager.class);
79    }
80   
 
81  1 toggle @Test
82    public void testAddDocument() throws ComponentLookupException
83    {
84  1 this.xclass.addTextField("property", "Property", 30);
85   
86  1 final Event event = new XClassPropertyAddedEvent(this.xclass.getField("property").getReference());
87   
88  1 this.mocker.getComponentUnderTest().onEvent(new DocumentCreatedEvent(this.document.getDocumentReference()),
89    this.document, this.oldcore.getXWikiContext());
90   
91    // Make sure the listener generated a xobject added event
92  1 verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
93    }
94   
 
95  1 toggle @Test
96    public void testDeleteDocument() throws ComponentLookupException
97    {
98  1 this.xclassOrigin.addTextField("property", "Property", 30);
99   
100  1 final Event event = new XClassPropertyDeletedEvent(this.xclassOrigin.getField("property").getReference());
101   
102  1 this.mocker.getComponentUnderTest().onEvent(new DocumentDeletedEvent(this.document.getDocumentReference()),
103    this.document, this.oldcore.getXWikiContext());
104   
105    // Make sure the listener generated a xobject added event
106  1 verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
107    }
108   
 
109  1 toggle @Test
110    public void testModifiedDocumentXClassPropertyAdded() throws ComponentLookupException
111    {
112  1 this.xclass.addTextField("property", "Property", 30);
113   
114  1 final Event event = new XClassPropertyAddedEvent(this.xclass.getField("property").getReference());
115   
116  1 this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()),
117    this.document, this.oldcore.getXWikiContext());
118   
119    // Make sure the listener generated a xobject added event
120  1 verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
121    }
122   
 
123  1 toggle @Test
124    public void testModifiedDocumentXClassPropertyDeleted() throws ComponentLookupException
125    {
126  1 this.xclassOrigin.addTextField("property", "Property", 30);
127   
128  1 final Event event = new XClassPropertyDeletedEvent(this.xclassOrigin.getField("property").getReference());
129   
130  1 this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()),
131    this.document, this.oldcore.getXWikiContext());
132   
133    // Make sure the listener generated a xobject added event
134  1 verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
135    }
136   
 
137  1 toggle @Test
138    public void testModifiedDocumentXClassPropertyModified() throws ComponentLookupException
139    {
140  1 this.xclassOrigin.addTextField("property", "Property", 30);
141  1 this.xclass.addTextField("property", "New Property", 30);
142   
143  1 final Event event = new XClassPropertyUpdatedEvent(this.xclassOrigin.getField("property").getReference());
144   
145  1 this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(this.document.getDocumentReference()),
146    this.document, this.oldcore.getXWikiContext());
147   
148    // Make sure the listener generated a xobject added event
149  1 verify(this.mockObservation).notify(eq(event), same(this.document), same(this.oldcore.getXWikiContext()));
150    }
151    }