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

File UserInstanceOutputFilterStreamTest.java

 

Code metrics

0
70
2
1
168
99
2
0.03
35
2
1

Classes

Class Line # Actions
UserInstanceOutputFilterStreamTest 42 70 0% 2 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 com.xpn.xwiki.internal.filter.output;
21   
22    import java.text.ParseException;
23   
24    import org.junit.jupiter.api.Test;
25    import org.xwiki.filter.FilterException;
26    import org.xwiki.model.reference.DocumentReference;
27   
28    import com.xpn.xwiki.XWikiException;
29    import com.xpn.xwiki.doc.XWikiDocument;
30    import com.xpn.xwiki.internal.filter.AbstractInstanceFilterStreamTest;
31    import com.xpn.xwiki.objects.BaseObject;
32    import com.xpn.xwiki.test.MockitoOldcoreRule;
33   
34    import static org.junit.jupiter.api.Assertions.assertEquals;
35    import static org.junit.jupiter.api.Assertions.assertFalse;
36   
37    /**
38    * Validate {@link UserInstanceOutputFilterStream}.
39    *
40    * @version $Id: b7ba84063ee68c2371cbcdf749e10c44f8f5c890 $
41    */
 
42    public class UserInstanceOutputFilterStreamTest extends AbstractInstanceFilterStreamTest
43    {
44    // Tests
45   
 
46  1 toggle @Test
47    public void testImportUsersAndGroupsPreserveVersion() throws FilterException, XWikiException, ParseException
48    {
49  1 UserInstanceOutputProperties outputProperties = new UserInstanceOutputProperties();
50   
51  1 outputProperties.setVersionPreserved(true);
52  1 outputProperties.setVerbose(false);
53   
54  1 importFromXML("user1", outputProperties);
55   
56    // XWiki.user1
57   
58  1 XWikiDocument userDocument = this.oldcore.getSpyXWiki()
59    .getDocument(new DocumentReference("wiki1", "XWiki", "user1"), this.oldcore.getXWikiContext());
60   
61  1 assertFalse(userDocument.isNew());
62   
63  1 assertEquals(new DocumentReference("wiki1", "XWiki", "user1"), userDocument.getCreatorReference());
64  1 assertEquals(toDate("2000-01-10 00:00:00.0 UTC"), userDocument.getCreationDate());
65  1 assertEquals(new DocumentReference("wiki1", "XWiki", "user1"), userDocument.getAuthorReference());
66  1 assertEquals(toDate("2000-01-11 00:00:00.0 UTC"), userDocument.getDate());
67  1 assertEquals(toDate("2000-01-11 00:00:00.0 UTC"), userDocument.getContentUpdateDate());
68  1 assertEquals(new DocumentReference("wiki1", "XWiki", "user1"), userDocument.getContentAuthorReference());
69  1 assertEquals(false, userDocument.isMinorEdit());
70  1 assertEquals("Import", userDocument.getComment());
71   
72  1 BaseObject userObject = userDocument.getXObject(MockitoOldcoreRule.USER_CLASS);
73  1 assertEquals(0, userObject.getNumber());
74  1 assertEquals("user1 first name", userObject.getStringValue("first_name"));
75  1 assertEquals("user1 last name", userObject.getStringValue("last_name"));
76  1 assertEquals("user1@email.ext", userObject.getStringValue("email"));
77  1 assertEquals(1, userObject.getIntValue("active"));
78   
79    // XWiki.user2
80   
81  1 userDocument = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "XWiki", "user2"),
82    this.oldcore.getXWikiContext());
83   
84  1 assertFalse(userDocument.isNew());
85   
86  1 assertEquals(new DocumentReference("wiki1", "XWiki", "user2"), userDocument.getCreatorReference());
87  1 assertEquals(toDate("2000-01-20 00:00:00.0 UTC"), userDocument.getCreationDate());
88  1 assertEquals(new DocumentReference("wiki1", "XWiki", "user2"), userDocument.getAuthorReference());
89  1 assertEquals(toDate("2000-01-21 00:00:00.0 UTC"), userDocument.getDate());
90  1 assertEquals(toDate("2000-01-21 00:00:00.0 UTC"), userDocument.getContentUpdateDate());
91  1 assertEquals(new DocumentReference("wiki1", "XWiki", "user2"), userDocument.getContentAuthorReference());
92  1 assertEquals(false, userDocument.isMinorEdit());
93  1 assertEquals("Import", userDocument.getComment());
94   
95  1 userObject = userDocument.getXObject(MockitoOldcoreRule.USER_CLASS);
96  1 assertEquals(0, userObject.getNumber());
97  1 assertEquals("user2 first name", userObject.getStringValue("first_name"));
98  1 assertEquals("user2 last name", userObject.getStringValue("last_name"));
99  1 assertEquals("user2@email.ext", userObject.getStringValue("email"));
100  1 assertEquals(0, userObject.getIntValue("active"));
101   
102    // XWiki.group1
103   
104  1 XWikiDocument groupDocument = this.oldcore.getSpyXWiki()
105    .getDocument(new DocumentReference("wiki1", "XWiki", "group1"), this.oldcore.getXWikiContext());
106   
107  1 assertFalse(groupDocument.isNew());
108   
109  1 BaseObject groupMemberObject0 = groupDocument.getXObject(MockitoOldcoreRule.GROUP_CLASS, 0);
110  1 assertEquals("XWiki.user1", groupMemberObject0.getStringValue("member"));
111  1 BaseObject groupMemberObject1 = groupDocument.getXObject(MockitoOldcoreRule.GROUP_CLASS, 1);
112  1 assertEquals("XWiki.user2", groupMemberObject1.getStringValue("member"));
113   
114    // XWiki.group2
115   
116  1 groupDocument = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "XWiki", "group2"),
117    this.oldcore.getXWikiContext());
118   
119  1 assertFalse(groupDocument.isNew());
120   
121  1 groupMemberObject0 = groupDocument.getXObject(MockitoOldcoreRule.GROUP_CLASS, 0);
122  1 assertEquals("XWiki.group1", groupMemberObject0.getStringValue("member"));
123   
124    // XWiki.emptygroup
125   
126  1 groupDocument = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "XWiki", "emptygroup"),
127    this.oldcore.getXWikiContext());
128   
129  1 assertFalse(groupDocument.isNew());
130   
131  1 groupMemberObject0 = groupDocument.getXObject(MockitoOldcoreRule.GROUP_CLASS, 0);
132  1 assertEquals("", groupMemberObject0.getStringValue("member"));
133    }
134   
 
135  1 toggle @Test
136    public void testImportUserWithoutWiki() throws FilterException, XWikiException, ParseException
137    {
138  1 UserInstanceOutputProperties outputProperties = new UserInstanceOutputProperties();
139   
140  1 outputProperties.setVersionPreserved(true);
141  1 outputProperties.setVerbose(false);
142   
143  1 importFromXML("userwithoutwiki", outputProperties);
144   
145    // XWiki.user
146   
147  1 XWikiDocument userDocument = this.oldcore.getSpyXWiki()
148    .getDocument(new DocumentReference("wiki", "XWiki", "user"), this.oldcore.getXWikiContext());
149   
150  1 assertFalse(userDocument.isNew());
151   
152  1 assertEquals(new DocumentReference("wiki", "XWiki", "user"), userDocument.getCreatorReference());
153  1 assertEquals(toDate("2000-01-10 00:00:00.0 UTC"), userDocument.getCreationDate());
154  1 assertEquals(new DocumentReference("wiki", "XWiki", "user"), userDocument.getAuthorReference());
155  1 assertEquals(toDate("2000-01-11 00:00:00.0 UTC"), userDocument.getDate());
156  1 assertEquals(toDate("2000-01-11 00:00:00.0 UTC"), userDocument.getContentUpdateDate());
157  1 assertEquals(new DocumentReference("wiki", "XWiki", "user"), userDocument.getContentAuthorReference());
158  1 assertEquals(false, userDocument.isMinorEdit());
159  1 assertEquals("Import", userDocument.getComment());
160   
161  1 BaseObject userObject = userDocument.getXObject(MockitoOldcoreRule.USER_CLASS);
162  1 assertEquals(0, userObject.getNumber());
163  1 assertEquals("user1 first name", userObject.getStringValue("first_name"));
164  1 assertEquals("user1 last name", userObject.getStringValue("last_name"));
165  1 assertEquals("user1@email.ext", userObject.getStringValue("email"));
166  1 assertEquals(1, userObject.getIntValue("active"));
167    }
168    }