1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.eventstream.internal

File UntypedRecordableEventDescriptorComponentBuilderTest.java

 

Code metrics

0
22
3
1
114
68
3
0.14
7.33
3
1

Classes

Class Line # Actions
UntypedRecordableEventDescriptorComponentBuilderTest 51 22 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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 org.xwiki.eventstream.internal;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.component.wiki.WikiComponent;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.DocumentReferenceResolver;
31    import org.xwiki.query.Query;
32    import org.xwiki.query.QueryManager;
33    import org.xwiki.security.authorization.AuthorizationManager;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import com.xpn.xwiki.doc.XWikiDocument;
37    import com.xpn.xwiki.objects.BaseObject;
38   
39    import static org.junit.Assert.assertEquals;
40    import static org.mockito.ArgumentMatchers.any;
41    import static org.mockito.Mockito.mock;
42    import static org.mockito.Mockito.verify;
43    import static org.mockito.Mockito.when;
44   
45    /**
46    * Unit tests for {@link UntypedRecordableEventDescriptorComponentBuilder}.
47    *
48    * @version $Id: 49845b7885a0ffa3ba472c76e401dae0e2fb5093 $
49    * @since 9.6RC1
50    */
 
51    public class UntypedRecordableEventDescriptorComponentBuilderTest
52    {
53    @Rule
54    public final MockitoComponentMockingRule<UntypedRecordableEventDescriptorComponentBuilder> mocker =
55    new MockitoComponentMockingRule<>(UntypedRecordableEventDescriptorComponentBuilder.class);
56   
57    private ModelBridge modelBridge;
58   
59    private QueryManager queryManager;
60   
61    private DocumentReferenceResolver<String> documentReferenceResolver;
62   
63    private AuthorizationManager authorizationManager;
64   
65    private DocumentReference event1;
66    private DocumentReference event2;
67    private DocumentReference event3;
68   
 
69  2 toggle @Before
70    public void setUp() throws Exception
71    {
72  2 queryManager = mocker.registerMockComponent(QueryManager.class);
73  2 modelBridge = mocker.registerMockComponent(ModelBridge.class);
74  2 documentReferenceResolver = mocker.registerMockComponent(DocumentReferenceResolver.class);
75  2 authorizationManager = mocker.registerMockComponent(AuthorizationManager.class);
76   
77  2 Query query = mock(Query.class);
78  2 when(queryManager.createQuery(any(), any())).thenReturn(query);
79  2 when(query.execute()).thenReturn(Arrays.asList("e1", "e2", "e3"));
80   
81  2 event1 = mock(DocumentReference.class);
82  2 event2 = mock(DocumentReference.class);
83  2 event3 = mock(DocumentReference.class);
84   
85  2 when(this.documentReferenceResolver.resolve("e1")).thenReturn(event1);
86  2 when(this.documentReferenceResolver.resolve("e2")).thenReturn(event2);
87  2 when(this.documentReferenceResolver.resolve("e3")).thenReturn(event3);
88    }
89   
 
90  1 toggle @Test
91    public void testClassReference() throws Exception
92    {
93  1 assertEquals("EventClass",
94    this.mocker.getComponentUnderTest().getClassReference().getName());
95    }
96   
 
97  1 toggle @Test
98    public void testBuildComponent() throws Exception
99    {
100  1 BaseObject baseObject = mock(BaseObject.class);
101  1 XWikiDocument parentDocument = mock(XWikiDocument.class);
102  1 DocumentReference documentReference = mock(DocumentReference.class);
103   
104  1 when(baseObject.getOwnerDocument()).thenReturn(parentDocument);
105  1 when(parentDocument.getDocumentReference()).thenReturn(documentReference);
106   
107    // Ensure that the user rights are correctly checked
108  1 when(this.authorizationManager.hasAccess(any(), any(), any())).thenReturn(true);
109   
110  1 List<WikiComponent> result = this.mocker.getComponentUnderTest().buildComponents(baseObject);
111   
112  1 assertEquals(1, result.size());
113    }
114    }