| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.store; |
| 21 |
|
|
| 22 |
|
import org.junit.Before; |
| 23 |
|
import org.junit.Rule; |
| 24 |
|
import org.junit.Test; |
| 25 |
|
import org.xwiki.cache.Cache; |
| 26 |
|
import org.xwiki.cache.CacheManager; |
| 27 |
|
import org.xwiki.model.internal.reference.UidStringEntityReferenceSerializer; |
| 28 |
|
import org.xwiki.model.reference.DocumentReference; |
| 29 |
|
import org.xwiki.observation.ObservationManager; |
| 30 |
|
import org.xwiki.observation.remote.RemoteObservationManagerContext; |
| 31 |
|
import org.xwiki.test.annotation.ComponentList; |
| 32 |
|
|
| 33 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 34 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
| 35 |
|
|
| 36 |
|
import static com.xpn.xwiki.test.mockito.OldcoreMatchers.isCacheConfiguration; |
| 37 |
|
import static org.junit.Assert.assertFalse; |
| 38 |
|
import static org.junit.Assert.assertTrue; |
| 39 |
|
import static org.mockito.ArgumentMatchers.any; |
| 40 |
|
import static org.mockito.ArgumentMatchers.eq; |
| 41 |
|
import static org.mockito.Mockito.mock; |
| 42 |
|
import static org.mockito.Mockito.times; |
| 43 |
|
import static org.mockito.Mockito.verify; |
| 44 |
|
import static org.mockito.Mockito.verifyNoMoreInteractions; |
| 45 |
|
import static org.mockito.Mockito.when; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@link |
| 49 |
|
|
| 50 |
|
@version |
| 51 |
|
|
| 52 |
|
@ComponentList(UidStringEntityReferenceSerializer.class) |
| |
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 2 |
Complexity Density: 0.07 |
|
| 53 |
|
public class XWikiCacheStoreTest |
| 54 |
|
{ |
| 55 |
|
@Rule |
| 56 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
| 57 |
|
|
| 58 |
|
private Cache<XWikiDocument> cache; |
| 59 |
|
|
| 60 |
|
private Cache<Boolean> existCache; |
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 62 |
1 |
@Before... |
| 63 |
|
public void before() throws Exception |
| 64 |
|
{ |
| 65 |
1 |
this.oldcore.getMocker().registerMockComponent(RemoteObservationManagerContext.class); |
| 66 |
1 |
this.oldcore.getMocker().registerMockComponent(ObservationManager.class); |
| 67 |
|
|
| 68 |
1 |
CacheManager cacheManager = this.oldcore.getMocker().registerMockComponent(CacheManager.class); |
| 69 |
1 |
cache = mock(Cache.class); |
| 70 |
1 |
when(cacheManager.<XWikiDocument>createNewCache(isCacheConfiguration("xwiki.store.pagecache"))).thenReturn( |
| 71 |
|
cache); |
| 72 |
1 |
existCache = mock(Cache.class); |
| 73 |
1 |
when(cacheManager.<Boolean>createNewCache(isCacheConfiguration("xwiki.store.pageexistcache"))).thenReturn( |
| 74 |
|
existCache); |
| 75 |
|
} |
| 76 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 77 |
1 |
@Test... |
| 78 |
|
public void testLoadXWikiDoc() throws Exception |
| 79 |
|
{ |
| 80 |
|
|
| 81 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
| 82 |
|
|
| 83 |
|
|
| 84 |
1 |
DocumentReference reference = new DocumentReference("otherwiki", "space", "page"); |
| 85 |
1 |
this.oldcore.getSpyXWiki().saveDocument(new XWikiDocument(reference), this.oldcore.getXWikiContext()); |
| 86 |
|
|
| 87 |
1 |
XWikiCacheStore store = new XWikiCacheStore(this.oldcore.getMockStore(), this.oldcore.getXWikiContext()); |
| 88 |
|
|
| 89 |
1 |
XWikiDocument existingDocument = |
| 90 |
|
store.loadXWikiDoc(new XWikiDocument(reference), this.oldcore.getXWikiContext()); |
| 91 |
|
|
| 92 |
1 |
assertFalse(existingDocument.isNew()); |
| 93 |
1 |
verify(this.cache).set(eq("4:wiki5:space4:page"), any(XWikiDocument.class)); |
| 94 |
1 |
verify(this.existCache).set("4:wiki5:space4:page", Boolean.TRUE); |
| 95 |
1 |
verify(this.cache).get(any()); |
| 96 |
1 |
verify(this.existCache).get(any()); |
| 97 |
|
|
| 98 |
1 |
verifyNoMoreInteractions(this.cache); |
| 99 |
1 |
verifyNoMoreInteractions(this.existCache); |
| 100 |
|
|
| 101 |
1 |
XWikiDocument notExistingDocument = |
| 102 |
|
store.loadXWikiDoc(new XWikiDocument(new DocumentReference("otherwiki", "space", "nopage")), |
| 103 |
|
this.oldcore.getXWikiContext()); |
| 104 |
|
|
| 105 |
1 |
assertTrue(notExistingDocument.isNew()); |
| 106 |
|
|
| 107 |
|
|
| 108 |
1 |
verify(this.cache).set(eq("4:wiki5:space4:page"), any(XWikiDocument.class)); |
| 109 |
1 |
verify(this.existCache).set("4:wiki5:space4:page", Boolean.TRUE); |
| 110 |
1 |
verify(this.existCache).set("4:wiki5:space6:nopage", Boolean.FALSE); |
| 111 |
1 |
verify(this.cache, times(2)).get(any()); |
| 112 |
1 |
verify(this.existCache, times(2)).get(any()); |
| 113 |
|
|
| 114 |
1 |
verifyNoMoreInteractions(this.cache); |
| 115 |
1 |
verifyNoMoreInteractions(this.existCache); |
| 116 |
|
} |
| 117 |
|
} |