diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2013-04-01 14:41:51 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2013-04-01 14:41:51 -0700 |
commit | 2bd2b7c2623d4266384e890271869efc044aabff (patch) | |
tree | 0b31f50e55975b6354ed458314e17b4441bb4e17 /plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCommitTest.java | |
parent | 1d526b16d476792ca7ce47616d55833115e8d6ab (diff) | |
download | idea-2bd2b7c2623d4266384e890271869efc044aabff.tar.gz |
Snapshot ee98b298267d0e09d2cd2f0731b6480a56dd48e7 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I4515f72af131fdea9fc6905a4dc0fe9532409a81
Diffstat (limited to 'plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCommitTest.java')
-rw-r--r-- | plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCommitTest.java | 492 |
1 files changed, 492 insertions, 0 deletions
diff --git a/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCommitTest.java b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCommitTest.java new file mode 100644 index 000000000000..f4da04ea201a --- /dev/null +++ b/plugins/svn4idea/testSource/org/jetbrains/idea/svn/SvnCommitTest.java @@ -0,0 +1,492 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.idea.svn; + +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vcs.*; +import com.intellij.openapi.vcs.changes.Change; +import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.NullableFunction; +import junit.framework.Assert; +import org.jetbrains.annotations.Nullable; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + +/** + * Created with IntelliJ IDEA. + * User: Irina.Chernushina + * Date: 2/28/13 + * Time: 11:59 AM + */ +public class SvnCommitTest extends Svn17TestCase { + private SvnVcs myVcs; + private VcsDirtyScopeManager myDirtyScopeManager; + private ChangeListManager myChangeListManager; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + myVcs = SvnVcs.getInstance(myProject); + myDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); + myChangeListManager = ChangeListManager.getInstance(myProject); + } + + @Test + public void testSimpleCommit() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + run2variants(new MyRunner() { + private String myName = "a.txt"; + + @Override + protected void run() throws Exception { + final VirtualFile file = createFileInCommand(myWorkingCopyDir, myName, "123"); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFile(file, FileStatus.ADDED); + } + + @Override + protected void cleanup() throws Exception { + myName = "b.txt"; + } + }); + } + + @Test + public void testCommitRename() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + run2variants(new MyRunner() { + private String myName = "a.txt"; + private String myRenamedName = "aRenamed.txt"; + + @Override + protected void run() throws Exception { + final VirtualFile file = createFileInCommand(myWorkingCopyDir, myName, "123"); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFile(file, FileStatus.ADDED); + + renameFileInCommand(file, myRenamedName); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFile(file, FileStatus.MODIFIED); + } + + @Override + protected void cleanup() throws Exception { + myName = "b.txt"; + myRenamedName = "bRenamed.txt"; + } + }); + } + + @Test + public void testRenameReplace() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + run2variants(new MyRunner() { + private String myName = "a.txt"; + private String myName2 = "aRenamed.txt"; + + @Override + protected void run() throws Exception { + final VirtualFile file = createFileInCommand(myWorkingCopyDir, myName, "123"); + final VirtualFile file2 = createFileInCommand(myWorkingCopyDir, myName2, "1235"); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(file, file2); + + renameFileInCommand(file, file.getName() + "7.txt"); + renameFileInCommand(file2, myName); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(file, file2); + } + + @Override + protected void cleanup() throws Exception { + myName = "b.txt"; + myName2 = "bRenamed.txt"; + } + }); + } + + @Test + public void testRenameFolder() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + run2variants(new MyRunner() { + private String folder = "f"; + + @Override + protected void run() throws Exception { + final VirtualFile dir = createDirInCommand(myWorkingCopyDir, folder); + final VirtualFile file = createFileInCommand(dir, "a.txt", "123"); + final VirtualFile file2 = createFileInCommand(dir, "b.txt", "1235"); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(dir, file, file2); + + renameFileInCommand(dir, dir.getName() + "dd"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(dir, file, file2); + } + + @Override + protected void cleanup() throws Exception { + folder = "f1"; + } + }); + } + + @Test + public void testCommitDeletion() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + run2variants(new MyRunner() { + private String folder = "f"; + + @Override + protected void run() throws Exception { + final VirtualFile dir = createDirInCommand(myWorkingCopyDir, folder); + final VirtualFile file = createFileInCommand(dir, "a.txt", "123"); + final VirtualFile file2 = createFileInCommand(dir, "b.txt", "1235"); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(dir, file, file2); + + final FilePath dirPath = new FilePathImpl(new File(dir.getPath()), true); + deleteFileInCommand(dir); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinPaths(dirPath); + } + + @Override + protected void cleanup() throws Exception { + folder = "f1"; + } + }); + } + + @Test + public void testSameRepoPlusInnerCopyCommitNative() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + prepareInnerCopy(false); + final MyRunner runner = new MyRunner() { + @Override + protected void run() throws Exception { + final File file1 = new File(myWorkingCopyDir.getPath(), "source/s1.txt"); + final File fileInner = new File(myWorkingCopyDir.getPath(), "source/inner1/inner2/inner/t11.txt"); + + Assert.assertTrue(file1.exists()); + Assert.assertTrue(fileInner.exists()); + final VirtualFile vf1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + final VirtualFile vf2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fileInner); + Assert.assertNotNull(vf1); + Assert.assertNotNull(vf2); + + editFileInCommand(vf1, "2317468732ghdwwe7y348rf"); + editFileInCommand(vf2, "2317468732ghdwwe7y348rf csdjcjksw"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + final HashSet<String> strings = checkinFiles(vf1, vf2); + System.out.println("" + StringUtil.join(strings, "\n")); + Assert.assertEquals(1, strings.size()); + } + + @Override + protected void cleanup() throws Exception { + } + }; + setNativeAcceleration(true); + runner.run(); + } + + @Test + public void testSameRepoPlusInnerCopyCommitSvnkit() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + prepareInnerCopy(false); + final MyRunner runner = new MyRunner() { + @Override + protected void run() throws Exception { + final File file1 = new File(myWorkingCopyDir.getPath(), "source/s1.txt"); + final File fileInner = new File(myWorkingCopyDir.getPath(), "source/inner1/inner2/inner/t11.txt"); + + Assert.assertTrue(file1.exists()); + Assert.assertTrue(fileInner.exists()); + final VirtualFile vf1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + final VirtualFile vf2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fileInner); + Assert.assertNotNull(vf1); + Assert.assertNotNull(vf2); + + editFileInCommand(vf1, "2317468732ghdwwe7y348rf"); + editFileInCommand(vf2, "2317468732ghdwwe7y348rf csdjcjksw"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + final HashSet<String> strings = checkinFiles(vf1, vf2); + System.out.println("" + StringUtil.join(strings, "\n")); + Assert.assertEquals(1, strings.size()); + } + + @Override + protected void cleanup() throws Exception { + } + }; + setNativeAcceleration(true); + runner.run(); + } + + @Test + public void testAnotherRepoPlusInnerCopyCommitNative() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + prepareInnerCopy(true); + final MyRunner runner = new MyRunner() { + @Override + protected void run() throws Exception { + final File file1 = new File(myWorkingCopyDir.getPath(), "source/s1.txt"); + final File fileInner = new File(myWorkingCopyDir.getPath(), "source/inner1/inner2/inner/t11.txt"); + + Assert.assertTrue(file1.exists()); + Assert.assertTrue(fileInner.exists()); + final VirtualFile vf1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + final VirtualFile vf2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fileInner); + Assert.assertNotNull(vf1); + Assert.assertNotNull(vf2); + + editFileInCommand(vf1, "2317468732ghdwwe7y348rf"); + editFileInCommand(vf2, "2317468732ghdwwe7y348rf csdjcjksw"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(vf1, vf2); + } + + @Override + protected void cleanup() throws Exception { + } + }; + setNativeAcceleration(true); + runner.run(); + } + + @Test + public void testAnotherRepoPlusInnerCopyCommitSvnkit() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + prepareInnerCopy(true); + final MyRunner runner = new MyRunner() { + @Override + protected void run() throws Exception { + final File file1 = new File(myWorkingCopyDir.getPath(), "source/s1.txt"); + final File fileInner = new File(myWorkingCopyDir.getPath(), "source/inner1/inner2/inner/t11.txt"); + + Assert.assertTrue(file1.exists()); + Assert.assertTrue(fileInner.exists()); + final VirtualFile vf1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + final VirtualFile vf2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fileInner); + Assert.assertNotNull(vf1); + Assert.assertNotNull(vf2); + + editFileInCommand(vf1, "2317468732ghdwwe7y348rf"); + editFileInCommand(vf2, "2317468732ghdwwe7y348rf csdjcjksw"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(vf1, vf2); + } + + @Override + protected void cleanup() throws Exception { + } + }; + setNativeAcceleration(true); + runner.run(); + } + + @Test + public void testPlusExternalCopyCommitNative() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + prepareExternal(); + final MyRunner runner = new MyRunner() { + @Override + protected void run() throws Exception { + final File file1 = new File(myWorkingCopyDir.getPath(), "source/s1.txt"); + final File fileInner = new File(myWorkingCopyDir.getPath(), "source/external/t11.txt"); + + Assert.assertTrue(file1.exists()); + Assert.assertTrue(fileInner.exists()); + final VirtualFile vf1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + final VirtualFile vf2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fileInner); + Assert.assertNotNull(vf1); + Assert.assertNotNull(vf2); + + editFileInCommand(vf1, "2317468732ghdwwe7y348rf"); + editFileInCommand(vf2, "2317468732ghdwwe7y348rf csdjcjksw"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(vf1, vf2); + } + + @Override + protected void cleanup() throws Exception { + } + }; + setNativeAcceleration(true); + runner.run(); + } + + @Test + public void testPlusExternalCopyCommitSvnkit() throws Exception { + enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); + enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); + prepareExternal(); + final MyRunner runner = new MyRunner() { + @Override + protected void run() throws Exception { + final File file1 = new File(myWorkingCopyDir.getPath(), "source/s1.txt"); + final File fileInner = new File(myWorkingCopyDir.getPath(), "source/external/t11.txt"); + + Assert.assertTrue(file1.exists()); + Assert.assertTrue(fileInner.exists()); + final VirtualFile vf1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + final VirtualFile vf2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fileInner); + Assert.assertNotNull(vf1); + Assert.assertNotNull(vf2); + + editFileInCommand(vf1, "2317468732ghdwwe7y348rf"); + editFileInCommand(vf2, "2317468732ghdwwe7y348rf csdjcjksw"); + + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + checkinFiles(vf1, vf2); + } + + @Override + protected void cleanup() throws Exception { + } + }; + setNativeAcceleration(false); + runner.run(); + } + + private void checkinPaths(FilePath... files) { + final List<Change> changes = new ArrayList<Change>(); + for (FilePath file : files) { + final Change change = myChangeListManager.getChange(file); + Assert.assertNotNull(change); + changes.add(change); + } + final List<VcsException> exceptions = myVcs.getCheckinEnvironment().commit(changes, "test comment list"); + Assert.assertTrue(exceptions == null || exceptions.isEmpty()); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + for (FilePath file : files) { + final Change changeA = myChangeListManager.getChange(file); + Assert.assertNull(changeA); + } + } + + private HashSet<String> checkinFiles(VirtualFile... files) { + final List<Change> changes = new ArrayList<Change>(); + for (VirtualFile file : files) { + final Change change = myChangeListManager.getChange(file); + Assert.assertNotNull(change); + changes.add(change); + } + final HashSet<String> feedback = new HashSet<String>(); + final List<VcsException> exceptions = myVcs.getCheckinEnvironment().commit(changes, "test comment list", + new NullableFunction<Object, Object>() { + @Nullable + @Override + public Object fun(Object o) { + return null; + } + }, feedback); + if (exceptions !=null && ! exceptions.isEmpty()) { + exceptions.get(0).printStackTrace(); + } + Assert.assertTrue(exceptions == null || exceptions.isEmpty()); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + + for (VirtualFile file : files) { + final Change changeA = myChangeListManager.getChange(file); + Assert.assertNull(changeA); + } + return feedback; + } + + private void checkinFile(VirtualFile file, FileStatus status) { + final Change change = myChangeListManager.getChange(file); + Assert.assertNotNull(change); + Assert.assertEquals(status, change.getFileStatus()); + final List<VcsException> exceptions = myVcs.getCheckinEnvironment().commit(Collections.singletonList(change), "test comment"); + Assert.assertTrue(exceptions == null || exceptions.isEmpty()); + myDirtyScopeManager.markEverythingDirty(); + myChangeListManager.ensureUpToDate(false); + final Change changeA = myChangeListManager.getChange(file); + Assert.assertNull(changeA); + } + + protected void run2variants(final MyRunner runner) throws Exception { + setNativeAcceleration(false); + runner.run(); + runner.cleanup(); + setNativeAcceleration(true); + runner.run(); + } + + private static abstract class MyRunner { + protected abstract void run() throws Exception; + protected abstract void cleanup() throws Exception; + } +} |