mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
improve unit tests for git remote command
This commit is contained in:
@@ -30,18 +30,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.CommitCommand;
|
import org.eclipse.jgit.api.CommitCommand;
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
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.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
@@ -96,6 +101,49 @@ public class AbstractRemoteCommandTestBase
|
|||||||
outgoingDirectory);
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -162,6 +210,9 @@ public class AbstractRemoteCommandTestBase
|
|||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
protected GitRepositoryHandler handler;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected Repository incomgingRepository;
|
protected Repository incomgingRepository;
|
||||||
|
|
||||||
@@ -181,5 +232,5 @@ public class AbstractRemoteCommandTestBase
|
|||||||
protected Repository outgoingRepository;
|
protected Repository outgoingRepository;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected GitRepositoryHandler handler;
|
private ScmTransportProtocol proto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import static org.junit.Assert.*;
|
|||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -90,6 +91,44 @@ public class GitIncomingCommandTest
|
|||||||
assertCommitsEquals(c2, cpr.getChangesets().get(1));
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -114,7 +153,7 @@ public class GitIncomingCommandTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Check for correct behaviour
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @throws GitAPIException
|
* @throws GitAPIException
|
||||||
@@ -122,6 +161,7 @@ public class GitIncomingCommandTest
|
|||||||
* @throws RepositoryException
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testGetIncomingChangesetsWithUnrelatedRepository()
|
public void testGetIncomingChangesetsWithUnrelatedRepository()
|
||||||
throws IOException, RepositoryException, GitAPIException
|
throws IOException, RepositoryException, GitAPIException
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -53,8 +54,7 @@ import java.io.IOException;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
public class GitOutgoingCommandTest
|
public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
|
||||||
extends AbstractRemoteCommandTestBase
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,6 +91,47 @@ public class GitOutgoingCommandTest
|
|||||||
assertCommitsEquals(c2, cpr.getChangesets().get(1));
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,17 +35,12 @@ package sonia.scm.repository.spi;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.transport.ScmTransportProtocol;
|
import org.eclipse.jgit.transport.ScmTransportProtocol;
|
||||||
import org.eclipse.jgit.transport.Transport;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sonia.scm.repository.GitRepositoryHandler;
|
|
||||||
import sonia.scm.repository.RepositoryException;
|
import sonia.scm.repository.RepositoryException;
|
||||||
import sonia.scm.repository.api.PushResponse;
|
import sonia.scm.repository.api.PushResponse;
|
||||||
|
|
||||||
@@ -100,39 +95,6 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase
|
|||||||
assertEquals(o1, commits.next());
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user