Merge branch 'develop' into feature/packaging

# Conflicts:
#	Jenkinsfile
#	pom.xml
This commit is contained in:
Sebastian Sdorra
2020-05-23 15:27:43 +02:00
339 changed files with 3978 additions and 8015 deletions

View File

@@ -0,0 +1,93 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.TempDirectory;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.nio.file.Path;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
@ExtendWith({MockitoExtension.class, TempDirectory.class})
class ScmLogFilePropertyDefinerTest {
@Mock
private SCMContextProvider context;
@Test
void shouldReturnPath(@TempDirectory.TempDir Path tempDir) {
when(context.getBaseDirectory()).thenReturn(tempDir.toFile());
ScmLogFilePropertyDefiner definer = builder().create();
Path logDirectory = tempDir.resolve("logs");
assertThat(definer.getPropertyValue()).isEqualTo(logDirectory.toAbsolutePath().toString());
}
@Test
void shouldReturnOsxPath(@TempDirectory.TempDir Path tempDir) {
ScmLogFilePropertyDefiner definer = builder()
.withOs("Mac OS X")
.withUserHome(tempDir.toAbsolutePath().toString())
.create();
Path logDirectory = tempDir.resolve("Library/Logs/SCM-Manager");
assertThat(definer.getPropertyValue()).isEqualTo(logDirectory.toAbsolutePath().toString());
}
private ScmLogFilePropertyDefinerBuilder builder() {
return new ScmLogFilePropertyDefinerBuilder();
}
private class ScmLogFilePropertyDefinerBuilder {
private Platform platform;
private Properties properties = new Properties();
public ScmLogFilePropertyDefinerBuilder() {
withOs("Linux");
}
public ScmLogFilePropertyDefinerBuilder withOs(String osName) {
platform = new Platform(osName, "64", "x86_64");
return this;
}
public ScmLogFilePropertyDefinerBuilder withUserHome(String path) {
properties.setProperty("user.home", path);
return this;
}
public ScmLogFilePropertyDefiner create() {
return new ScmLogFilePropertyDefiner(context, platform, properties);
}
}
}

View File

@@ -1,85 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* 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.Embedded;
import de.otto.edison.hal.HalRepresentation;
import de.otto.edison.hal.Link;
import de.otto.edison.hal.Links;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import static de.otto.edison.hal.Embedded.embeddedBuilder;
import static de.otto.edison.hal.Links.linkingTo;
import static org.assertj.core.api.Assertions.assertThat;
class EdisonHalAppenderTest {
private Links.Builder linksBuilder;
private Embedded.Builder embeddedBuilder;
private EdisonHalAppender appender;
@BeforeEach
void prepare() {
linksBuilder = linkingTo();
embeddedBuilder = embeddedBuilder();
appender = new EdisonHalAppender(linksBuilder, embeddedBuilder);
}
@Test
void shouldAppendOneLink() {
appender.appendLink("self", "https://scm.hitchhiker.com");
Links links = linksBuilder.build();
assertThat(links.getLinkBy("self").get().getHref()).isEqualTo("https://scm.hitchhiker.com");
}
@Test
void shouldAppendMultipleLinks() {
appender.linkArrayBuilder("items")
.append("one", "http://one")
.append("two", "http://two")
.build();
List<Link> items = linksBuilder.build().getLinksBy("items");
assertThat(items).hasSize(2);
}
@Test
void shouldAppendEmbedded() {
HalRepresentation one = new HalRepresentation();
appender.appendEmbedded("one", one);
HalRepresentation two = new HalRepresentation();
appender.appendEmbedded("two", new HalRepresentation());
Embedded embedded = embeddedBuilder.build();
assertThat(embedded.getItemsBy("one")).containsOnly(one);
assertThat(embedded.getItemsBy("two")).containsOnly(two);
}
}

View File

@@ -114,7 +114,7 @@ class PendingPluginResourceTest {
@BeforeEach
void bindSubject() {
ThreadContext.bind(subject);
lenient().when(subject.isPermitted("plugin:manage")).thenReturn(true);
lenient().when(subject.isPermitted("plugin:write")).thenReturn(true);
lenient().when(restarter.isSupported()).thenReturn(true);
}
@@ -228,7 +228,7 @@ class PendingPluginResourceTest {
@BeforeEach
void bindSubject() {
ThreadContext.bind(subject);
when(subject.isPermitted("plugin:manage")).thenReturn(false);
when(subject.isPermitted("plugin:write")).thenReturn(false);
}
@AfterEach

View File

@@ -119,7 +119,7 @@ class PluginDtoCollectionMapperTest {
@Test
void shouldNotAddInstallLinkForNewVersionWhenNotPermitted() {
when(subject.isPermitted("plugin:manage")).thenReturn(false);
when(subject.isPermitted("plugin:write")).thenReturn(false);
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
HalRepresentation result = mapper.mapInstalled(
@@ -132,7 +132,7 @@ class PluginDtoCollectionMapperTest {
@Test
void shouldNotAddInstallLinkForNewVersionWhenInstallationIsPending() {
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
AvailablePlugin availablePlugin = createAvailablePlugin("scm-some-plugin", "2");
@@ -147,7 +147,7 @@ class PluginDtoCollectionMapperTest {
@Test
void shouldAddUpdateLinkForNewVersionWhenPermitted() {
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
HalRepresentation result = mapper.mapInstalled(
@@ -161,7 +161,7 @@ class PluginDtoCollectionMapperTest {
@Test
void shouldAddUpdateWithRestartLinkForNewVersionWhenPermitted() {
when(restarter.isSupported()).thenReturn(true);
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
HalRepresentation result = mapper.mapInstalled(
@@ -175,7 +175,7 @@ class PluginDtoCollectionMapperTest {
@Test
void shouldSetInstalledPluginPendingWhenCorrespondingAvailablePluginIsPending() {
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
PluginDtoCollectionMapper mapper = new PluginDtoCollectionMapper(resourceLinks, pluginDtoMapper, manager);
AvailablePlugin availablePlugin = createAvailablePlugin("scm-some-plugin", "2");

View File

@@ -127,7 +127,7 @@ class PluginDtoMapperTest {
@Test
void shouldAppendInstallLink() {
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
AvailablePlugin plugin = createAvailable(createPluginInformation());
PluginDto dto = mapper.mapAvailable(plugin);
@@ -138,7 +138,7 @@ class PluginDtoMapperTest {
@Test
void shouldAppendInstallWithRestartLink() {
when(restarter.isSupported()).thenReturn(true);
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
AvailablePlugin plugin = createAvailable(createPluginInformation());
PluginDto dto = mapper.mapAvailable(plugin);
@@ -166,7 +166,7 @@ class PluginDtoMapperTest {
@Test
void shouldAppendUninstallLink() {
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
InstalledPlugin plugin = createInstalled(createPluginInformation());
when(plugin.isUninstallable()).thenReturn(true);
@@ -178,7 +178,7 @@ class PluginDtoMapperTest {
@Test
void shouldAppendUninstallWithRestartLink() {
when(restarter.isSupported()).thenReturn(true);
when(subject.isPermitted("plugin:manage")).thenReturn(true);
when(subject.isPermitted("plugin:write")).thenReturn(true);
InstalledPlugin plugin = createInstalled(createPluginInformation());
when(plugin.isUninstallable()).thenReturn(true);

View File

@@ -602,12 +602,12 @@ class DefaultPluginManagerTest {
}
@Nested
class WithoutManagePermissions {
class WithoutWritePermissions {
@BeforeEach
void setUpSubject() {
ThreadContext.bind(subject);
doThrow(AuthorizationException.class).when(subject).checkPermission("plugin:manage");
doThrow(AuthorizationException.class).when(subject).checkPermission("plugin:write");
}
@AfterEach