Remove old property for default branch

This commit is contained in:
René Pfeuffer
2018-12-12 17:30:23 +01:00
parent ddc2cbbfab
commit dbbe467479
22 changed files with 148 additions and 342 deletions

View File

@@ -86,7 +86,7 @@ public class GitConfigResourceTest {
public void prepareEnvironment() {
GitConfig gitConfig = createConfiguration();
when(repositoryHandler.getConfig()).thenReturn(gitConfig);
GitRepositoryConfigResource gitRepositoryConfigResource = new GitRepositoryConfigResource(repositoryConfigMapper, repositoryManager, configurationStoreFactory);
GitRepositoryConfigResource gitRepositoryConfigResource = new GitRepositoryConfigResource(repositoryConfigMapper, repositoryManager, new GitRepositoryConfigStoreProvider(configurationStoreFactory));
GitConfigResource gitConfigResource = new GitConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler, of(gitRepositoryConfigResource));
dispatcher.getRegistry().addSingletonResource(gitConfigResource);
when(scmPathInfoStore.get().getApiRestUri()).thenReturn(baseUri);

View File

@@ -53,7 +53,7 @@ import static org.mockito.Mockito.when;
/**
* @author Sebastian Sdorra
*/
@RunWith(MockitoJUnitRunner.class)
@RunWith(MockitoJUnitRunner.Silent.class)
public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
@Mock

View File

@@ -1,163 +0,0 @@
/**
* Copyright (c) 2014, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
import sonia.scm.HandlerEventType;
/**
* Unit tests for {@link GitRepositoryModifyListener}.
*
* @author Sebastian Sdorra
*/
public class GitRepositoryModifyListenerTest {
private GitRepositoryModifyTestListener repositoryModifyListener;
/**
* Set up test object.
*/
@Before
public void setUpObjectUnderTest(){
repositoryModifyListener = new GitRepositoryModifyTestListener();
}
/**
* Tests happy path.
*/
@Test
public void testHandleEvent() {
Repository old = RepositoryTestData.createHeartOfGold("git");
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
Repository current = RepositoryTestData.createHeartOfGold("git");
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
repositoryModifyListener.handleEvent(event);
assertNotNull(repositoryModifyListener.repository);
assertSame(current, repositoryModifyListener.repository);
}
/**
* Tests with new default branch.
*/
@Test
public void testWithNewDefaultBranch() {
Repository old = RepositoryTestData.createHeartOfGold("git");
Repository current = RepositoryTestData.createHeartOfGold("git");
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
repositoryModifyListener.handleEvent(event);
assertNotNull(repositoryModifyListener.repository);
assertSame(current, repositoryModifyListener.repository);
}
/**
* Tests with non git repositories.
*/
@Test
public void testNonGitRepository(){
Repository old = RepositoryTestData.createHeartOfGold("hg");
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
Repository current = RepositoryTestData.createHeartOfGold("hg");
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
repositoryModifyListener.handleEvent(event);
assertNull(repositoryModifyListener.repository);
}
/**
* Tests without default branch.
*/
@Test
public void testWithoutDefaultBranch(){
Repository old = RepositoryTestData.createHeartOfGold("git");
Repository current = RepositoryTestData.createHeartOfGold("git");
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
repositoryModifyListener.handleEvent(event);
assertNull(repositoryModifyListener.repository);
}
/**
* Tests with non modify event.
*/
@Test
public void testNonModifyEvent(){
Repository old = RepositoryTestData.createHeartOfGold("git");
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
Repository current = RepositoryTestData.createHeartOfGold("git");
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "develop");
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.CREATE, current, old);
repositoryModifyListener.handleEvent(event);
assertNull(repositoryModifyListener.repository);
}
/**
* Tests with non git repositories.
*/
@Test
public void testNoModification(){
Repository old = RepositoryTestData.createHeartOfGold("git");
old.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
Repository current = RepositoryTestData.createHeartOfGold("git");
current.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "master");
RepositoryModificationEvent event = new RepositoryModificationEvent(HandlerEventType.MODIFY, current, old);
repositoryModifyListener.handleEvent(event);
assertNull(repositoryModifyListener.repository);
}
private static class GitRepositoryModifyTestListener extends GitRepositoryModifyListener {
private Repository repository;
@Override
protected void sendClearRepositoryCacheEvent(Repository repository) {
this.repository = repository;
}
}
}

View File

@@ -35,6 +35,9 @@ package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.After;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
/**
*
@@ -51,6 +54,7 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
public void close()
{
if (context != null) {
context.setConfig(new GitRepositoryConfig());
context.close();
}
}
@@ -65,7 +69,7 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
{
if (context == null)
{
context = new GitContext(repositoryDirectory, repository);
context = new GitContext(repositoryDirectory, repository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory()));
}
return context;

View File

@@ -35,9 +35,11 @@ package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.BlameLine;
import sonia.scm.repository.BlameResult;
import sonia.scm.repository.GitConstants;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import java.io.IOException;
@@ -73,7 +75,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
assertEquals("fcd0ef1831e4002ac43ea539f4094334c79ea9ec", result.getLine(1).getRevision());
// set default branch and test again
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
createContext().setConfig(new GitRepositoryConfig("test-branch"));
result = createCommand().getBlameResult(request);
assertNotNull(result);
assertEquals(1, result.getTotal());

View File

@@ -32,9 +32,11 @@
package sonia.scm.repository.spi;
import org.junit.Test;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.BrowserResult;
import sonia.scm.repository.FileObject;
import sonia.scm.repository.GitConstants;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import java.io.IOException;
import java.util.Collection;
@@ -78,7 +80,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
@Test
public void testExplicitDefaultBranch() throws IOException {
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
createContext().setConfig(new GitRepositoryConfig("test-branch"));
FileObject root = createCommand().getBrowserResult(new BrowseCommandRequest()).getFile();
assertNotNull(root);

View File

@@ -38,7 +38,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import sonia.scm.NotFoundException;
import sonia.scm.repository.GitConstants;
import sonia.scm.repository.GitRepositoryConfig;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -67,7 +67,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
assertEquals("a\nline for blame", execute(request));
// set default branch for repository and check again
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
createContext().setConfig(new GitRepositoryConfig("test-branch"));
assertEquals("a and b", execute(request));
}

View File

@@ -38,7 +38,9 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Ignore;
import org.junit.Test;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import java.io.IOException;
@@ -103,7 +105,7 @@ public class GitIncomingCommandTest
commit(outgoing, "added a");
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory, null), incomingRepository);
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())), incomingRepository);
PullCommandRequest req = new PullCommandRequest();
req.setRemoteRepository(outgoingRepository);
pull.pull(req);
@@ -187,7 +189,7 @@ public class GitIncomingCommandTest
*/
private GitIncomingCommand createCommand()
{
return new GitIncomingCommand(handler, new GitContext(incomingDirectory, null),
return new GitIncomingCommand(handler, new GitContext(incomingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())),
incomingRepository);
}
}

View File

@@ -36,9 +36,11 @@ package sonia.scm.repository.spi;
import com.google.common.io.Files;
import org.junit.Test;
import sonia.scm.event.ScmEventBus;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.GitConstants;
import sonia.scm.repository.ClearRepositoryCacheEvent;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.repository.Modifications;
import java.io.File;
@@ -78,7 +80,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
assertTrue(result.getChangesets().stream().allMatch(r -> r.getBranches().isEmpty()));
// set default branch and fetch again
repository.setProperty(GitConstants.PROPERTY_DEFAULT_BRANCH, "test-branch");
createContext().setConfig(new GitRepositoryConfig("test-branch"));
result = createCommand().getChangesets(new LogCommandRequest());

View File

@@ -18,8 +18,8 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
@Before
public void init() {
incomingModificationsCommand = new GitModificationsCommand(new GitContext(incomingDirectory, null), incomingRepository);
outgoingModificationsCommand = new GitModificationsCommand(new GitContext(outgoingDirectory, null), outgoingRepository);
incomingModificationsCommand = new GitModificationsCommand(new GitContext(incomingDirectory, null, null), incomingRepository);
outgoingModificationsCommand = new GitModificationsCommand(new GitContext(outgoingDirectory, null, null), outgoingRepository);
}
@Test
@@ -63,12 +63,12 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
}
void pushOutgoingAndPullIncoming() throws IOException {
GitPushCommand cmd = new GitPushCommand(handler, new GitContext(outgoingDirectory, null),
GitPushCommand cmd = new GitPushCommand(handler, new GitContext(outgoingDirectory, null, null),
outgoingRepository);
PushCommandRequest request = new PushCommandRequest();
request.setRemoteRepository(incomingRepository);
cmd.push(request);
GitPullCommand pullCommand = new GitPullCommand(handler, new GitContext(incomingDirectory, null),
GitPullCommand pullCommand = new GitPullCommand(handler, new GitContext(incomingDirectory, null, null),
incomingRepository);
PullCommandRequest pullRequest = new PullCommandRequest();
pullRequest.setRemoteRepository(incomingRepository);

View File

@@ -38,7 +38,9 @@ package sonia.scm.repository.spi;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import java.io.IOException;
@@ -104,7 +106,7 @@ public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
commit(outgoing, "added a");
GitPushCommand push = new GitPushCommand(handler,
new GitContext(outgoingDirectory, null),
new GitContext(outgoingDirectory, null, null),
outgoingRepository);
PushCommandRequest req = new PushCommandRequest();
@@ -158,7 +160,7 @@ public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
*/
private GitOutgoingCommand createCommand()
{
return new GitOutgoingCommand(handler, new GitContext(outgoingDirectory, null),
return new GitOutgoingCommand(handler, new GitContext(outgoingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())),
outgoingRepository);
}
}

View File

@@ -98,7 +98,7 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase
*/
private GitPushCommand createCommand()
{
return new GitPushCommand(handler, new GitContext(outgoingDirectory, null),
return new GitPushCommand(handler, new GitContext(outgoingDirectory, null, null),
outgoingRepository);
}
}