Search in sources :

Example 11 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenContentLengthIsDifferent.

/**
 * Compare() should return false when comparing two files with different
 * content length
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenContentLengthIsDifferent() throws Exception {
    // when
    byte[] shortContent = "short content".getBytes("UTF-8");
    byte[] longContent = "very long long content".getBytes("UTF-8");
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(longContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(shortContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 12 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenLongContentIsDifferent.

/**
 * Comparing two 'large' files that have same length and almost identical
 * content should return false.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenLongContentIsDifferent() throws Exception {
    // when
    byte[] localContent = new byte[8192];
    Arrays.fill(localContent, (byte) 'a');
    byte[] remoteContent = new byte[8192];
    Arrays.fill(remoteContent, (byte) 'a');
    remoteContent[8101] = 'b';
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 13 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantTreeSubscriberTest method createGitResourceVariantTreeSubscriber.

private GitResourceVariantTreeSubscriber createGitResourceVariantTreeSubscriber(String src, String dst, boolean includeLocal) throws IOException {
    GitSynchronizeData gsd = new GitSynchronizeData(testRepo.getRepository(), src, dst, includeLocal);
    GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
    return new GitResourceVariantTreeSubscriber(gsds);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)

Example 14 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantTreeTest method shouldReturnNullResourceVariant2.

/**
 * getResourceVariant() should return null when given resource doesn't exist
 * in repository.
 *
 * @throws Exception
 */
@Test
public void shouldReturnNullResourceVariant2() throws Exception {
    // when
    IPackageFragment iPackage = project.createPackage("org.egit.test");
    IType mainJava = project.createType(iPackage, "Main.java", "class Main {}");
    try (Git git = new Git(repo)) {
        git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
    }
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitSyncCache cache = GitSyncCache.getAllData(dataSet, new NullProgressMonitor());
    // given
    GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(cache, dataSet);
    // then
    assertNull(grvt.getResourceVariant(mainJava.getResource()));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) Git(org.eclipse.jgit.api.Git) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 15 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitResourceVariantTreeTest method shouldReturnTwoRoots.

/**
 * When we have two or more project associated with repository, roots()
 * method should return list of project. In this case we have two project
 * associated with particular repository, therefore '2' value is expected.
 *
 * @throws Exception
 */
@Test
public void shouldReturnTwoRoots() throws Exception {
    // when
    // create second project
    TestProject secondProject = new TestProject(true, "Project-2");
    try {
        IProject secondIProject = secondProject.project;
        // add connect project with repository
        new ConnectProviderOperation(secondIProject, gitDir).execute(null);
        try (Git git = new Git(repo)) {
            git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
        }
        GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
        GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
        // given
        GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
        // then
        IResource[] roots = grvt.roots();
        // sort in order to be able to assert the project instances
        Arrays.sort(roots, new Comparator<IResource>() {

            @Override
            public int compare(IResource r1, IResource r2) {
                String path1 = r1.getFullPath().toString();
                String path2 = r2.getFullPath().toString();
                return path1.compareTo(path2);
            }
        });
        assertEquals(2, roots.length);
        IResource actualProject = roots[0];
        assertEquals(this.project.project, actualProject);
        IResource actualProject1 = roots[1];
        assertEquals(secondIProject, actualProject1);
    } finally {
        secondProject.dispose();
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProject(org.eclipse.core.resources.IProject) Git(org.eclipse.jgit.api.Git) TestProject(org.eclipse.egit.core.test.TestProject) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Aggregations

GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)42 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)26 Test (org.junit.Test)15 Repository (org.eclipse.jgit.lib.Repository)14 IResource (org.eclipse.core.resources.IResource)13 IFile (org.eclipse.core.resources.IFile)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)9 IOException (java.io.IOException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)5 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3