30
30
import java .io .IOException ;
31
31
import java .net .URISyntaxException ;
32
32
import java .nio .channels .FileChannel ;
33
+ import java .nio .file .Files ;
34
+ import java .nio .file .Path ;
33
35
import java .util .ArrayList ;
34
36
import java .util .Arrays ;
35
37
import java .util .Collections ;
51
53
import static org .opengrok .indexer .condition .RepositoryInstalled .Type .CVS ;
52
54
53
55
/**
54
- *
56
+ * Tests for {@link CVSRepository} functionality.
55
57
* @author austvik
56
58
*/
57
59
@ EnabledForRepository (CVS )
@@ -120,7 +122,7 @@ public static void runCvsCommand(File reposRoot, String... args) {
120
122
@ Test
121
123
void testGetBranchNoBranch () throws Exception {
122
124
setUpTestRepository ();
123
- File root = new File (repository .getSourceRoot (), "cvs_test/ cvsrepo" );
125
+ File root = Path . of (repository .getSourceRoot (), "cvs_test" , " cvsrepo"). toFile ( );
124
126
CVSRepository cvsrepo = (CVSRepository ) RepositoryFactory .getRepository (root );
125
127
assertNull (cvsrepo .getBranch ());
126
128
}
@@ -135,27 +137,26 @@ void testGetBranchNoBranch() throws Exception {
135
137
@ Test
136
138
void testNewBranch () throws Exception {
137
139
setUpTestRepository ();
138
- File root = new File (repository .getSourceRoot (), "cvs_test/ cvsrepo" );
140
+ File root = Path . of (repository .getSourceRoot (), "cvs_test" , " cvsrepo"). toFile ( );
139
141
140
142
// Create new branch and switch to it.
141
143
runCvsCommand (root , "tag" , "-b" , "mybranch" );
142
144
// Note that the 'update' command will change the entries in 'cvsroot' directory.
143
145
runCvsCommand (root , "update" , "-r" , "mybranch" );
144
146
145
- // Now the repository object can be instantiated so that determineBranch()
146
- // will be called.
147
+ // Now the repository object can be instantiated and determineBranch() will be called.
147
148
CVSRepository cvsrepo = (CVSRepository ) RepositoryFactory .getRepository (root );
148
149
149
150
assertEquals ("mybranch" , cvsrepo .getBranch ());
150
151
151
152
// Change the content and commit.
152
153
File mainC = new File (root , "main.c" );
153
- FileChannel outChan = new FileOutputStream (mainC , true ).getChannel ();
154
- outChan .truncate (0 );
155
- outChan . close ();
156
- FileWriter fw = new FileWriter (mainC );
157
- fw .write ("#include <foo.h>\n " );
158
- fw . close ();
154
+ try ( FileChannel outChan = new FileOutputStream (mainC , true ).getChannel ()) {
155
+ outChan .truncate (0 );
156
+ }
157
+ try ( FileWriter fw = new FileWriter (mainC )) {
158
+ fw .write ("#include <foo.h>\n " );
159
+ }
159
160
runCvsCommand (root , "commit" , "-m" , "change on a branch" , "main.c" );
160
161
161
162
// Check that annotation for the changed line has branch revision.
@@ -169,6 +170,32 @@ void testNewBranch() throws Exception {
169
170
assertEquals ("1.1" , mainCHistory .getHistoryEntries ().get (2 ).getRevision ());
170
171
}
171
172
173
+ @ Test
174
+ void testGetHistoryGet () throws Exception {
175
+ setUpTestRepository ();
176
+ File root = Path .of (repository .getSourceRoot (), "cvs_test" , "cvsrepo" ).toFile ();
177
+ CVSRepository cvsRepo = (CVSRepository ) RepositoryFactory .getRepository (root );
178
+
179
+ Path repoRoot = Path .of (repository .getSourceRoot (), "cvs_test" , "cvsrepo" );
180
+ assertTrue (repoRoot .toFile ().exists ());
181
+ String repoFile = "main.c" ;
182
+ String revision = "1.2" ;
183
+
184
+ File tmpFile = File .createTempFile ("cvsGetHistoryGetTest" , "" );
185
+ assertTrue (tmpFile .exists ());
186
+ try (FileOutputStream out = new FileOutputStream (tmpFile )) {
187
+ assertTrue (cvsRepo .getHistoryGet (out , repoRoot .toString (), repoFile , revision ));
188
+ }
189
+
190
+ String revisionContents1 = new String (Files .readAllBytes (tmpFile .toPath ()));
191
+ tmpFile .delete ();
192
+ assertTrue (revisionContents1 .length () > 0 );
193
+
194
+ String revisionContents2 = new String (cvsRepo .getHistoryGet (repoRoot .toString (), repoFile , revision ).
195
+ readAllBytes ());
196
+ assertEquals (revisionContents1 , revisionContents2 );
197
+ }
198
+
172
199
/**
173
200
* Assert that revision strings in history entries are sorted semantically.
174
201
* This is necessary for displaying revisions on a branch in correct order.
0 commit comments