Author: adietish
Date: 2011-08-19 12:22:55 -0400 (Fri, 19 Aug 2011)
New Revision: 34096
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/META-INF/MANIFEST.MF
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestUtils.java
Log:
[JBIDE-9513] implementing push test
Modified: trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/META-INF/MANIFEST.MF 2011-08-19
16:22:44 UTC (rev 34095)
+++ trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/META-INF/MANIFEST.MF 2011-08-19
16:22:55 UTC (rev 34096)
@@ -10,6 +10,7 @@
org.eclipse.jgit;bundle-version="[1.1.0,2.0.0)",
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)",
+ org.eclipse.core.filesystem;bundle-version="1.3.100",
org.junit;bundle-version="[4.8.2,5.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java 2011-08-19
16:22:44 UTC (rev 34095)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/EGitUtilsTest.java 2011-08-19
16:22:55 UTC (rev 34096)
@@ -1,28 +1,26 @@
package org.jboss.ide.eclipse.as.egit.internal.test;
import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.RepositoryCache;
-import org.eclipse.egit.core.op.AddToIndexOperation;
import org.eclipse.egit.core.op.CloneOperation;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
-import org.jboss.ide.eclipse.as.egit.core.EgitUtils;
+import org.jboss.ide.eclipse.as.egit.core.EGitUtils;
import org.jboss.ide.eclipse.as.egit.internal.test.util.MockSystemReader;
import org.jboss.ide.eclipse.as.egit.internal.test.util.TestProject;
import org.jboss.ide.eclipse.as.egit.internal.test.util.TestRepository;
@@ -33,83 +31,99 @@
public class EGitUtilsTest {
+ private static final String GIT_EMAIL = "dummyUser(a)redhat.com";
+
+ private static final String GIT_USER = "dummyUser";
+
protected final TestUtils testUtils = new TestUtils();
- private List<IResource> resources = new ArrayList<IResource>();
private File gitDir;
private TestRepository testRepository;
- private Repository repository;
private TestProject testProject;
- private IProject project;
private TestRepository clonedTestRepository;
+ private IFile testFile;
+
@Before
public void setUp() throws Exception {
Activator.getDefault().getRepositoryCache().clear();
+ createMockSystemReader();
+
this.testProject = new TestProject(true);
- this.project = testProject.getProject();
+ this.testFile = testUtils.addFileToProject(testProject.getProject(), "a.txt",
"1234");
- createMockSystemReader();
-
this.gitDir = createGitDir(testProject);
this.testRepository = new TestRepository(gitDir);
- this.repository = testRepository.getRepository();
- testRepository.connect(project);
+ setUserAndEmail(testRepository);
+ testRepository.connect(testProject.getProject());
+ testRepository.addAndCommit(testProject.getProject(), testFile.getLocation().toFile(),
"commit");
+
+ this.clonedTestRepository = cloneRepository(testRepository.getRepository());
+ }
- this.clonedTestRepository = cloneRepository(repository);
+ private void setUserAndEmail(TestRepository testRepository) {
+ StoredConfig config = testRepository.getRepository().getConfig();
+ config.setString(ConfigConstants.CONFIG_USER_SECTION, null,
ConfigConstants.CONFIG_KEY_NAME,
+ GIT_USER);
+ config.setString(ConfigConstants.CONFIG_USER_SECTION, null,
ConfigConstants.CONFIG_KEY_EMAIL,
+ GIT_EMAIL);
}
private TestRepository cloneRepository(Repository repository) throws URISyntaxException,
InvocationTargetException,
InterruptedException, IOException {
URIish uri = new URIish("file:///" + repository.getDirectory().toString());
- String repoParent = repository.getDirectory().getParent();
+ File workspaceDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
File clonedRepositoryFile =
- new File(repoParent, "clonedRepository-" +
String.valueOf(System.currentTimeMillis()));
+ new File(workspaceDir, "clonedRepository-" +
String.valueOf(System.currentTimeMillis()));
CloneOperation clop =
- new CloneOperation(uri, true, null, clonedRepositoryFile,
"refs/heads/master", "origin", 0);
+ new CloneOperation(uri, true, null, clonedRepositoryFile, Constants.R_HEADS +
Constants.MASTER,
+ Constants.DEFAULT_REMOTE_NAME, 0);
clop.run(null);
RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache();
- Repository clonedRepository =
- repositoryCache.lookupRepository(new File(clonedRepositoryFile, Constants.DOT_GIT));
- return new TestRepository(clonedRepository);
+ Repository clonedRepository = repositoryCache
+ .lookupRepository(new File(clonedRepositoryFile, Constants.DOT_GIT));
+ TestRepository testRepository = new TestRepository(clonedRepository);
+ // Repository clonedRepository = new FileRepository(new
+ // File(clonedRepositoryFile, Constants.DOT_GIT));
+ // TestRepository testRepository = new TestRepository(clonedRepository);
+ // we push to branch "test" of repository2
+ // RefUpdate createBranch = testRepository.getRepository().updateRef(
+ // "refs/heads/test");
+ // createBranch.setNewObjectId(testRepository.getRepository().resolve(
+ // "refs/heads/master"));
+ // createBranch.update();
+
+ return testRepository;
}
private void createMockSystemReader() {
MockSystemReader mockSystemReader = new MockSystemReader();
SystemReader.setInstance(mockSystemReader);
+ File workspaceFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile()
+ .getAbsoluteFile();
mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY,
- ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile()
- .getAbsoluteFile().toString());
+ workspaceFile.toString());
}
private File createGitDir(TestProject testProject) throws IOException {
- IPath workspaceRoot = project.getWorkspace().getRoot().getRawLocation();
- // IPath randomFolder =
- // workspaceRoot.append(String.valueOf(System.currentTimeMillis()));
- // File gitDir = new File(randomFolder.toFile(), Constants.DOT_GIT);
- File gitDir = new File(workspaceRoot.toFile(), Constants.DOT_GIT);
- if (gitDir.exists()) {
- // guard
- FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
- }
- return gitDir;
+ return new File(testProject.getProject().getLocation().toFile(), Constants.DOT_GIT);
}
@After
public void tearDown() throws Exception {
cleanupRepository(testRepository);
cleanupRepository(clonedTestRepository);
-
+
testProject.dispose();
- project = null;
Activator.getDefault().getRepositoryCache().clear();
}
private static void cleanupRepository(TestRepository testRepository) throws IOException
{
File repositoryDirectory = testRepository.getRepository().getDirectory();
- if (repositoryDirectory.exists()) {
- FileUtils.delete(repositoryDirectory, FileUtils.RECURSIVE | FileUtils.RETRY);
+ File repositoryParent = repositoryDirectory.getParentFile();
+ if (repositoryParent.exists()) {
+ FileUtils.delete(repositoryParent, FileUtils.RECURSIVE | FileUtils.RETRY);
}
testRepository.dispose();
}
@@ -118,25 +132,42 @@
public void canCommitFileInProject() throws Exception {
IFile file = testUtils.addFileToProject(
testProject.getProject(),
- "a.txt", "some text");
- resources.add(file);
- new AddToIndexOperation(resources).execute(null);
+ "b.txt", "some text");
+ addToRepository(file, testRepository);
- EgitUtils.commit(project, null);
+ EGitUtils.commit(testProject.getProject(), null);
- testUtils.assertRepositoryContainsFiles(repository, new String[] {
testUtils.getRepositoryPath(file) });
+ testUtils.assertRepositoryContainsFiles(testRepository.getRepository(),
+ new String[] { testUtils.getRepositoryPath(file),
testUtils.getRepositoryPath(testFile) });
}
@Test
public void canPushRepoToAntoherRepo() throws Exception {
- IFile file = testUtils.addFileToProject(testProject.getProject(), "a.txt",
"some text");
- resources.add(file);
- new AddToIndexOperation(resources).execute(null);
- EgitUtils.commit(project, null);
- EgitUtils.push(clonedTestRepository.getRepository(), null);
+ String clonedFilePath = testUtils.getRepositoryPath(testFile);
+ File clonedFile = new File(clonedFilePath);
+ FileWriter writer = new FileWriter(clonedFile);
+ writer.write("4321");
+ writer.close();
- testUtils.assertRepositoryContainsFiles(repository, new String[] {
testUtils.getRepositoryPath(file) });
+ new Git(clonedTestRepository.getRepository())
+ .commit()
+ .setCommitter(GIT_USER, GIT_EMAIL)
+ .setMessage("commit")
+ .call();
+
+ EGitUtils.push(clonedTestRepository.getRepository(), null);
+
+ testUtils.assertRepositoryContainsFilesWithContent(
+ testRepository.getRepository(),
+ testUtils.getRepositoryPath(testFile),
+ "4321");
+ }
+
+ private void addToRepository(IFile file, TestRepository testRepository) throws
IOException, CoreException {
+ // List<IResource> resources = new ArrayList<IResource>();
+ // resources.add(file);
+ // new AddToIndexOperation(resources).execute(null);
+ testRepository.track(new File(file.getLocation().toOSString()));
}
-
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java 2011-08-19
16:22:44 UTC (rev 34095)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestRepository.java 2011-08-19
16:22:55 UTC (rev 34096)
@@ -48,7 +48,7 @@
/**
* Helper class for creating and filling a test repository
- *
+ *
*/
public class TestRepository {
@@ -58,7 +58,7 @@
/**
* Creates a new test repository
- *
+ *
* @param gitDir
* @throws IOException
*/
@@ -80,7 +80,7 @@
/**
* Creates a test repository from an existing Repository
- *
+ *
* @param repository
* @throws IOException
*/
@@ -105,7 +105,7 @@
/**
* create an initial commit containing a file "dummy" in the
- *
+ *
* @param message
* commit message
* @return commit object
@@ -129,7 +129,7 @@
/**
* Create a file or get an existing one
- *
+ *
* @param project
* instance of project inside with file will be created
* @param name
@@ -151,7 +151,7 @@
/**
* Track, add to index and finally commit given file
- *
+ *
* @param project
* @param file
* @param commitMessage
@@ -169,7 +169,7 @@
/**
* Appends file content to given file, then track, add to index and finally
* commit it.
- *
+ *
* @param project
* @param file
* @param content
@@ -186,7 +186,7 @@
/**
* Appends file content to given file, then track, add to index and finally
* commit it.
- *
+ *
* @param project
* @param file
* @param content
@@ -205,11 +205,11 @@
/**
* Commits the current index
- *
+ *
* @param message
* commit message
* @return commit object
- *
+ *
* @throws NoHeadException
* @throws NoMessageException
* @throws UnmergedPathException
@@ -231,13 +231,13 @@
/**
* Adds file to version control
- *
+ *
* @param file
* @throws IOException
*/
public void track(File file) throws IOException {
- String repoPath = getRepoRelativePath(new Path(file.getPath())
- .toString());
+ String repoPath = getRepoRelativePath(
+ new Path(file.getPath()).toString());
try {
new Git(repository).add().addFilepattern(repoPath).call();
} catch (NoFilepatternException e) {
@@ -247,7 +247,7 @@
/**
* Creates a new branch and immediately checkout it.
- *
+ *
* @param refName
* starting point for the new branch
* @param newRefName
@@ -260,7 +260,7 @@
/**
* Creates a new branch
- *
+ *
* @param refName
* starting point for the new branch
* @param newRefName
@@ -286,7 +286,7 @@
/**
* Checkouts branch
- *
+ *
* @param refName
* full name of branch
* @throws CoreException
@@ -297,7 +297,7 @@
/**
* Adds the given file to the index
- *
+ *
* @param project
* @param file
* @throws Exception
@@ -307,10 +307,9 @@
addToIndex(iFile);
}
-
/**
* Adds the given file to the index
- *
+ *
* @param file
* @throws CoreException
* @throws IOException
@@ -326,7 +325,7 @@
/**
* Appends content to end of given file.
- *
+ *
* @param file
* @param content
* @throws IOException
@@ -337,7 +336,7 @@
/**
* Appends content to end of given file.
- *
+ *
* @param file
* @param content
* @throws IOException
@@ -348,7 +347,7 @@
/**
* Appends content to given file.
- *
+ *
* @param file
* @param content
* @param append
@@ -363,7 +362,7 @@
/**
* Appends content to given file.
- *
+ *
* @param file
* @param content
* @param append
@@ -385,7 +384,7 @@
/**
* Checks if a file with the given path exists in the HEAD tree
- *
+ *
* @param path
* @return true if the file exists
* @throws IOException
@@ -464,7 +463,7 @@
/**
* Connect a project to this repository
- *
+ *
* @param project
* @throws CoreException
*/
@@ -476,7 +475,7 @@
/**
* Disconnects provider from project
- *
+ *
* @param project
* @throws CoreException
*/
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestUtils.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestUtils.java 2011-08-19
16:22:44 UTC (rev 34095)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.egit.test/src/org/jboss/ide/eclipse/as/egit/internal/test/util/TestUtils.java 2011-08-19
16:22:55 UTC (rev 34096)
@@ -257,6 +257,9 @@
public String getRepositoryPath(IResource resource) {
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
+ if (mapping == null) {
+ throw new IllegalArgumentException(resource + " is not in any repository");
+ }
return mapping.getRepoRelativePath(resource);
}