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));
}
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));
}
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);
}
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()));
}
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();
}
}
Aggregations