mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 05:25:44 +01:00
improve unit tests for git remote command
This commit is contained in:
@@ -30,18 +30,23 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.api.CommitCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.ScmTransportProtocol;
|
||||
import org.eclipse.jgit.transport.Transport;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -96,6 +101,49 @@ public class AbstractRemoteCommandTestBase
|
||||
outgoingDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@After
|
||||
public void tearDownProtocol()
|
||||
{
|
||||
Transport.unregister(proto);
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUpProtocol()
|
||||
{
|
||||
|
||||
// store reference to handle weak references
|
||||
proto = new ScmTransportProtocol(new Provider<HookEventFacade>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public HookEventFacade get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}, new Provider<GitRepositoryHandler>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public GitRepositoryHandler get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
Transport.register(proto);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -162,6 +210,9 @@ public class AbstractRemoteCommandTestBase
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
/** Field description */
|
||||
protected GitRepositoryHandler handler;
|
||||
|
||||
/** Field description */
|
||||
protected Repository incomgingRepository;
|
||||
|
||||
@@ -181,5 +232,5 @@ public class AbstractRemoteCommandTestBase
|
||||
protected Repository outgoingRepository;
|
||||
|
||||
/** Field description */
|
||||
protected GitRepositoryHandler handler;
|
||||
private ScmTransportProtocol proto;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import static org.junit.Assert.*;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -89,6 +90,44 @@ public class GitIncomingCommandTest
|
||||
assertCommitsEquals(c1, cpr.getChangesets().get(0));
|
||||
assertCommitsEquals(c2, cpr.getChangesets().get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws GitAPIException
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetIncomingChangesetsWithAllreadyPullChangesets()
|
||||
throws IOException, GitAPIException, RepositoryException
|
||||
{
|
||||
write(outgoing, outgoingDirectory, "a.txt", "content of a.txt");
|
||||
|
||||
commit(outgoing, "added a");
|
||||
|
||||
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory), incomgingRepository);
|
||||
PullCommandRequest req = new PullCommandRequest();
|
||||
req.setRemoteRepository(outgoingRepository);
|
||||
pull.pull(req);
|
||||
|
||||
write(outgoing, outgoingDirectory, "b.txt", "content of b.txt");
|
||||
|
||||
RevCommit c2 = commit(outgoing, "added b");
|
||||
|
||||
GitIncomingCommand cmd = createCommand();
|
||||
IncomingCommandRequest request = new IncomingCommandRequest();
|
||||
|
||||
request.setRemoteRepository(outgoingRepository);
|
||||
|
||||
ChangesetPagingResult cpr = cmd.getIncomingChangesets(request);
|
||||
|
||||
assertNotNull(cpr);
|
||||
|
||||
assertEquals(1, cpr.getTotal());
|
||||
assertCommitsEquals(c2, cpr.getChangesets().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -114,7 +153,7 @@ public class GitIncomingCommandTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
* Check for correct behaviour
|
||||
*
|
||||
*
|
||||
* @throws GitAPIException
|
||||
@@ -122,6 +161,7 @@ public class GitIncomingCommandTest
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGetIncomingChangesetsWithUnrelatedRepository()
|
||||
throws IOException, RepositoryException, GitAPIException
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -53,8 +54,7 @@ import java.io.IOException;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitOutgoingCommandTest
|
||||
extends AbstractRemoteCommandTestBase
|
||||
public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -91,6 +91,47 @@ public class GitOutgoingCommandTest
|
||||
assertCommitsEquals(c2, cpr.getChangesets().get(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws GitAPIException
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetOutgoingChangesetsWithAllreadyPushedChanges()
|
||||
throws IOException, GitAPIException, RepositoryException
|
||||
{
|
||||
write(outgoing, outgoingDirectory, "a.txt", "content of a.txt");
|
||||
|
||||
commit(outgoing, "added a");
|
||||
|
||||
GitPushCommand push = new GitPushCommand(handler,
|
||||
new GitContext(outgoingDirectory),
|
||||
outgoingRepository);
|
||||
PushCommandRequest req = new PushCommandRequest();
|
||||
|
||||
req.setRemoteRepository(incomgingRepository);
|
||||
push.push(req);
|
||||
|
||||
write(outgoing, outgoingDirectory, "b.txt", "content of b.txt");
|
||||
|
||||
RevCommit c2 = commit(outgoing, "added b");
|
||||
|
||||
GitOutgoingCommand cmd = createCommand();
|
||||
OutgoingCommandRequest request = new OutgoingCommandRequest();
|
||||
|
||||
request.setRemoteRepository(incomgingRepository);
|
||||
|
||||
ChangesetPagingResult cpr = cmd.getOutgoingChangesets(request);
|
||||
|
||||
assertNotNull(cpr);
|
||||
|
||||
assertEquals(1, cpr.getTotal());
|
||||
assertCommitsEquals(c2, cpr.getChangesets().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -35,17 +35,12 @@ package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.ScmTransportProtocol;
|
||||
import org.eclipse.jgit.transport.Transport;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.api.PushResponse;
|
||||
|
||||
@@ -100,39 +95,6 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase
|
||||
assertEquals(o1, commits.next());
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUpProtocol()
|
||||
{
|
||||
|
||||
// store reference to handle weak references
|
||||
proto = new ScmTransportProtocol(new Provider<HookEventFacade>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public HookEventFacade get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}, new Provider<GitRepositoryHandler>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public GitRepositoryHandler get()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
Transport.register(proto);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user