|
19 | 19 | */ |
20 | 20 | package org.xwiki.web; |
21 | 21 |
|
| 22 | +import java.util.List; |
| 23 | + |
22 | 24 | import javax.inject.Inject; |
23 | 25 | import javax.inject.Named; |
24 | 26 |
|
25 | 27 | import org.junit.jupiter.api.BeforeEach; |
26 | 28 | import org.junit.jupiter.api.Test; |
27 | 29 | import org.xwiki.extension.DefaultExtensionDependency; |
28 | 30 | import org.xwiki.extension.ExtensionDependency; |
| 31 | +import org.xwiki.extension.ExtensionId; |
| 32 | +import org.xwiki.extension.job.InstallRequest; |
| 33 | +import org.xwiki.extension.job.plan.internal.DefaultExtensionPlan; |
29 | 34 | import org.xwiki.extension.script.ExtensionManagerScriptService; |
30 | 35 | import org.xwiki.extension.version.internal.DefaultVersionConstraint; |
| 36 | +import org.xwiki.logging.LogQueue; |
31 | 37 | import org.xwiki.script.service.ScriptService; |
32 | 38 | import org.xwiki.template.TemplateManager; |
33 | 39 | import org.xwiki.test.junit5.mockito.MockComponent; |
34 | 40 | import org.xwiki.test.page.PageTest; |
35 | 41 |
|
36 | 42 | import static org.hamcrest.MatcherAssert.assertThat; |
37 | 43 | import static org.hamcrest.Matchers.containsString; |
| 44 | +import static org.hamcrest.Matchers.matchesRegex; |
| 45 | +import static org.hamcrest.Matchers.not; |
38 | 46 | import static org.mockito.Mockito.doReturn; |
| 47 | +import static org.mockito.Mockito.mock; |
| 48 | +import static org.mockito.Mockito.verify; |
39 | 49 | import static org.mockito.Mockito.when; |
40 | 50 |
|
41 | 51 | /** |
@@ -78,4 +88,37 @@ void nonExistingExtensionRequest() throws Exception |
78 | 88 | <span class="extension-name"><test></span><span |
79 | 89 | class="extension-version"><test></span>""")); |
80 | 90 | } |
| 91 | + |
| 92 | + @Test |
| 93 | + void nonExistingExtensionRequestWithJobStatus() throws Exception |
| 94 | + { |
| 95 | + String testValue = "<test>"; |
| 96 | + this.stubRequest.put("extensionId", testValue); |
| 97 | + this.stubRequest.put("extensionVersion", testValue); |
| 98 | + this.stubRequest.put("extensionSection", "progress"); |
| 99 | + String namespace = "wiki:xwiki"; |
| 100 | + this.stubRequest.put("extensionNamespace", namespace); |
| 101 | + ExtensionId extensionId = new ExtensionId(testValue, testValue); |
| 102 | + |
| 103 | + // Mock an extension job status for an installation request with the necessary properties to trigger the |
| 104 | + // display of the log message. |
| 105 | + ExtensionManagerScriptService service = (ExtensionManagerScriptService) this.extensionManagerScriptService; |
| 106 | + InstallRequest installRequest = mock(); |
| 107 | + when(installRequest.getExtensions()).thenReturn(List.of(extensionId)); |
| 108 | + LogQueue logEvents = new LogQueue(); |
| 109 | + logEvents.info("Resolving extension [{}] on namespace [{}]", extensionId, namespace); |
| 110 | + DefaultExtensionPlan<InstallRequest> extensionPlan = mock(); |
| 111 | + when(extensionPlan.getRequest()).thenReturn(installRequest); |
| 112 | + when(extensionPlan.getLogTail()).thenReturn(logEvents); |
| 113 | + when(service.getExtensionPlanJobStatus(testValue, namespace)).thenReturn(extensionPlan); |
| 114 | + |
| 115 | + String output = this.templateManager.render("distribution.vm"); |
| 116 | + |
| 117 | + verify(service).getExtensionPlanJobStatus(testValue, namespace); |
| 118 | + |
| 119 | + assertThat(output, containsString("<test>")); |
| 120 | + assertThat(output, not(containsString(testValue))); |
| 121 | + assertThat(output, matchesRegex("(?s).*Resolving extension \\[<a href=\"[^\"]*\" class=\"extension-link\"><" |
| 122 | + + "test>/<test></a>].*")); |
| 123 | + } |
81 | 124 | } |
0 commit comments