mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
enhance NamespaceStrategy API / improve frontend validation and use namespace extension point in RenameRepository component
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 com.google.common.collect.Lists;
|
||||
@@ -68,7 +68,7 @@ class NamespaceStrategyResourceTest {
|
||||
}
|
||||
|
||||
private Set<NamespaceStrategy> allStrategies() {
|
||||
return strategies(new AwesomeNamespaceStrategy(), new SuperNamespaceStrategy(), new MegaNamespaceStrategy());
|
||||
return strategies(new AwesomeNamespaceStrategy(), new SuperNamespaceStrategy(), new MegaNamespaceStrategy());
|
||||
}
|
||||
|
||||
private Set<NamespaceStrategy> strategies(NamespaceStrategy... strategies) {
|
||||
@@ -80,6 +80,11 @@ class NamespaceStrategyResourceTest {
|
||||
public String createNamespace(Repository repository) {
|
||||
return "awesome";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SuperNamespaceStrategy implements NamespaceStrategy {
|
||||
@@ -87,6 +92,11 @@ class NamespaceStrategyResourceTest {
|
||||
public String createNamespace(Repository repository) {
|
||||
return "super";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MegaNamespaceStrategy implements NamespaceStrategy {
|
||||
@@ -94,5 +104,10 @@ class NamespaceStrategyResourceTest {
|
||||
public String createNamespace(Repository repository) {
|
||||
return "mega";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.shiro.subject.SimplePrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
@@ -40,7 +41,9 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import sonia.scm.PageResult;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.CustomNamespaceStrategy;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.NamespaceStrategy;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryInitializer;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
@@ -56,6 +59,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
@@ -72,6 +76,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyObject;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -105,6 +110,8 @@ public class RepositoryRootResourceTest extends RepositoryTestBase {
|
||||
private RepositoryInitializer repositoryInitializer;
|
||||
@Mock
|
||||
private ScmConfiguration configuration;
|
||||
@Mock
|
||||
private Set<NamespaceStrategy> strategies;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<Predicate<Repository>> filterCaptor;
|
||||
@@ -129,6 +136,7 @@ public class RepositoryRootResourceTest extends RepositoryTestBase {
|
||||
when(serviceFactory.create(any(Repository.class))).thenReturn(service);
|
||||
when(scmPathInfoStore.get()).thenReturn(uriInfo);
|
||||
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/x/y"));
|
||||
doReturn(ImmutableSet.of(new CustomNamespaceStrategy()).iterator()).when(strategies).iterator();
|
||||
SimplePrincipalCollection trillian = new SimplePrincipalCollection("trillian", REALM);
|
||||
trillian.add(new User("trillian"), REALM);
|
||||
shiro.setSubject(
|
||||
|
||||
@@ -21,11 +21,12 @@
|
||||
* 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.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.shiro.util.ThreadContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -34,7 +35,9 @@ import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.repository.CustomNamespaceStrategy;
|
||||
import sonia.scm.repository.HealthCheckFailure;
|
||||
import sonia.scm.repository.NamespaceStrategy;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
@@ -42,13 +45,16 @@ import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.repository.api.ScmProtocol;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.stream.Stream.of;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
@@ -75,6 +81,8 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
private ScmPathInfo uriInfo;
|
||||
@Mock
|
||||
private ScmConfiguration configuration;
|
||||
@Mock
|
||||
private Set<NamespaceStrategy> strategies;
|
||||
|
||||
@InjectMocks
|
||||
private RepositoryToRepositoryDtoMapperImpl mapper;
|
||||
@@ -88,6 +96,7 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
when(scmPathInfoStore.get()).thenReturn(uriInfo);
|
||||
when(configuration.getNamespaceStrategy()).thenReturn("CustomNamespaceStrategy");
|
||||
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/x/y"));
|
||||
doReturn(ImmutableSet.of(new CustomNamespaceStrategy()).iterator()).when(strategies).iterator();
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -66,12 +66,17 @@ class NamespaceStrategyProviderTest {
|
||||
return new LinkedHashSet<>(Arrays.asList(new Trillian(), new Zaphod(), new Arthur()));
|
||||
}
|
||||
|
||||
private static class Trillian implements NamespaceStrategy{
|
||||
private static class Trillian implements NamespaceStrategy {
|
||||
|
||||
@Override
|
||||
public String createNamespace(Repository repository) {
|
||||
return "trillian";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Zaphod implements NamespaceStrategy {
|
||||
@@ -80,6 +85,11 @@ class NamespaceStrategyProviderTest {
|
||||
public String createNamespace(Repository repository) {
|
||||
return "zaphod";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Arthur implements NamespaceStrategy {
|
||||
@@ -88,6 +98,11 @@ class NamespaceStrategyProviderTest {
|
||||
public String createNamespace(Repository repository) {
|
||||
return "arthur";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -30,7 +30,7 @@ import sonia.scm.ScmConstraintViolationException;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class NamespaceStrategyValidatorTest {
|
||||
|
||||
@@ -52,6 +52,11 @@ class NamespaceStrategyValidatorTest {
|
||||
public String createNamespace(Repository repository) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeChanged() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user