mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
show restart checkbox only if restarting is supported
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
@@ -36,6 +36,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.lifecycle.Restarter;
|
||||
import sonia.scm.plugin.AvailablePlugin;
|
||||
import sonia.scm.plugin.AvailablePluginDescriptor;
|
||||
import sonia.scm.plugin.InstalledPlugin;
|
||||
@@ -59,6 +60,9 @@ class PluginDtoCollectionMapperTest {
|
||||
|
||||
ResourceLinks resourceLinks = ResourceLinksMock.createMock(URI.create("/"));
|
||||
|
||||
@Mock
|
||||
private Restarter restarter;
|
||||
|
||||
@InjectMocks
|
||||
PluginDtoMapperImpl pluginDtoMapper;
|
||||
|
||||
@@ -142,7 +146,7 @@ class PluginDtoCollectionMapperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAddInstallLinkForNewVersionWhenPermitted() {
|
||||
void shouldAddUpdateLinkForNewVersionWhenPermitted() {
|
||||
when(subject.isPermitted("plugin:manage")).thenReturn(true);
|
||||
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
|
||||
|
||||
@@ -154,6 +158,21 @@ class PluginDtoCollectionMapperTest {
|
||||
assertThat(plugin.getLinks().getLinkBy("update")).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAddUpdateWithRestartLinkForNewVersionWhenPermitted() {
|
||||
when(restarter.isSupported()).thenReturn(true);
|
||||
when(subject.isPermitted("plugin:manage")).thenReturn(true);
|
||||
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
|
||||
|
||||
HalRepresentation result = mapper.mapInstalled(
|
||||
singletonList(createInstalledPlugin("scm-some-plugin", "1")),
|
||||
singletonList(createAvailablePlugin("scm-some-plugin", "2")));
|
||||
|
||||
PluginDto plugin = getPluginDtoFromResult(result);
|
||||
assertThat(plugin.getLinks().getLinkBy("update")).isNotEmpty();
|
||||
assertThat(plugin.getLinks().getLinkBy("updateWithRestart")).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetInstalledPluginPendingWhenCorrespondingAvailablePluginIsPending() {
|
||||
when(subject.isPermitted("plugin:manage")).thenReturn(true);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -35,6 +35,7 @@ import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.lifecycle.Restarter;
|
||||
import sonia.scm.plugin.AvailablePlugin;
|
||||
import sonia.scm.plugin.AvailablePluginDescriptor;
|
||||
import sonia.scm.plugin.InstalledPlugin;
|
||||
@@ -56,6 +57,9 @@ class PluginDtoMapperTest {
|
||||
@SuppressWarnings("unused") // Is injected
|
||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(URI.create("https://hitchhiker.com/"));
|
||||
|
||||
@Mock
|
||||
private Restarter restarter;
|
||||
|
||||
@InjectMocks
|
||||
private PluginDtoMapperImpl mapper;
|
||||
|
||||
@@ -122,6 +126,7 @@ class PluginDtoMapperTest {
|
||||
|
||||
PluginDto dto = mapper.mapAvailable(plugin);
|
||||
assertThat(dto.getLinks().getLinkBy("install")).isEmpty();
|
||||
assertThat(dto.getLinks().getLinkBy("installWithRestart")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,6 +139,17 @@ class PluginDtoMapperTest {
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/available/scm-cas-plugin/install");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendInstallWithRestartLink() {
|
||||
when(restarter.isSupported()).thenReturn(true);
|
||||
when(subject.isPermitted("plugin:manage")).thenReturn(true);
|
||||
AvailablePlugin plugin = createAvailable(createPluginInformation());
|
||||
|
||||
PluginDto dto = mapper.mapAvailable(plugin);
|
||||
assertThat(dto.getLinks().getLinkBy("installWithRestart").get().getHref())
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/available/scm-cas-plugin/install?restart=true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnMiscellaneousIfCategoryIsNull() {
|
||||
PluginInformation information = createPluginInformation();
|
||||
@@ -162,4 +178,17 @@ class PluginDtoMapperTest {
|
||||
assertThat(dto.getLinks().getLinkBy("uninstall").get().getHref())
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/installed/scm-cas-plugin/uninstall");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendUninstallWithRestartLink() {
|
||||
when(restarter.isSupported()).thenReturn(true);
|
||||
when(subject.isPermitted("plugin:manage")).thenReturn(true);
|
||||
|
||||
InstalledPlugin plugin = createInstalled(createPluginInformation());
|
||||
when(plugin.isUninstallable()).thenReturn(true);
|
||||
|
||||
PluginDto dto = mapper.mapInstalled(plugin, emptyList());
|
||||
assertThat(dto.getLinks().getLinkBy("uninstallWithRestart").get().getHref())
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/installed/scm-cas-plugin/uninstall?restart=true");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user