1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package fr.ifremer.isisfish.vcs;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37 import org.apache.commons.io.FileUtils;
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40 import org.nuiton.util.version.Version;
41 import org.nuiton.util.version.Versions;
42 import org.junit.After;
43 import org.junit.Assert;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.tmatesoft.svn.core.SVNCommitInfo;
47 import org.tmatesoft.svn.core.SVNDepth;
48 import org.tmatesoft.svn.core.SVNException;
49 import org.tmatesoft.svn.core.SVNURL;
50 import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
51 import org.tmatesoft.svn.core.wc.SVNClientManager;
52 import org.tmatesoft.svn.core.wc.SVNCopySource;
53 import org.tmatesoft.svn.core.wc.SVNRevision;
54 import org.tmatesoft.svn.core.wc.SVNStatus;
55 import org.tmatesoft.svn.core.wc.SVNStatusType;
56 import org.tmatesoft.svn.core.wc.SVNUpdateClient;
57 import org.tmatesoft.svn.core.wc.SVNWCClient;
58
59 import fr.ifremer.isisfish.AbstractIsisFishTest;
60 import fr.ifremer.isisfish.vcs.VCS.Status;
61
62
63
64
65
66
67
68
69
70
71
72
73 public class VCSSVNTest extends AbstractIsisFishTest {
74
75
76 private static Log log = LogFactory.getLog(VCSSVNTest.class);
77
78
79
80
81
82
83 public static final File TMPDIR = new File("/tmp");
84
85 public static final String FILECONTENTTAG = "Version 3.1.0";
86 public static final String FILECONTENTTRUNK = "Version 3.2.0";
87
88 protected static File template;
89 protected static File remoteRepo;
90 protected static File localRepo;
91 protected static File localRepoTrunk;
92
93 protected VCSSVN vcs = null;
94
95
96
97
98 public VCSSVNTest() {
99
100 }
101
102
103
104
105
106
107 @Before
108 public void setUp() throws IOException, SVNException {
109 template = new File(TMPDIR, "testsvn-template");
110 remoteRepo = new File(TMPDIR, "testsvn-repo");
111 localRepo = new File(TMPDIR, "testsvn-local");
112 localRepoTrunk = new File(TMPDIR, "testsvn-localTrunk");
113
114
115 tearDown();
116
117
118
119
120 vcs = new VCSSVN(localRepo, "file", "", remoteRepo.getAbsolutePath()
121 + "/isis-fish-data", null, "", "");
122
123
124
125
126
127
128
129 new File(template, "regions" + File.separator + "DemoRegion"
130 + File.separator + "data").mkdirs();
131 new File(template, "simulations" + File.separator + "simu1"
132 + File.separator + "data").mkdirs();
133 new File(template, "scripts").mkdirs();
134
135 FileUtils.writeStringToFile(new File(template, "scripts" + File.separator
136 + "version.txt"), FILECONTENTTAG);
137
138
139 SVNRepositoryFactory.createLocalRepository(remoteRepo, false, true);
140
141
142 SVNURL svnURL = SVNURL.parseURIEncoded("file://"
143 + remoteRepo.getAbsolutePath());
144 SVNURL svnRoot = svnURL.appendPath("isis-fish-data", false);
145 SVNURL svnTrunk = svnRoot.appendPath("trunk", false);
146 SVNURL svnTags = svnRoot.appendPath("tags", false);
147
148 SVNClientManager svnManager = SVNClientManager.newInstance();
149
150 svnManager.getCommitClient().doMkDir(
151 new SVNURL[] { svnRoot, svnTrunk, svnTags }, "add dir");
152
153 svnManager.getCommitClient().doImport(template, svnTrunk,
154 "initial import", null, true, true, SVNDepth.INFINITY);
155
156
157 SVNCopySource source = new SVNCopySource(SVNRevision.HEAD,
158 SVNRevision.HEAD, svnTrunk);
159
160 svnManager.getCopyClient().doCopy(new SVNCopySource[] { source },
161 svnTags.appendPath("3.1.0", false), false,
162 true,
163 true,
164 "Create tag", null);
165
166 }
167
168
169
170
171 @After
172 public void tearDown() {
173
174 if (template.exists()) {
175 FileUtils.deleteQuietly(template);
176 }
177 if (remoteRepo.exists()) {
178 FileUtils.deleteQuietly(remoteRepo);
179 }
180 if (localRepo.exists()) {
181 FileUtils.deleteQuietly(localRepo);
182 }
183 if (localRepoTrunk.exists()) {
184 FileUtils.deleteQuietly(localRepoTrunk);
185 }
186 }
187
188
189
190
191 @Test
192 public void testgetSVNManager() {
193
194
195 if (log.isInfoEnabled()) {
196 log.info("testgetSVNManager()");
197 }
198
199 SVNClientManager result = vcs.getSVNManager();
200 Assert.assertNotNull(result);
201 }
202
203
204
205
206
207 @Test
208 public void testgetRemoteURL() throws SVNException {
209
210
211 if (log.isInfoEnabled()) {
212 log.info("testgetRemoteURL()");
213 }
214
215 SVNURL expResult = SVNURL.create("file", null, "", -1, remoteRepo
216 .getAbsolutePath()
217 + "/" + "isis-fish-data", true);
218 SVNURL result = vcs.getRemoteURL();
219 Assert.assertEquals(expResult, result);
220
221 }
222
223
224
225
226 @Test
227 public void testIsVersionnableFile() {
228
229
230 if (log.isInfoEnabled()) {
231 log.info("testIsVersionnableFile()");
232 }
233
234
235 File file = new File(".svn");
236 boolean result = vcs.isVersionnableFile(file);
237 Assert.assertFalse(result);
238
239
240 file = new File("Toto.java");
241 result = vcs.isVersionnableFile(file);
242 Assert.assertFalse(result);
243
244
245 file = new File(vcs.getLocalRepository(), "Toto.java");
246 result = vcs.isVersionnableFile(file);
247 Assert.assertTrue(result);
248
249
250 file = new File(vcs.getLocalRepository(), "libaudio.la");
251 result = vcs.isVersionnableFile(file);
252 Assert.assertFalse(result);
253
254
255 file = new File(vcs.getLocalRepository(), "libaudio.lo");
256 result = vcs.isVersionnableFile(file);
257 Assert.assertFalse(result);
258
259
260 file = new File(vcs.getLocalRepository(), "libaudio.lads");
261 result = vcs.isVersionnableFile(file);
262 Assert.assertTrue(result);
263
264
265 file = new File(vcs.getLocalRepository(), "libaudio.lads~");
266 result = vcs.isVersionnableFile(file);
267 Assert.assertFalse(result);
268
269
270 file = new File(vcs.getLocalRepository(), "commit.rev1234.rej");
271 result = vcs.isVersionnableFile(file);
272 Assert.assertFalse(result);
273 }
274
275
276
277
278
279
280 @Test
281 public void testAll() throws IOException, VCSException {
282
283
284 if (log.isInfoEnabled()) {
285 log.info("testIsVersionnableAbleFile()");
286 }
287
288
289
290 VCSSVN trunk = new VCSSVN(localRepoTrunk, "file", "", remoteRepo
291 .getAbsolutePath()
292 + "/" + "isis-fish-data", null, "", "");
293
294 trunk.checkout(null, true);
295
296
297 vcs.checkout(null, false);
298 Assert.assertTrue(vcs.getLocalRepository().exists());
299 Assert.assertTrue(vcs.getTag().startsWith("/trunk"));
300
301
302 vcs.update(new File(vcs.getLocalRepository(), "scripts"), true);
303 File version = new File(vcs.getLocalRepository(), "scripts"
304 + File.separator + "version.txt");
305 Assert.assertTrue(version.exists());
306 Assert.assertEquals(FILECONTENTTAG, FileUtils.readFileToString(version));
307
308
309 FileUtils.writeStringToFile(version, FILECONTENTTRUNK);
310 vcs.commit(null, "modif du fichier version");
311 Assert.assertEquals(FILECONTENTTRUNK, FileUtils.readFileToString(version));
312
313
314 File demo = new File(vcs.getLocalRepository(), "regions"
315 + File.separator + "DemoRegion");
316 vcs.update(demo, true);
317 Assert.assertTrue(demo.exists());
318
319
320 vcs.delete(Collections.singletonList(demo), "suppression d'une region");
321 Assert.assertFalse(demo.exists());
322
323
324 File fileToAdd = new File(vcs.getLocalRepository(), "newfile.txt");
325 String lecontent = "Le nouveau fichier";
326 FileUtils.writeStringToFile(fileToAdd, lecontent);
327 vcs.add(Arrays.asList(fileToAdd), "ajout d'un fichier");
328
329
330 vcs.setTag(Versions.valueOf("3.1.0"));
331 Assert.assertTrue(vcs.getTag().startsWith("/tags/3.1.0"));
332 Assert.assertEquals(FILECONTENTTAG, FileUtils.readFileToString(version));
333 Assert.assertTrue(demo.exists());
334
335
336 File fileVersion = new File(trunk.getLocalRepository(), "scripts"
337 + File.separator + "version.txt");
338 File fileDeleted = new File(trunk.getLocalRepository(), "regions"
339 + File.separator + "DemoRegion");
340 File newfileAdded = new File(trunk.getLocalRepository(), "newfile.txt");
341 Map<File, SVNStatus> map = trunk.getRemoteStatus(trunk
342 .getLocalRepository(), true);
343 Assert.assertEquals(3, map.size());
344 Assert.assertTrue(map.containsKey(fileVersion));
345 Assert.assertTrue(map.containsKey(fileDeleted));
346 Assert.assertTrue(map.containsKey(newfileAdded));
347
348
349 FileUtils.writeStringToFile(fileVersion, "Le nouveau content de version");
350
351
352 List<File> conflictFile = trunk.update(null, true);
353 if (log.isInfoEnabled()) {
354 log.info("conflictFile: " + conflictFile.toString());
355 }
356 Assert.assertEquals(1, conflictFile.size());
357 Assert.assertTrue(conflictFile.contains(fileVersion));
358
359 File fileAdded = new File(trunk.getLocalRepository(), "newfile.txt");
360 Assert.assertEquals(lecontent, FileUtils.readFileToString(fileAdded));
361 Assert.assertFalse(fileDeleted.exists());
362
363
364 Map<File, SVNStatus> map2 = trunk.getRemoteStatus(trunk
365 .getLocalRepository(), true);
366 Assert.assertEquals(0, map2.size());
367
368
369 Map<File, SVNStatus> map3 = trunk.getLocalStatus(trunk
370 .getLocalRepository(), true);
371 Assert.assertEquals(1, map3.size());
372 Assert.assertTrue(map3.containsKey(fileVersion));
373
374
375
376 trunk.commit(Arrays.asList(fileVersion),
377 "Commit fichier version, avec les conflits");
378 Map<File, SVNStatus> map4 = trunk.getRemoteStatus(trunk
379 .getLocalRepository(), true);
380 Assert.assertEquals(0, map4.size());
381 Map<File, SVNStatus> map5 = trunk.getLocalStatus(trunk
382 .getLocalRepository(), true);
383 Assert.assertEquals(0, map5.size());
384 }
385
386
387
388
389
390
391 @Test
392 public void testAdd() throws Exception {
393
394
395 if (log.isInfoEnabled()) {
396 log.info("testAdd()");
397 }
398
399
400 vcs.checkout(null, true);
401
402
403 File firstFile = new File(vcs.getLocalRepository() + File.separator
404 + "scripts" + File.separator + "version.txt");
405 FileUtils.writeStringToFile(firstFile, "Version 3.2.1");
406
407 List<File> files = Collections.singletonList(firstFile);
408
409 vcs.add(files, "test commit");
410 }
411
412
413
414
415
416
417
418
419 @Test
420 public void testCheckProtocol() throws VCSException {
421
422 vcs.checkout(null, false);
423
424 vcs.checkProtocol();
425 }
426
427
428
429
430
431
432 @Test
433 public void testCleanup() throws VCSException {
434
435 vcs.checkout(null, false);
436
437 vcs.cleanup(null);
438 }
439
440
441
442
443
444
445
446
447
448 @Test
449 public void testGetChanglog() throws VCSException, IOException,
450 SVNException {
451
452
453 if (log.isInfoEnabled()) {
454 log.info("testGetChanglog()");
455 }
456
457 File firstFile = new File(vcs.getLocalRepository() + File.separator
458 + "scripts" + File.separator + "version.txt");
459 File secondFile = new File(vcs.getLocalRepository() + File.separator
460 + "simulations" + File.separator + "simu1" + File.separator
461 + "simulation.properties");
462 List<File> files = new ArrayList<File>();
463 files.add(firstFile);
464 files.add(secondFile);
465
466
467 vcs.checkout(null, true);
468
469
470 FileUtils.writeStringToFile(firstFile, "version 3.2.1");
471 FileUtils.writeStringToFile(secondFile, "name = test1");
472 SVNClientManager svnManager = SVNClientManager.newInstance();
473 svnManager.getWCClient().doAdd(secondFile,
474 true,
475 false,
476 true,
477 SVNDepth.FILES,
478 false,
479 true);
480 svnManager.getCommitClient().doCommit(
481 new File[] { firstFile, secondFile }, false,
482 "mise a jour de la version", null, null, false, true,
483 SVNDepth.INFINITY);
484
485 Map<File, String> result = vcs.getChanglog(files);
486
487 Map<File, String> expResult = new HashMap<File, String>();
488 expResult.put(firstFile, "mise a jour de la version");
489 expResult.put(secondFile, "mise a jour de la version");
490 Assert.assertEquals(expResult, result);
491 }
492
493
494
495
496
497
498 @Test
499 public void testGetDiff() throws VCSException, IOException {
500
501
502 if (log.isInfoEnabled()) {
503 log.info("testGetDiff()");
504 }
505
506 File firstFile = new File(vcs.getLocalRepository() + File.separator
507 + "scripts" + File.separator + "version.txt");
508
509 vcs.checkout(null, true);
510
511
512 FileUtils.writeStringToFile(firstFile, "Version 3.2.1");
513
514 String result = vcs.getDiff(firstFile);
515
516
517 Assert.assertTrue(result.indexOf("version.txt") > 0);
518 Assert.assertTrue(result.indexOf("-Version 3.1.0") > 0);
519 Assert.assertTrue(result.indexOf("+Version 3.2.1") > 0);
520
521 }
522
523
524
525
526
527 @Test
528 public void testGetFileList() throws VCSException {
529
530
531 if (log.isInfoEnabled()) {
532 log.info("testGetFileList()");
533 }
534
535 vcs.checkout(null, true);
536
537 File directory = null;
538 List<String> expResult = new ArrayList<String>(3);
539 expResult.add("regions");
540 expResult.add("scripts");
541 expResult.add("simulations");
542 List<String> result = vcs.getFileList(directory);
543 Assert.assertEquals(expResult, result);
544 }
545
546
547
548
549
550
551 @Test
552 public void testGetFileList2() throws VCSException, SVNException {
553
554
555 if (log.isInfoEnabled()) {
556 log.info("testGetFileList2()");
557 }
558
559 vcs.checkout(null, true);
560
561
562 File newDir = new File(vcs.getLocalRepository() + "/testadddir");
563 newDir.mkdir();
564
565 SVNWCClient wcClient = vcs.getSVNManager().getWCClient();
566 wcClient.doAdd(newDir,
567 true,
568 false,
569 true,
570 SVNDepth.FILES,
571 false,
572 true);
573
574
575 File directory = null;
576 List<String> expResult = new ArrayList<String>(3);
577 expResult.add("regions");
578 expResult.add("scripts");
579 expResult.add("simulations");
580 List<String> result = vcs.getFileList(directory);
581 Assert.assertEquals(expResult, result);
582 }
583
584
585
586
587
588
589
590
591
592 @Test
593 public void testGetFileList3() throws VCSException, SVNException {
594
595
596 if (log.isInfoEnabled()) {
597 log.info("testGetFileList3()");
598 }
599
600
601 vcs.checkout(null, true);
602
603
604 SVNURL svnURL = SVNURL.parseURIEncoded("file://"
605 + remoteRepo.getAbsolutePath());
606 SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false)
607 .appendPath("trunk", false).appendPath("test", false);
608 SVNClientManager svnManager = SVNClientManager.newInstance();
609 svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir },
610 "add test dir");
611
612
613 File directory = null;
614 List<String> expResult = new ArrayList<String>(3);
615 expResult.add("regions");
616 expResult.add("scripts");
617 expResult.add("simulations");
618 expResult.add("test");
619 List<String> result = vcs.getFileList(directory);
620 Assert.assertEquals(expResult, result);
621 }
622
623
624
625
626
627
628
629 @Test
630 public void testGetUpdatedFile() throws VCSException, IOException,
631 SVNException {
632
633
634 if (log.isInfoEnabled()) {
635 log.info("testGetUpdatedFile()");
636 }
637
638 List<File> expResult = new ArrayList<File>();
639 expResult.add(new File(vcs.getLocalRepository().getAbsolutePath()
640 + File.separator + "test"));
641 expResult.add(vcs.getLocalRepository());
642
643
644 vcs.checkout(null, true);
645
646
647 SVNURL svnURL = SVNURL.parseURIEncoded("file://"
648 + remoteRepo.getAbsolutePath());
649 SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false)
650 .appendPath("trunk", false).appendPath("test", false);
651 SVNClientManager svnManager = SVNClientManager.newInstance();
652 svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir },
653 "add test dir");
654
655 List<File> result = vcs.getUpdatedFile();
656 Assert.assertEquals(expResult, result);
657 }
658
659
660
661
662
663
664
665 @Test
666 public void testGetUpdatedFileEmptyResult() throws VCSException,
667 IOException, SVNException {
668
669
670 if (log.isInfoEnabled()) {
671 log.info("testGetUpdatedFile()");
672 }
673
674 List<File> expResult = new ArrayList<File>();
675
676
677 vcs.checkout(null, true);
678
679 List<File> result = vcs.getUpdatedFile();
680 Assert.assertEquals(expResult, result);
681
682 }
683
684
685
686
687
688
689
690 @Test
691 public void testHaveUpdate() throws VCSException, SVNException {
692
693
694 if (log.isInfoEnabled()) {
695 log.info("testHaveUpdate()");
696 }
697
698
699 vcs.checkout(null, true);
700
701
702 SVNURL svnURL = SVNURL.parseURIEncoded("file://"
703 + remoteRepo.getAbsolutePath());
704 SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false)
705 .appendPath("trunk", false).appendPath("test", false);
706 SVNClientManager svnManager = SVNClientManager.newInstance();
707 svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir },
708 "add test dir");
709
710 boolean result = vcs.haveUpdate();
711 Assert.assertTrue(result);
712 }
713
714
715
716
717
718
719
720 @Test
721 public void testHaveNoUpdate() throws VCSException, SVNException {
722
723
724 if (log.isInfoEnabled()) {
725 log.info("testHaveNoUpdate()");
726 }
727
728
729 vcs.checkout(null, true);
730
731 boolean result = vcs.haveUpdate();
732 Assert.assertFalse(result);
733 }
734
735
736
737
738 @Test
739 public void testIsConnected() {
740
741
742 if (log.isInfoEnabled()) {
743 log.info("testIsConnected()");
744 }
745
746 boolean result = vcs.isConnected();
747 Assert.assertTrue(result);
748 }
749
750
751
752
753
754 @Test
755 public void testIsOnRemote() throws VCSException {
756
757
758 if (log.isInfoEnabled()) {
759 log.info("testIsOnRemote()");
760 }
761
762 vcs.checkout(null, false);
763
764 File file = null;
765 boolean result = vcs.isOnRemote(file);
766 Assert.assertTrue(result);
767 }
768
769
770
771
772
773 @Test
774 public void testIsOnRemote2() throws VCSException {
775
776
777 if (log.isInfoEnabled()) {
778 log.info("testIsOnRemote2()");
779 }
780
781 vcs.checkout(null, false);
782
783 File file = new File(vcs.getLocalRepository() + File.separator
784 + "scripts" + File.separator + "version.txt");
785 boolean result = vcs.isOnRemote(file);
786 Assert.assertTrue(result);
787 }
788
789
790
791
792
793
794 @Test
795 public void testIsOnRemote3() throws VCSException, SVNException {
796
797
798 if (log.isInfoEnabled()) {
799 log.info("testIsOnRemote3()");
800 }
801
802 vcs.checkout(null, false);
803
804
805 SVNURL svnURL = SVNURL.parseURIEncoded("file://"
806 + remoteRepo.getAbsolutePath());
807 SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false)
808 .appendPath("trunk", false).appendPath("test", false);
809 SVNClientManager svnManager = SVNClientManager.newInstance();
810 svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir },
811 "add test dir");
812
813 File file = new File(vcs.getLocalRepository() + File.separator + "test");
814 boolean result = vcs.isOnRemote(file);
815 Assert.assertTrue(result);
816 }
817
818
819
820
821
822
823 @Test
824 public void testIsOnRemote4() throws VCSException, SVNException {
825
826
827 if (log.isInfoEnabled()) {
828 log.info("testIsOnRemote4()");
829 }
830
831 vcs.checkout(null, false);
832
833
834 SVNURL svnURL = SVNURL.parseURIEncoded("file://"
835 + remoteRepo.getAbsolutePath());
836 SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false)
837 .appendPath("trunk", false).appendPath("scripts", false);
838 SVNClientManager svnManager = SVNClientManager.newInstance();
839 svnManager.getCommitClient().doDelete(new SVNURL[] { svnURLNewDir },
840 "del scripts dir");
841
842 File file = new File(vcs.getLocalRepository() + File.separator
843 + "scripts");
844 boolean result = vcs.isOnRemote(file);
845 Assert.assertFalse(result);
846 }
847
848
849
850
851
852
853
854 @Test
855 public void testIsOnRemote5() throws VCSException, SVNException,
856 IOException {
857
858
859 if (log.isInfoEnabled()) {
860 log.info("testIsOnRemote5()");
861 }
862
863 vcs.checkout(null, false);
864
865
866 File file = new File(vcs.getLocalRepository() + File.separator
867 + "test.txt");
868 FileUtils.writeStringToFile(file, "name = test1");
869 SVNClientManager svnManager = SVNClientManager.newInstance();
870 svnManager.getWCClient().doAdd(file,
871 true,
872 false,
873 true,
874 SVNDepth.FILES,
875 false,
876 true);
877
878 boolean result = vcs.isOnRemote(file);
879 Assert.assertFalse(result);
880 }
881
882
883
884
885
886 @Test
887 public void testIsTag() throws VCSException {
888
889
890 if (log.isInfoEnabled()) {
891 log.info("testGetDiff()");
892 }
893
894 Version version = Versions.valueOf("3.1.0");
895 Assert.assertTrue(vcs.isTag(version));
896
897 version = Versions.valueOf("3.2.0");
898 Assert.assertFalse(vcs.isTag(version));
899 }
900
901
902
903
904
905 @Test
906 public void testIsUpToDate() throws VCSException {
907
908
909 if (log.isInfoEnabled()) {
910 log.info("testIsUpToDate()");
911 }
912
913 vcs.checkout(null, false);
914
915 File file = null;
916 boolean result = vcs.isUpToDate(file);
917 Assert.assertTrue(result);
918
919 }
920
921
922
923
924
925
926
927 @Test
928 public void testIsUpToDate2() throws VCSException, IOException,
929 SVNException {
930
931
932 if (log.isInfoEnabled()) {
933 log.info("testIsUpToDate2()");
934 }
935
936
937 vcs.checkout(null, false);
938
939
940 File file = new File(vcs.getLocalRepository() + File.separator
941 + "test.txt");
942 FileUtils.writeStringToFile(file, "name = test1");
943 SVNClientManager svnManager = SVNClientManager.newInstance();
944 svnManager.getWCClient().doAdd(file,
945 true,
946 false,
947 true,
948 SVNDepth.FILES,
949 false,
950 true);
951
952 boolean result = vcs.isUpToDate(file);
953 Assert.assertFalse(result);
954
955 }
956
957
958
959
960
961
962
963 @Test
964 public void testIsUpToDate3() throws VCSException, IOException,
965 SVNException {
966
967
968 if (log.isInfoEnabled()) {
969 log.info("testIsUpToDate3()");
970 }
971
972
973 vcs.checkout(null, false);
974
975
976 SVNURL svnURL = SVNURL.parseURIEncoded("file://" + remoteRepo.getAbsolutePath());
977 SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false)
978 .appendPath("trunk", false).appendPath("test", false);
979 SVNClientManager svnManager = SVNClientManager.newInstance();
980 svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir },
981 "add test dir");
982
983 File file = new File(vcs.getLocalRepository() + File.separator + "test");
984 boolean result = vcs.isUpToDate(file);
985 Assert.assertFalse(result);
986
987 }
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002 @Test
1003 public void testUpdateWithLock() throws VCSException, SVNException,
1004 IOException {
1005
1006
1007 if (log.isInfoEnabled()) {
1008 log.info("testUpdateWithLock()");
1009 }
1010
1011
1012 vcs.checkout(null, false);
1013
1014
1015 File file = new File(vcs.getLocalRepository(), "scripts"
1016 + File.separator + "version.txt");
1017 FileUtils.writeStringToFile(file, "aaaaaz");
1018 SVNClientManager svnManager = SVNClientManager.newInstance();
1019 SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
1020 new File[] { file },
1021 false,
1022 "modify version",
1023 null,
1024 null,
1025 false,
1026 false,
1027 SVNDepth.INFINITY);
1028
1029
1030 log.debug("Commited, new revision is " + rev.getNewRevision());
1031
1032
1033 SVNRevision revision = SVNRevision.create(rev.getNewRevision() - 1);
1034 SVNClientManager svnManagerLocal = vcs.getSVNManager();
1035 SVNUpdateClient updateClient = svnManagerLocal.getUpdateClient();
1036 long newRevision = updateClient.doUpdate(vcs.getLocalRepository(),
1037 revision,
1038 SVNDepth.INFINITY,
1039 false,
1040 false);
1041 log.debug("Updated at revision " + newRevision);
1042
1043
1044
1045
1046
1047
1048
1049 Map<File, SVNStatus> files = vcs.getRemoteStatus(null, true);
1050 log.info("Will update file = " + files.keySet());
1051 Assert.assertTrue("Must be one file updated", files.size() == 1);
1052
1053
1054 List<File> filesInConflict = vcs.update(null, true);
1055 Assert.assertTrue("No file should be in conflit", filesInConflict
1056 .isEmpty());
1057 }
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072 @Test
1073 public void testUpdateWithConflict() throws VCSException, SVNException,
1074 IOException {
1075
1076
1077 if (log.isInfoEnabled()) {
1078 log.info("testUpdateWithConflict()");
1079 }
1080
1081
1082 vcs.checkout(null, false);
1083
1084
1085 File file = new File(vcs.getLocalRepository(), "scripts"
1086 + File.separator + "version.txt");
1087 FileUtils.writeStringToFile(file, "aaaaaz");
1088 SVNClientManager svnManager = SVNClientManager.newInstance();
1089 SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
1090 new File[] { file },
1091 false,
1092 "modify version",
1093 null,
1094 null,
1095 false,
1096 false,
1097 SVNDepth.INFINITY);
1098
1099
1100 log.debug("Commited, new revision is " + rev.getNewRevision());
1101
1102
1103 SVNRevision revision = SVNRevision.create(rev.getNewRevision() - 1);
1104 SVNClientManager svnManagerLocal = vcs.getSVNManager();
1105 SVNUpdateClient updateClient = svnManagerLocal.getUpdateClient();
1106 long newRevision = updateClient.doUpdate(vcs.getLocalRepository(),
1107 revision,
1108 SVNDepth.INFINITY,
1109 false,
1110 false);
1111 log.debug("Updated at revision " + newRevision);
1112
1113
1114 File file2 = new File(vcs.getLocalRepository(), "scripts"
1115 + File.separator + "version.txt");
1116 FileUtils.writeStringToFile(file2, "oooooo");
1117
1118
1119 List<File> filesInConflict = vcs.update(null, true);
1120 Assert.assertNotNull(filesInConflict);
1121 Assert.assertEquals(1, filesInConflict.size());
1122 log.debug("Conflicts are : " + filesInConflict);
1123 }
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 @Test
1139 public void testSwitchWithConflict() throws VCSException, SVNException,
1140 IOException {
1141
1142
1143 if (log.isInfoEnabled()) {
1144 log.info("testSwitchWithConflict()");
1145 }
1146
1147
1148 vcs.checkout(Versions.valueOf("3.1.0"), false);
1149
1150
1151 File file = new File(vcs.getLocalRepository(), "scripts"
1152 + File.separator + "version.txt");
1153 FileUtils.writeStringToFile(file, "aaaaaz");
1154 SVNClientManager svnManager = SVNClientManager.newInstance();
1155 SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
1156 new File[] { file },
1157 false,
1158 "modify version",
1159 null,
1160 null,
1161 false,
1162 false,
1163 SVNDepth.INFINITY);
1164
1165
1166 log.debug("Commited, new revision is " + rev.getNewRevision());
1167
1168
1169 vcs.setTag(null);
1170
1171
1172 File file2 = new File(vcs.getLocalRepository(), "scripts"
1173 + File.separator + "version.txt");
1174 FileUtils.writeStringToFile(file2, "oooooo");
1175
1176
1177 List<File> filesInConflict = vcs.setTag(Versions.valueOf("3.1.0"));
1178 Assert.assertNotNull(filesInConflict);
1179 Assert.assertEquals(1, filesInConflict.size());
1180 log.debug("Conflicts are : " + filesInConflict);
1181 }
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196 @Test
1197 public void testCheckFileStatusWithConflict() throws VCSException, SVNException,
1198 IOException {
1199
1200
1201 if (log.isInfoEnabled()) {
1202 log.info("testCheckFileStatusWithConflict()");
1203 }
1204
1205
1206 vcs.checkout(null, false);
1207
1208
1209 File file = new File(vcs.getLocalRepository(), "scripts"
1210 + File.separator + "version.txt");
1211 FileUtils.writeStringToFile(file, "aaaaaz");
1212 SVNClientManager svnManager = SVNClientManager.newInstance();
1213 SVNCommitInfo rev = svnManager.getCommitClient().doCommit(
1214 new File[] { file },
1215 false,
1216 "modify version",
1217 null,
1218 null,
1219 false,
1220 false,
1221 SVNDepth.INFINITY);
1222
1223
1224 log.debug("Commited, new revision is " + rev.getNewRevision());
1225
1226
1227 SVNRevision revision = SVNRevision.create(rev.getNewRevision() - 1);
1228 SVNClientManager svnManagerLocal = vcs.getSVNManager();
1229 SVNUpdateClient updateClient = svnManagerLocal.getUpdateClient();
1230 long newRevision = updateClient.doUpdate(vcs.getLocalRepository(),
1231 revision,
1232 SVNDepth.INFINITY,
1233 false,
1234 false);
1235 log.debug("Updated at revision " + newRevision);
1236
1237
1238 File file2 = new File(vcs.getLocalRepository(), "scripts"
1239 + File.separator + "version.txt");
1240 FileUtils.writeStringToFile(file2, "oooooo");
1241
1242
1243 List<File> filesInConflict = vcs.checkFileStatus();
1244 Assert.assertNotNull(filesInConflict);
1245 Assert.assertEquals(1, filesInConflict.size());
1246 log.debug("Conflicts are : " + filesInConflict);
1247
1248
1249
1250 filesInConflict = vcs.checkFileStatus();
1251 Assert.assertNull(filesInConflict);
1252 }
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 @Test
1266 public void testGetLocalStatusModified() throws VCSException, SVNException,
1267 IOException {
1268
1269
1270 if (log.isInfoEnabled()) {
1271 log.info("testGetLocalStatusModified()");
1272 }
1273
1274
1275 vcs.checkout(null, false);
1276
1277
1278 File file = new File(vcs.getLocalRepository(), "scripts"
1279 + File.separator + "version.txt");
1280 FileUtils.writeStringToFile(file, "modified content");
1281
1282 Assert.assertEquals(Status.STATUS_MODIFIED, vcs.getLocalStatus(file));
1283 }
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296 @Test
1297 public void testGetLocalStatusMissing() throws VCSException, SVNException,
1298 IOException {
1299
1300
1301 if (log.isInfoEnabled()) {
1302 log.info("testGetLocalStatusMissing()");
1303 }
1304
1305
1306 vcs.checkout(null, false);
1307
1308
1309 File file = new File(vcs.getLocalRepository(), "scripts"
1310 + File.separator + "version.txt");
1311 Assert.assertTrue(file.delete());
1312
1313 Map<File, SVNStatus> statusFiles = vcs.getLocalStatus(file, true, SVNStatusType.STATUS_MISSING);
1314 Assert.assertEquals(1, statusFiles.size());
1315 }
1316 }