Search in sources :

Example 6 with GitSynchronizeDataSet

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

the class GitResourceVariantComparatorTest method shouldReturnTrueWhenLongContentLengthIsDifferent.

/**
 * Compare two 'large' files that have same content length and content
 * should return true.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnTrueWhenLongContentLengthIsDifferent() throws Exception {
    // when
    byte[] localContent = new byte[8192];
    Arrays.fill(localContent, (byte) 'a');
    byte[] remoteContent = new byte[8192];
    Arrays.fill(remoteContent, (byte) 'a');
    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 7 with GitSynchronizeDataSet

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

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenLongContentLengthIsDifferent.

/**
 * Comparing two 'large' files that have different length but same content
 * should return false.
 * <p>
 * This and previous three test cases cover almost the same functionality
 * but they are covering all return points in compare methods that can be
 * used when comparing files content
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenLongContentLengthIsDifferent() throws Exception {
    // when
    byte[] localContent = new byte[8192];
    Arrays.fill(localContent, (byte) 'a');
    byte[] remoteContent = new byte[8200];
    Arrays.fill(remoteContent, (byte) 'a');
    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 8 with GitSynchronizeDataSet

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

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

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

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