Search in sources :

Example 11 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet 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 12 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet 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)

Example 13 with GitSynchronizeDataSet

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

the class GitResourceVariantTreeTest method shouldReturnNullResourceVariant.

/**
 * Checks that getResourceVariant will not throw NPE for null argument. This
 * method is called with null argument when local or remote resource does
 * not exist.
 *
 * @throws Exception
 */
@Test
public void shouldReturnNullResourceVariant() throws Exception {
    // when
    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);
    // given
    GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(null, dataSet);
    // then
    assertNull(grvt.getResourceVariant(null));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Git(org.eclipse.jgit.api.Git) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) Test(org.junit.Test)

Example 14 with GitSynchronizeDataSet

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

the class GitSubscriberResourceMappingContextTest method prepareContext.

private RemoteResourceMappingContext prepareContext(String srcRev, String dstRev) throws Exception {
    GitSynchronizeData gsd = new GitSynchronizeData(repo, srcRev, dstRev, true);
    GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
    GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsds);
    subscriber.init(new NullProgressMonitor());
    return new GitSubscriberResourceMappingContext(subscriber, gsds);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)

Example 15 with GitSynchronizeDataSet

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

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenShortContentIsDifferent.

/**
 * Comparing two files that have same content length but having small
 * difference inside content should return false.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenShortContentIsDifferent() throws Exception {
    // when
    byte[] localContent = "very long long content".getBytes("UTF-8");
    // this typo should be here
    byte[] remoteContent = "very long lonk 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(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)

Aggregations

GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)29 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)26 Test (org.junit.Test)15 IFile (org.eclipse.core.resources.IFile)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)8 IResource (org.eclipse.core.resources.IResource)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 HashSet (java.util.HashSet)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)6 IOException (java.io.IOException)4 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)4 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)4 Git (org.eclipse.jgit.api.Git)4 Repository (org.eclipse.jgit.lib.Repository)4 File (java.io.File)3 SubscriberScopeManager (org.eclipse.team.core.subscribers.SubscriberScopeManager)3 LinkedHashSet (java.util.LinkedHashSet)2