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.objects.classes; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import org.junit.Before; |
25 |
|
import org.junit.Rule; |
26 |
|
import org.junit.Test; |
27 |
|
import org.xwiki.model.internal.DefaultModelConfiguration; |
28 |
|
import org.xwiki.model.internal.reference.DefaultEntityReferenceProvider; |
29 |
|
import org.xwiki.model.internal.reference.DefaultStringDocumentReferenceResolver; |
30 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceResolver; |
31 |
|
import org.xwiki.model.internal.reference.DefaultStringEntityReferenceSerializer; |
32 |
|
import org.xwiki.model.internal.reference.DefaultSymbolScheme; |
33 |
|
import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer; |
34 |
|
import org.xwiki.model.internal.reference.LocalUidStringEntityReferenceSerializer; |
35 |
|
import org.xwiki.model.reference.DocumentReference; |
36 |
|
import org.xwiki.observation.internal.DefaultObservationManager; |
37 |
|
import org.xwiki.query.Query; |
38 |
|
import org.xwiki.query.QueryManager; |
39 |
|
import org.xwiki.rendering.syntax.Syntax; |
40 |
|
import org.xwiki.test.annotation.AfterComponent; |
41 |
|
import org.xwiki.test.annotation.ComponentList; |
42 |
|
|
43 |
|
import com.xpn.xwiki.XWikiException; |
44 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
45 |
|
import com.xpn.xwiki.internal.event.XClassPropertyEventGeneratorListener; |
46 |
|
import com.xpn.xwiki.internal.model.reference.CurrentEntityReferenceProvider; |
47 |
|
import com.xpn.xwiki.internal.model.reference.CurrentReferenceDocumentReferenceResolver; |
48 |
|
import com.xpn.xwiki.internal.model.reference.CurrentReferenceEntityReferenceResolver; |
49 |
|
import com.xpn.xwiki.internal.model.reference.CurrentStringDocumentReferenceResolver; |
50 |
|
import com.xpn.xwiki.internal.model.reference.CurrentStringEntityReferenceResolver; |
51 |
|
import com.xpn.xwiki.internal.store.PropertyConverter; |
52 |
|
import com.xpn.xwiki.objects.BaseObject; |
53 |
|
import com.xpn.xwiki.objects.BaseProperty; |
54 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
55 |
|
|
56 |
|
import static org.junit.Assert.assertEquals; |
57 |
|
import static org.mockito.Mockito.mock; |
58 |
|
import static org.mockito.Mockito.when; |
59 |
|
|
60 |
|
|
61 |
|
@link |
62 |
|
|
63 |
|
@version |
64 |
|
|
65 |
|
@ComponentList({ |
66 |
|
XClassMigratorListener.class, |
67 |
|
DefaultObservationManager.class, |
68 |
|
LocalStringEntityReferenceSerializer.class, |
69 |
|
DefaultStringDocumentReferenceResolver.class, |
70 |
|
PropertyConverter.class, |
71 |
|
CurrentReferenceDocumentReferenceResolver.class, |
72 |
|
CurrentReferenceEntityReferenceResolver.class, |
73 |
|
CurrentEntityReferenceProvider.class, |
74 |
|
DefaultModelConfiguration.class, |
75 |
|
DefaultStringEntityReferenceResolver.class, |
76 |
|
DefaultEntityReferenceProvider.class, |
77 |
|
XClassPropertyEventGeneratorListener.class, |
78 |
|
CurrentStringDocumentReferenceResolver.class, |
79 |
|
CurrentStringEntityReferenceResolver.class, |
80 |
|
LocalUidStringEntityReferenceSerializer.class, |
81 |
|
DefaultStringEntityReferenceSerializer.class, |
82 |
|
DefaultSymbolScheme.class |
83 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 4 |
Complexity Density: 0.17 |
|
84 |
|
public class XClassMigratorListenerTest |
85 |
|
{ |
86 |
|
@Rule |
87 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
88 |
|
|
89 |
|
private XWikiDocument xobjectDocument; |
90 |
|
|
91 |
|
private XWikiDocument xclassDocument; |
92 |
|
|
93 |
|
private QueryManager mockQueryManager; |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
1 |
@AfterComponent... |
96 |
|
public void afterComponent() throws Exception |
97 |
|
{ |
98 |
1 |
this.mockQueryManager = this.oldcore.getMocker().registerMockComponent(QueryManager.class); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
101 |
1 |
@Before... |
102 |
|
public void before() throws Exception |
103 |
|
{ |
104 |
1 |
this.xclassDocument = new XWikiDocument(new DocumentReference("wiki", "Space", "Class")); |
105 |
1 |
this.xclassDocument.setSyntax(Syntax.PLAIN_1_0); |
106 |
|
|
107 |
1 |
this.xobjectDocument = new XWikiDocument(new DocumentReference("wiki", "Space", "Page")); |
108 |
1 |
this.xobjectDocument.setSyntax(Syntax.PLAIN_1_0); |
109 |
1 |
BaseObject xobject = new BaseObject(); |
110 |
1 |
xobject.setXClassReference(this.xclassDocument.getDocumentReference()); |
111 |
1 |
this.xobjectDocument.addXObject(xobject); |
112 |
|
|
113 |
1 |
Query query = mock(Query.class); |
114 |
1 |
when(this.mockQueryManager.createQuery("from doc.object(Space.Class) as obj", Query.XWQL)).thenReturn(query); |
115 |
1 |
when(query.<String>execute()).thenReturn(Arrays.asList("Space.Page")); |
116 |
|
|
117 |
|
|
118 |
1 |
this.oldcore.notifyDocumentUpdatedEvent(true); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void migrateProperty() throws Exception |
123 |
|
{ |
124 |
1 |
this.xclassDocument.getXClass().addTextField("property", "property", 30); |
125 |
1 |
saveXClassDocument(); |
126 |
1 |
this.xobjectDocument.setStringValue(this.xclassDocument.getDocumentReference(), "property", "42"); |
127 |
1 |
this.oldcore.getSpyXWiki().saveDocument(this.xobjectDocument, this.oldcore.getXWikiContext()); |
128 |
|
|
129 |
|
|
130 |
1 |
this.xclassDocument.getXClass().removeField("property"); |
131 |
1 |
this.xclassDocument.getXClass().addNumberField("property", "property", 30, "integer"); |
132 |
1 |
saveXClassDocument(); |
133 |
|
|
134 |
|
|
135 |
1 |
this.xobjectDocument = |
136 |
|
this.oldcore.getSpyXWiki().getDocument(this.xobjectDocument.getDocumentReference(), |
137 |
|
this.oldcore.getXWikiContext()); |
138 |
|
|
139 |
1 |
assertEquals(42, ((BaseProperty) this.xobjectDocument.getXObject(this.xclassDocument.getDocumentReference()) |
140 |
|
.get("property")).getValue()); |
141 |
|
} |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
143 |
2 |
private void saveXClassDocument() throws XWikiException... |
144 |
|
{ |
145 |
2 |
this.oldcore.getSpyXWiki().saveDocument(this.xclassDocument, this.oldcore.getXWikiContext()); |
146 |
2 |
this.xclassDocument = |
147 |
|
this.oldcore.getSpyXWiki().getDocument(this.xclassDocument.getDocumentReference(), |
148 |
|
this.oldcore.getXWikiContext()); |
149 |
|
} |
150 |
|
} |