| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.platform.blog.internal; |
| 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.extension.ExtensionId; |
| 28 |
|
import org.xwiki.extension.InstalledExtension; |
| 29 |
|
import org.xwiki.extension.event.ExtensionUpgradedEvent; |
| 30 |
|
import org.xwiki.model.reference.WikiReference; |
| 31 |
|
import org.xwiki.platform.blog.BlogVisibilityMigration; |
| 32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 33 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
| 34 |
|
|
| 35 |
|
import static org.mockito.ArgumentMatchers.eq; |
| 36 |
|
import static org.mockito.Mockito.mock; |
| 37 |
|
import static org.mockito.Mockito.verify; |
| 38 |
|
import static org.mockito.Mockito.verifyZeroInteractions; |
| 39 |
|
import static org.mockito.Mockito.when; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@version |
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (41) |
Complexity: 10 |
Complexity Density: 0.33 |
|
| 44 |
|
public class BlogUpgradeEventListenerTest |
| 45 |
|
{ |
| 46 |
|
@Rule |
| 47 |
|
public MockitoComponentMockingRule<BlogUpgradeEventListener> mocker = |
| 48 |
|
new MockitoComponentMockingRule<>(BlogUpgradeEventListener.class); |
| 49 |
|
|
| 50 |
|
private BlogVisibilityMigration blogVisibilityMigration; |
| 51 |
|
private WikiDescriptorManager wikiDescriptorManager; |
| 52 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 53 |
7 |
@Before... |
| 54 |
|
public void setUp() throws Exception |
| 55 |
|
{ |
| 56 |
7 |
blogVisibilityMigration = mocker.getInstance(BlogVisibilityMigration.class); |
| 57 |
7 |
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
| 58 |
|
} |
| 59 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 60 |
5 |
private void testWithVersion(String version, boolean executedExpected) throws Exception... |
| 61 |
|
{ |
| 62 |
|
|
| 63 |
5 |
InstalledExtension installedExtension1 = mock(InstalledExtension.class); |
| 64 |
5 |
InstalledExtension installedExtension2 = mock(InstalledExtension.class); |
| 65 |
5 |
InstalledExtension installedExtension3 = mock(InstalledExtension.class); |
| 66 |
|
|
| 67 |
5 |
ExtensionUpgradedEvent event = new ExtensionUpgradedEvent( |
| 68 |
|
new ExtensionId("org.xwiki.platform:xwiki-platform-blog-ui", "9.0"), "wiki:chocolate"); |
| 69 |
|
|
| 70 |
5 |
when(installedExtension1.getId()).thenReturn(new ExtensionId("foo", "8")); |
| 71 |
5 |
when(installedExtension2.getId()).thenReturn(new ExtensionId("bar", "9.0")); |
| 72 |
5 |
when(installedExtension2.getId()).thenReturn(new ExtensionId("org.xwiki.platform:xwiki-platform-blog-ui", |
| 73 |
|
version)); |
| 74 |
|
|
| 75 |
|
|
| 76 |
5 |
mocker.getComponentUnderTest().onEvent(event, null, |
| 77 |
|
Arrays.asList(installedExtension1, installedExtension2, installedExtension3)); |
| 78 |
|
|
| 79 |
|
|
| 80 |
5 |
if (executedExpected) { |
| 81 |
2 |
verify(blogVisibilityMigration).execute(eq(new WikiReference("chocolate"))); |
| 82 |
|
} else { |
| 83 |
3 |
verifyZeroInteractions(blogVisibilityMigration); |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 87 |
1 |
@Test... |
| 88 |
|
public void onEventWithVersion82() throws Exception |
| 89 |
|
{ |
| 90 |
1 |
testWithVersion("8.2", true); |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 93 |
1 |
@Test... |
| 94 |
|
public void onEventWithVersion51() throws Exception |
| 95 |
|
{ |
| 96 |
1 |
testWithVersion("5.1", true); |
| 97 |
|
} |
| 98 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 99 |
1 |
@Test... |
| 100 |
|
public void onEventWithVersion746() throws Exception |
| 101 |
|
{ |
| 102 |
1 |
testWithVersion("7.4.6", false); |
| 103 |
|
} |
| 104 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 105 |
1 |
@Test... |
| 106 |
|
public void onEventWithVersion843() throws Exception |
| 107 |
|
{ |
| 108 |
1 |
testWithVersion("8.4.3", false); |
| 109 |
|
} |
| 110 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 111 |
1 |
@Test... |
| 112 |
|
public void onEventWithVersion90() throws Exception |
| 113 |
|
{ |
| 114 |
1 |
testWithVersion("9.0", false); |
| 115 |
|
} |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 117 |
1 |
@Test... |
| 118 |
|
public void onEventWithNoBlogInstalled() throws Exception |
| 119 |
|
{ |
| 120 |
|
|
| 121 |
1 |
InstalledExtension installedExtension1 = mock(InstalledExtension.class); |
| 122 |
|
|
| 123 |
1 |
ExtensionUpgradedEvent event = new ExtensionUpgradedEvent( |
| 124 |
|
new ExtensionId("org.xwiki.platform:xwiki-platform-blog-ui", "9.0"), "wiki:chocolate"); |
| 125 |
|
|
| 126 |
1 |
when(installedExtension1.getId()).thenReturn(new ExtensionId("foobar", "8")); |
| 127 |
|
|
| 128 |
|
|
| 129 |
1 |
mocker.getComponentUnderTest().onEvent(event, null, Arrays.asList(installedExtension1)); |
| 130 |
|
|
| 131 |
|
|
| 132 |
1 |
verifyZeroInteractions(blogVisibilityMigration); |
| 133 |
|
} |
| 134 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 135 |
1 |
@Test... |
| 136 |
|
public void onEventWithNoNamespace() throws Exception |
| 137 |
|
{ |
| 138 |
|
|
| 139 |
1 |
InstalledExtension installedExtension1 = mock(InstalledExtension.class); |
| 140 |
|
|
| 141 |
1 |
ExtensionUpgradedEvent event = new ExtensionUpgradedEvent( |
| 142 |
|
new ExtensionId("org.xwiki.platform:xwiki-platform-blog-ui", "9.0"), null); |
| 143 |
|
|
| 144 |
1 |
when(installedExtension1.getId()).thenReturn(new ExtensionId("org.xwiki.platform:xwiki-platform-blog-ui", |
| 145 |
|
"2.3")); |
| 146 |
|
|
| 147 |
1 |
when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("wiki1", "wiki2")); |
| 148 |
|
|
| 149 |
|
|
| 150 |
1 |
mocker.getComponentUnderTest().onEvent(event, null, Arrays.asList(installedExtension1)); |
| 151 |
|
|
| 152 |
|
|
| 153 |
1 |
verify(blogVisibilityMigration).execute(eq(new WikiReference("wiki1"))); |
| 154 |
1 |
verify(blogVisibilityMigration).execute(eq(new WikiReference("wiki2"))); |
| 155 |
|
} |
| 156 |
|
} |