1 package com
.intellij
.historyIntegrTests
;
4 import com
.intellij
.history
.FileRevisionTimestampComparator
;
5 import com
.intellij
.history
.LocalHistory
;
6 import com
.intellij
.history
.core
.LocalVcs
;
7 import com
.intellij
.history
.core
.revisions
.Revision
;
8 import com
.intellij
.history
.core
.storage
.Storage
;
9 import com
.intellij
.history
.utils
.RunnableAdapter
;
10 import com
.intellij
.openapi
.command
.CommandProcessor
;
11 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
12 import com
.intellij
.openapi
.fileTypes
.FileTypes
;
13 import com
.intellij
.openapi
.fileTypes
.StdFileTypes
;
14 import com
.intellij
.openapi
.vfs
.VirtualFile
;
17 import java
.io
.IOException
;
18 import java
.util
.List
;
20 public class BasicsTest
extends IntegrationTestCase
{
21 public void testComponentInitialization() {
22 assertNotNull(getVcsComponent());
25 public void testSaving() throws Exception
{
26 VirtualFile f
= root
.createChildData(null, "file.txt");
28 getVcsComponent().doCloseVcs();
30 File dir
= getVcsComponent().getStorageDir();
31 Storage s
= new Storage(dir
);
32 LocalVcs vcs
= new LocalVcs(s
);
34 assertTrue(vcs
.hasEntry(f
.getPath()));
37 public void testProcessingCommands() throws Exception
{
38 final VirtualFile
[] f
= new VirtualFile
[1];
40 CommandProcessor
.getInstance().executeCommand(myProject
, new RunnableAdapter() {
42 public void doRun() throws IOException
{
43 f
[0] = root
.createChildData(null, "f1.txt");
44 f
[0].setBinaryContent(new byte[]{1});
45 f
[0].setBinaryContent(new byte[]{2});
49 assertEquals(1, getVcsRevisionsFor(f
[0]).size());
52 public void testUpdatingOnFileTypesChange() throws Exception
{
53 VirtualFile f
= root
.createChildData(null, "file.xxx");
55 assertFalse(hasVcsEntry(f
));
57 FileTypeManager tm
= FileTypeManager
.getInstance();
58 tm
.registerFileType(FileTypes
.PLAIN_TEXT
, "xxx");
60 assertTrue(hasVcsEntry(f
));
62 tm
.removeAssociatedExtension(FileTypes
.PLAIN_TEXT
, "xxx");
64 assertFalse(hasVcsEntry(f
));
67 public void testPuttingUserLabel() throws Exception
{
68 VirtualFile f
= root
.createChildData(null, "f.txt");
70 LocalHistory
.putUserLabel(myProject
, "global");
72 assertEquals(2, getVcsRevisionsFor(f
).size());
73 assertEquals(3, getVcsRevisionsFor(root
).size());
75 LocalHistory
.putUserLabel(myProject
, f
, "file");
77 List
<Revision
> rr
= getVcsRevisionsFor(f
);
78 assertEquals(3, rr
.size());
79 assertEquals("file", rr
.get(0).getName());
80 assertFalse(rr
.get(0).getCauseChange().isSystemLabel());
81 assertEquals("global", rr
.get(1).getName());
82 assertFalse(rr
.get(1).getCauseChange().isSystemLabel());
84 rr
= getVcsRevisionsFor(root
);
85 assertEquals(3, rr
.size());
86 assertEquals("global", rr
.get(0).getName());
87 assertFalse(rr
.get(0).getCauseChange().isSystemLabel());
90 public void testPuttingSystemLabel() throws IOException
{
91 VirtualFile f
= root
.createChildData(null, "file.txt");
93 assertEquals(1, getVcsRevisionsFor(f
).size());
94 assertEquals(2, getVcsRevisionsFor(root
).size());
96 LocalHistory
.putSystemLabel(myProject
, "label");
98 List
<Revision
> rr
= getVcsRevisionsFor(f
);
99 assertEquals(2, rr
.size());
100 assertEquals("label", rr
.get(0).getName());
101 assertTrue(rr
.get(0).getCauseChange().isSystemLabel());
103 rr
= getVcsRevisionsFor(root
);
104 assertEquals(3, rr
.size());
105 assertEquals("label", rr
.get(0).getName());
106 assertTrue(rr
.get(0).getCauseChange().isSystemLabel());
109 public void testPuttingLabelWithUnsavedDocuments() throws Exception
{
110 VirtualFile f
= root
.createChildData(null, "f.txt");
111 f
.setBinaryContent(new byte[]{1});
113 setDocumentTextFor(f
, new byte[] {2});
114 LocalHistory
.putSystemLabel(myProject
, "label");
116 assertEquals(2, getVcsContentOf(f
)[0]);
118 setDocumentTextFor(f
, new byte[] {3});
119 LocalHistory
.putUserLabel(myProject
, "label");
121 assertEquals(3, getVcsContentOf(f
)[0]);
123 setDocumentTextFor(f
, new byte[] {4});
124 LocalHistory
.putUserLabel(myProject
, f
, "label");
126 assertEquals(4, getVcsContentOf(f
)[0]);
129 public void testIsUnderControl() throws Exception
{
130 VirtualFile f1
= root
.createChildData(null, "file.txt");
131 VirtualFile f2
= root
.createChildData(null, "file.xxx");
133 assertTrue(LocalHistory
.isUnderControl(myProject
, f1
));
134 assertFalse(LocalHistory
.isUnderControl(myProject
, f2
));
137 public void testHasUnavailableContent() throws Exception
{
138 VirtualFile f
= root
.createChildData(null, "file.txt");
139 assertFalse(LocalHistory
.hasUnavailableContent(myProject
, f
));
141 f
.setBinaryContent(new byte[2 * 1024 * 1024]);
142 assertTrue(LocalHistory
.hasUnavailableContent(myProject
, f
));
145 public void testHasUnavailableContentForUnversionedFile() throws Exception
{
146 VirtualFile f
= root
.createChildData(null, "f");
147 assertFalse(LocalHistory
.hasUnavailableContent(myProject
, f
));
150 public void testHasUnavailableContentForDirectory() throws Exception
{
151 VirtualFile dir
= root
.createChildDirectory(null, "dir");
152 assertFalse(LocalHistory
.hasUnavailableContent(myProject
, dir
));
155 public void testContentAtDate() throws Exception
{
156 VirtualFile f
= root
.createChildData(null, "f.txt");
157 f
.setBinaryContent(new byte[]{1}, -1, 10);
158 f
.setBinaryContent(new byte[]{2}, -1, 20);
160 assertEquals(1, LocalHistory
.getByteContent(myProject
, f
, comparator(10))[0]);
161 assertNull(LocalHistory
.getByteContent(myProject
, f
, comparator(15)));
162 assertEquals(2, LocalHistory
.getByteContent(myProject
, f
, comparator(20))[0]);
163 assertNull(LocalHistory
.getByteContent(myProject
, f
, comparator(30)));
166 public void testContentAtDateForFilteredFilesIsNull() throws Exception
{
167 VirtualFile f
= root
.createChildData(null, "f.xxx");
168 f
.setBinaryContent(new byte[]{1}, -1, 10);
170 assertNull(LocalHistory
.getByteContent(myProject
, f
, comparator(10)));
173 public void testRevisionsIfThereWasFileThatBecameUnversioned() throws IOException
{
174 FileTypeManager
.getInstance().registerFileType(StdFileTypes
.PLAIN_TEXT
, "jjj");
175 VirtualFile f
= root
.createChildData(null, "f.jjj");
176 FileTypeManager
.getInstance().removeAssociatedExtension(StdFileTypes
.PLAIN_TEXT
, "jjj");
178 List
<Revision
> rr
= getVcsRevisionsFor(root
);
179 assertEquals(3, rr
.size());
181 assertNull(rr
.get(0).getEntry().findChild("f.jjj"));
182 assertNotNull(rr
.get(1).getEntry().findChild("f.jjj"));
183 assertNull(rr
.get(2).getEntry().findChild("f.jjj"));
187 private FileRevisionTimestampComparator
comparator(final long timestamp
) {
188 return new FileRevisionTimestampComparator() {
189 public boolean isSuitable(long revisionTimestamp
) {
190 return revisionTimestamp
== timestamp
;