Search in sources :

Example 11 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant 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)

Example 12 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenComparingFileAndContainer.

/**
 * It is possible to have a local file that has same name as a remote
 * folder. In some cases that two resources can be compared. In this case
 * compare method should return false, because they aren't same resources
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenComparingFileAndContainer() {
    // when
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(null);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(true);
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : IFile(org.eclipse.core.resources.IFile) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 13 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnTrueWhenShortContentIsDifferent.

/**
 * Comparing two files that have the same content and content length should
 * return true
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnTrueWhenShortContentIsDifferent() throws Exception {
    // when
    byte[] localContent = "very long long content".getBytes("UTF-8");
    byte[] remoteContent = "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(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
    assertTrue(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 14 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantTreeSubscriberTest method getRemoteVariant.

private IResourceVariant getRemoteVariant(GitResourceVariantTreeSubscriber subscriber, IResource resource) throws TeamException {
    IResourceVariantTree tree = subscriber.getRemoteTree();
    assertNotNull(tree);
    assertTrue(tree instanceof GitRemoteResourceVariantTree);
    IResourceVariant resourceVariant = tree.getResourceVariant(resource);
    assertNotNull(resourceVariant);
    assertTrue(resourceVariant instanceof GitRemoteResource);
    return resourceVariant;
}
Also used : IResourceVariantTree(org.eclipse.team.core.variants.IResourceVariantTree) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant)

Example 15 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantTreeSubscriberTest method testSyncMasterAndBranch.

@Test
public void testSyncMasterAndBranch() throws Exception {
    GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(MASTER, BRANCH, false);
    grvts.init(new NullProgressMonitor());
    IResourceVariant actualSource = getSourceVariant(grvts, changedFile, false);
    IResourceVariant actualBase = getBaseVariant(grvts, changedFile);
    IResourceVariant actualRemote = getRemoteVariant(grvts, changedFile);
    assertVariantMatchCommit(actualSource, commitMaster);
    assertVariantMatchCommit(actualBase, initialCommit);
    assertVariantMatchCommit(actualRemote, commitBranch);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Aggregations

IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)21 Test (org.junit.Test)13 IFile (org.eclipse.core.resources.IFile)9 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)9 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IResourceVariantTree (org.eclipse.team.core.variants.IResourceVariantTree)4 IResource (org.eclipse.core.resources.IResource)3 File (java.io.File)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RemoteResourceVariant (org.eclipse.team.internal.ecf.core.variants.RemoteResourceVariant)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IContainer (org.eclipse.core.resources.IContainer)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 CoreException (org.eclipse.core.runtime.CoreException)1