View Javadoc
1   /*
2    * #%L
3    * IsisFish
4    * 
5    * $Id: VCSSVNTest.java 4156 2014-12-09 11:27:18Z echatellier $
6    * $HeadURL: https://svn.codelutin.com/isis-fish/tags/isis-fish-4.4.0.2/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java $
7    * %%
8    * Copyright (C) 2008 - 2013 Ifremer, Code Lutin, Chatellier Eric
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as
12   * published by the Free Software Foundation, either version 3 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/gpl-3.0.html>.
23   * #L%
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   * Class de test VCS.
64   * 
65   * Created: 12 janv. 2006 16:20:33
66   * 
67   * @author poussin
68   * 
69   * @version $Revision: 4156 $
70   * 
71   * Last update: $Date: 2014-12-09 12:27:18 +0100 (Tue, 09 Dec 2014) $ by : $Author: echatellier $
72   */
73  public class VCSSVNTest extends AbstractIsisFishTest {
74  
75      /** Class logger */
76      private static Log log = LogFactory.getLog(VCSSVNTest.class);
77  
78      /**
79       * Run test out of target directory for SVN to not find parent .svn with not supported svn format.
80       * 
81       * FIXME echatellier 20131127 : try to relocate into target and chroot svnkit tests
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       * Constructor.
97       */
98      public VCSSVNTest() {
99  
100     }
101 
102     /**
103      * Init call before each test.
104      * @throws IOException 
105      * @throws SVNException 
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         // un peu de nettoyage
115         tearDown();
116 
117         // creation de l'instance de notre VCS pour les tests
118         // on le fait au debut pour que la l'init de la lib svn soit fait
119         // par la classe elle meme et ainsi tester que ca marche
120         vcs = new VCSSVN(localRepo, "file", "", remoteRepo.getAbsolutePath()
121                 + "/isis-fish-data", null, "", "");
122 
123         // Creation d'un repo local avec un trunk et un tag
124         // durant le test, on modifie version.txt pour utiliser
125         // fileContentTrunk et modifier le contenu. On peut alors tester
126         // le changement de tag en fonction du contenu du fichier
127 
128         // creation d'un template de directory
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         // creation du repo pour les tests
139         SVNRepositoryFactory.createLocalRepository(remoteRepo, false, true);
140 
141         // ajout de source dans le repo
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         // creation de l'arborescence
150         svnManager.getCommitClient().doMkDir(
151                 new SVNURL[] { svnRoot, svnTrunk, svnTags }, "add dir");
152         //svnManager.getCommitClient().doImport(template, svnTrunk, "initial import", true, true);
153         svnManager.getCommitClient().doImport(template, svnTrunk,
154                 "initial import", null, true, true, SVNDepth.INFINITY);
155 
156         // 1.1.x svnManager.getCopyClient().doCopy(svnTrunk, SVNRevision.HEAD, svnTags.appendPath("3.1.0", false), false, true, "Create tag");
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, /*isMove*/
162                 true, /*makeParents*/
163                 true, /*failWhenDstExists*/
164                 "Create tag", null);
165 
166     }
167 
168     /**
169      * Clean repo directories.
170      */
171     @After
172     public void tearDown() {
173         // un peu de nettoyage
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      * Test of getSVNManager method, of class VCSSVN.
190      */
191     @Test
192     public void testgetSVNManager() {
193 
194         // log
195         if (log.isInfoEnabled()) {
196             log.info("testgetSVNManager()");
197         }
198 
199         SVNClientManager result = vcs.getSVNManager();
200         Assert.assertNotNull(result);
201     }
202 
203     /**
204      * Test of getRemoteURL method, of class VCSSVN.
205      * @throws SVNException 
206      */
207     @Test
208     public void testgetRemoteURL() throws SVNException {
209 
210         // log
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      * Test of isVersionnableFile method, of class VCSSVN.
225      */
226     @Test
227     public void testIsVersionnableFile() {
228 
229         // log
230         if (log.isInfoEnabled()) {
231             log.info("testIsVersionnableFile()");
232         }
233 
234         // un fichier special, on refuse
235         File file = new File(".svn");
236         boolean result = vcs.isVersionnableFile(file);
237         Assert.assertFalse(result);
238 
239         // Pas dans le repository local, on refuse
240         file = new File("Toto.java");
241         result = vcs.isVersionnableFile(file);
242         Assert.assertFalse(result);
243 
244         // enfin un bout fichier :)
245         file = new File(vcs.getLocalRepository(), "Toto.java");
246         result = vcs.isVersionnableFile(file);
247         Assert.assertTrue(result);
248 
249         // match pas (svn ignore)
250         file = new File(vcs.getLocalRepository(), "libaudio.la");
251         result = vcs.isVersionnableFile(file);
252         Assert.assertFalse(result);
253 
254         // match pas (svn ignore)
255         file = new File(vcs.getLocalRepository(), "libaudio.lo");
256         result = vcs.isVersionnableFile(file);
257         Assert.assertFalse(result);
258 
259         // match (svn ignore)
260         file = new File(vcs.getLocalRepository(), "libaudio.lads");
261         result = vcs.isVersionnableFile(file);
262         Assert.assertTrue(result);
263 
264         // match pas (svn ignore)
265         file = new File(vcs.getLocalRepository(), "libaudio.lads~");
266         result = vcs.isVersionnableFile(file);
267         Assert.assertFalse(result);
268 
269         // match pas (svn ignore)
270         file = new File(vcs.getLocalRepository(), "commit.rev1234.rej");
271         result = vcs.isVersionnableFile(file);
272         Assert.assertFalse(result);
273     }
274 
275     /**
276      * Test of checkout method, of class VCSSVN.
277      * @throws IOException 
278      * @throws VCSException 
279      */
280     @Test
281     public void testAll() throws IOException, VCSException {
282 
283         // log
284         if (log.isInfoEnabled()) {
285             log.info("testIsVersionnableAbleFile()");
286         }
287 
288         // trunk contient une copie complete de trunk, elle permet de test
289         // status lors que l'on fait des commits sur le trunk sur instance
290         VCSSVN trunk = new VCSSVN(localRepoTrunk, "file", "", remoteRepo
291                 .getAbsolutePath()
292                 + "/" + "isis-fish-data", null, "", "");
293 
294         trunk.checkout(null, true);
295 
296         // on ne checkout rien juste le .svn dans le repertoire racine
297         vcs.checkout(null, false);
298         Assert.assertTrue(vcs.getLocalRepository().exists());
299         Assert.assertTrue(vcs.getTag().startsWith("/trunk"));
300 
301         // update scripts dir
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         // modification du fichier version.txt
309         FileUtils.writeStringToFile(version, FILECONTENTTRUNK);
310         vcs.commit(null, "modif du fichier version");
311         Assert.assertEquals(FILECONTENTTRUNK, FileUtils.readFileToString(version));
312 
313         // recuperation de DemoRegion
314         File demo = new File(vcs.getLocalRepository(), "regions"
315                 + File.separator + "DemoRegion");
316         vcs.update(demo, true);
317         Assert.assertTrue(demo.exists());
318 
319         // suppression de DemoRegion
320         vcs.delete(Collections.singletonList(demo), "suppression d'une region");
321         Assert.assertFalse(demo.exists());
322 
323         // ajout d'un fichier sur le trunk avant passage sur le tag
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         // test switchTag
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         // recherche du status des fichiers
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()); // version.txt modifie, DemoRegion supprimee
344         Assert.assertTrue(map.containsKey(fileVersion));
345         Assert.assertTrue(map.containsKey(fileDeleted));
346         Assert.assertTrue(map.containsKey(newfileAdded));
347 
348         // modif dans repo trunk de version pour qu'il y ait un conflit
349         FileUtils.writeStringToFile(fileVersion, "Le nouveau content de version");
350 
351         // update global du repo trunk
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         // recherche du status des fichiers en remote, il ne doit plus y avoir de diff
364         Map<File, SVNStatus> map2 = trunk.getRemoteStatus(trunk
365                 .getLocalRepository(), true);
366         Assert.assertEquals(0, map2.size());
367 
368         // il doit toujours y avoir version.txt qui est modifier localement
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         // on commit le fichier version.txt pour verifier qu'en local et remote
375         // il n'y a plus de modif
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      * Test of add method, of class VCSSVN.
388      *
389      * @throws Exception 
390      */
391     @Test
392     public void testAdd() throws Exception {
393 
394         // log
395         if (log.isInfoEnabled()) {
396             log.info("testAdd()");
397         }
398 
399         // checkout a TAG
400         vcs.checkout(null, true);
401 
402         // now, make a modification, on LOCAL repo
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      * Verifie la connexion et si le protocole a change, switch le repository
414      * pour utiliser le nouveau protocole. Si on est en mode interface (mode
415      * graphique) et que le switch se passe mal, demande a l'utilisateur
416      * de nouvelle valeur pour le protocole (+ identifiant, ...)
417      * @throws VCSException
418      */
419     @Test
420     public void testCheckProtocol() throws VCSException {
421 
422         vcs.checkout(null, false);
423 
424         vcs.checkProtocol();
425     }
426 
427     /**
428      * Test cleanup.
429      * 
430      * @throws VCSException
431      */
432     @Test
433     public void testCleanup() throws VCSException {
434 
435         vcs.checkout(null, false);
436 
437         vcs.cleanup(null);
438     }
439 
440     /**
441      * Return all changelog between local file version and remote repository
442      * file version.
443      * 
444      * @throws VCSException 
445      * @throws IOException 
446      * @throws SVNException 
447      */
448     @Test
449     public void testGetChanglog() throws VCSException, IOException,
450             SVNException {
451 
452         // log
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         // first, checkout trunk
467         vcs.checkout(null, true);
468 
469         // now, make a modification, on LOCAL repo
470         FileUtils.writeStringToFile(firstFile, "version 3.2.1");
471         FileUtils.writeStringToFile(secondFile, "name = test1");
472         SVNClientManager svnManager = SVNClientManager.newInstance();
473         svnManager.getWCClient().doAdd(secondFile, // File path
474                 true, // boolean force
475                 false, // boolean mkdir
476                 true, // boolean climbUnversionedParents
477                 SVNDepth.FILES, // SVNDepth depth
478                 false, // boolean includeIgnored
479                 true); // boolean makeParents
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      * Test of getDiff method, of class VCSSVN.
495      * @throws VCSException 
496      * @throws IOException 
497      */
498     @Test
499     public void testGetDiff() throws VCSException, IOException {
500 
501         // log
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         // now, make a modification, on LOCAL repo
512         FileUtils.writeStringToFile(firstFile, "Version 3.2.1");
513 
514         String result = vcs.getDiff(firstFile);
515 
516         // quelques tests sur la sortie, pas d'égalité parfaite
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      * Test of getFileList method, of class VCSSVN.
525      * @throws VCSException 
526      */
527     @Test
528     public void testGetFileList() throws VCSException {
529 
530         // log
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      * Test of getFileList method, of class VCSSVN.
548      * @throws VCSException 
549      * @throws SVNException 
550      */
551     @Test
552     public void testGetFileList2() throws VCSException, SVNException {
553 
554         // log
555         if (log.isInfoEnabled()) {
556             log.info("testGetFileList2()");
557         }
558 
559         vcs.checkout(null, true);
560 
561         // add new directory
562         File newDir = new File(vcs.getLocalRepository() + "/testadddir");
563         newDir.mkdir();
564 
565         SVNWCClient wcClient = vcs.getSVNManager().getWCClient();
566         wcClient.doAdd(newDir, // File path
567                 true, // boolean force
568                 false, // boolean mkdir
569                 true, // boolean climbUnversionedParents
570                 SVNDepth.FILES, // SVNDepth depth
571                 false, // boolean includeIgnored
572                 true); // boolean makeParents
573 
574         // previous added dir, should not appear in list
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      * Test of getFileList method, of class VCSSVN.
586      * 
587      * Add some dir on remote repo.
588      * 
589      * @throws VCSException 
590      * @throws SVNException 
591      */
592     @Test
593     public void testGetFileList3() throws VCSException, SVNException {
594 
595         // log
596         if (log.isInfoEnabled()) {
597             log.info("testGetFileList3()");
598         }
599 
600         // checkout current trunk
601         vcs.checkout(null, true);
602 
603         // now, make a modification, on REMOTE repo
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         // previous added dir, should appear in list
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      * Test of getUpdatedFile method, of class VCSSVN.
625      * @throws VCSException 
626      * @throws IOException 
627      * @throws SVNException 
628      */
629     @Test
630     public void testGetUpdatedFile() throws VCSException, IOException,
631             SVNException {
632 
633         // log
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         // checkout current trunk
644         vcs.checkout(null, true);
645 
646         // now, make a modification, on REMOTE repo
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      * Test of getUpdatedFile method, of class VCSSVN.
661      * @throws VCSException 
662      * @throws IOException 
663      * @throws SVNException 
664      */
665     @Test
666     public void testGetUpdatedFileEmptyResult() throws VCSException,
667             IOException, SVNException {
668 
669         // log
670         if (log.isInfoEnabled()) {
671             log.info("testGetUpdatedFile()");
672         }
673 
674         List<File> expResult = new ArrayList<File>();
675 
676         // checkout current trunk
677         vcs.checkout(null, true);
678 
679         List<File> result = vcs.getUpdatedFile();
680         Assert.assertEquals(expResult, result);
681 
682     }
683 
684     /**
685      * Ask if there are some new or modified files on server.
686      * 
687      * @throws VCSException 
688      * @throws SVNException 
689      */
690     @Test
691     public void testHaveUpdate() throws VCSException, SVNException {
692 
693         // log
694         if (log.isInfoEnabled()) {
695             log.info("testHaveUpdate()");
696         }
697 
698         // checkout current trunk
699         vcs.checkout(null, true);
700 
701         // now, make a modification, on REMOTE repo
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      * Ask if there are some new or modified files on server.
716      * 
717      * @throws VCSException 
718      * @throws SVNException 
719      */
720     @Test
721     public void testHaveNoUpdate() throws VCSException, SVNException {
722 
723         // log
724         if (log.isInfoEnabled()) {
725             log.info("testHaveNoUpdate()");
726         }
727 
728         // checkout current trunk
729         vcs.checkout(null, true);
730 
731         boolean result = vcs.haveUpdate();
732         Assert.assertFalse(result);
733     }
734 
735     /**
736      * Test of isConnected method, of class VCSSVN.
737      */
738     @Test
739     public void testIsConnected() {
740 
741         // log
742         if (log.isInfoEnabled()) {
743             log.info("testIsConnected()");
744         }
745 
746         boolean result = vcs.isConnected();
747         Assert.assertTrue(result);
748     }
749 
750     /**
751      * Test of isOnRemote method, of class VCSSVN.
752      * @throws VCSException 
753      */
754     @Test
755     public void testIsOnRemote() throws VCSException {
756 
757         // log
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      * Test of isOnRemote method, of class VCSSVN.
771      * @throws VCSException 
772      */
773     @Test
774     public void testIsOnRemote2() throws VCSException {
775 
776         // log
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      * Test of isOnRemote method, of class VCSSVN.
791      * @throws VCSException 
792      * @throws SVNException 
793      */
794     @Test
795     public void testIsOnRemote3() throws VCSException, SVNException {
796 
797         // log
798         if (log.isInfoEnabled()) {
799             log.info("testIsOnRemote3()");
800         }
801 
802         vcs.checkout(null, false);
803 
804         // now, make a modification, on REMOTE repo
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      * Test of isOnRemote method, of class VCSSVN.
820      * @throws VCSException 
821      * @throws SVNException 
822      */
823     @Test
824     public void testIsOnRemote4() throws VCSException, SVNException {
825 
826         // log
827         if (log.isInfoEnabled()) {
828             log.info("testIsOnRemote4()");
829         }
830 
831         vcs.checkout(null, false);
832 
833         // now, make a modification, on REMOTE repo
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      * Test of isOnRemote method, of class VCSSVN.
850      * @throws VCSException 
851      * @throws SVNException 
852      * @throws IOException 
853      */
854     @Test
855     public void testIsOnRemote5() throws VCSException, SVNException,
856             IOException {
857 
858         // log
859         if (log.isInfoEnabled()) {
860             log.info("testIsOnRemote5()");
861         }
862 
863         vcs.checkout(null, false);
864 
865         // modif on local repo
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, // File path
871                 true, // boolean force
872                 false, // boolean mkdir
873                 true, // boolean climbUnversionedParents
874                 SVNDepth.FILES, // SVNDepth depth
875                 false, // boolean includeIgnored
876                 true); // boolean makeParents
877 
878         boolean result = vcs.isOnRemote(file);
879         Assert.assertFalse(result);
880     }
881 
882     /**
883      * Test of isTag method, of class VCSSVN.
884      * @throws VCSException 
885      */
886     @Test
887     public void testIsTag() throws VCSException {
888 
889         // log
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      * Test of isUpToDate method, of class VCSSVN.
903      * @throws VCSException 
904      */
905     @Test
906     public void testIsUpToDate() throws VCSException {
907 
908         // log
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      * Test of isUpToDate method, of class VCSSVN.
923      * @throws VCSException 
924      * @throws IOException 
925      * @throws SVNException 
926      */
927     @Test
928     public void testIsUpToDate2() throws VCSException, IOException,
929             SVNException {
930 
931         // log
932         if (log.isInfoEnabled()) {
933             log.info("testIsUpToDate2()");
934         }
935 
936         // chechout
937         vcs.checkout(null, false);
938 
939         // modif on local repo
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, // File path
945                 true, // boolean force
946                 false, // boolean mkdir
947                 true, // boolean climbUnversionedParents
948                 SVNDepth.FILES, // SVNDepth depth
949                 false, // boolean includeIgnored
950                 true); // boolean makeParents
951 
952         boolean result = vcs.isUpToDate(file);
953         Assert.assertFalse(result);
954 
955     }
956 
957     /**
958      * Test of isUpToDate method, of class VCSSVN.
959      * @throws VCSException 
960      * @throws IOException 
961      * @throws SVNException 
962      */
963     @Test
964     public void testIsUpToDate3() throws VCSException, IOException,
965             SVNException {
966 
967         // log
968         if (log.isInfoEnabled()) {
969             log.info("testIsUpToDate3()");
970         }
971 
972         // chechout
973         vcs.checkout(null, false);
974 
975         // now, make a modification, on REMOTE repo
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      * Test an update with a local locked file.
991      * 
992      * - Checkout
993      * - commit modification
994      * - update at revision -1
995      * - lock one file
996      * - update at head
997      * 
998      * @throws VCSException 
999      * @throws SVNException 
1000      * @throws IOException 
1001      */
1002     @Test
1003     public void testUpdateWithLock() throws VCSException, SVNException,
1004             IOException {
1005 
1006         // log
1007         if (log.isInfoEnabled()) {
1008             log.info("testUpdateWithLock()");
1009         }
1010 
1011         // chechout
1012         vcs.checkout(null, false);
1013 
1014         // modif on remote repo
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 },// File[] paths,
1021                 false, //boolean keepLocks,
1022                 "modify version", //String commitMessage,
1023                 null, //SVNProperties revisionProperties,
1024                 null,// String[] changelists,
1025                 false, //boolean keepChangelist,
1026                 false, //boolean force,
1027                 SVNDepth.INFINITY); //SVNDepth depth);
1028 
1029         // display : At revision 4
1030         log.debug("Commited, new revision is " + rev.getNewRevision());
1031 
1032         // do a new checkout at revision n-1
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(), // File file
1037                 revision, // SVNRevision revision
1038                 SVNDepth.INFINITY, // SVNDepth depth
1039                 false, // boolean allowUnversionedObstructions
1040                 false); // boolean depthIsSticky
1041         log.debug("Updated at revision " + newRevision);
1042 
1043         // lock that file
1044         /*File[] filesLocal = { new File(vcs.getLocalRepository(), "scripts"
1045                 + File.separator + "version.txt") };
1046         SVNWCClient wcClient = svnManagerLocal.getWCClient();
1047         wcClient.doLock(filesLocal, true, "add lock");*/
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         // try to update...
1054         List<File> filesInConflict = vcs.update(null, true);
1055         Assert.assertTrue("No file should be in conflit", filesInConflict
1056                 .isEmpty());
1057     }
1058 
1059     /**
1060      * Test an update with file in conflict.
1061      * 
1062      * - Checkout
1063      * - commit modification
1064      * - update at revision -1
1065      * - modify one file
1066      * - update at head
1067      * 
1068      * @throws VCSException 
1069      * @throws SVNException 
1070      * @throws IOException 
1071      */
1072     @Test
1073     public void testUpdateWithConflict() throws VCSException, SVNException,
1074             IOException {
1075 
1076         // log
1077         if (log.isInfoEnabled()) {
1078             log.info("testUpdateWithConflict()");
1079         }
1080 
1081         // chechout
1082         vcs.checkout(null, false);
1083 
1084         // modif on remote repo
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 },// File[] paths,
1091                 false, //boolean keepLocks,
1092                 "modify version", //String commitMessage,
1093                 null, //SVNProperties revisionProperties,
1094                 null,// String[] changelists,
1095                 false, //boolean keepChangelist,
1096                 false, //boolean force,
1097                 SVNDepth.INFINITY); //SVNDepth depth);
1098 
1099         // display : At revision 4
1100         log.debug("Commited, new revision is " + rev.getNewRevision());
1101 
1102         // do a new checkout at revision n-1
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(), // File file
1107                 revision, // SVNRevision revision
1108                 SVNDepth.INFINITY, // SVNDepth depth
1109                 false, // boolean allowUnversionedObstructions
1110                 false); // boolean depthIsSticky
1111         log.debug("Updated at revision " + newRevision);
1112 
1113         // modify one file
1114         File file2 = new File(vcs.getLocalRepository(), "scripts"
1115                 + File.separator + "version.txt");
1116         FileUtils.writeStringToFile(file2, "oooooo");
1117 
1118         // try to update...
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      * Test a trunk-to-trunk switch with file in conflict.
1127      * 
1128      * - Checkout tag
1129      * - commit modification
1130      * - swith to trunk
1131      * - modify same file
1132      * - switch to tag
1133      * 
1134      * @throws VCSException 
1135      * @throws SVNException 
1136      * @throws IOException 
1137      */
1138     @Test
1139     public void testSwitchWithConflict() throws VCSException, SVNException,
1140             IOException {
1141 
1142         // log
1143         if (log.isInfoEnabled()) {
1144             log.info("testSwitchWithConflict()");
1145         }
1146 
1147         // chechout tags
1148         vcs.checkout(Versions.valueOf("3.1.0"), false);
1149 
1150         // modif on remote repo on tag :)
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 },// File[] paths,
1157                 false, //boolean keepLocks,
1158                 "modify version", //String commitMessage,
1159                 null, //SVNProperties revisionProperties,
1160                 null,// String[] changelists,
1161                 false, //boolean keepChangelist,
1162                 false, //boolean force,
1163                 SVNDepth.INFINITY); //SVNDepth depth);
1164 
1165         // display : At revision 4
1166         log.debug("Commited, new revision is " + rev.getNewRevision());
1167 
1168         // switch to trunk
1169         vcs.setTag(null);
1170 
1171         // modify one file
1172         File file2 = new File(vcs.getLocalRepository(), "scripts"
1173                 + File.separator + "version.txt");
1174         FileUtils.writeStringToFile(file2, "oooooo");
1175 
1176         // try to update...
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      * Test a checkFileStatus (witch is doing an update)
1185      * 
1186      * - Checkout
1187      * - commit modification
1188      * - update at revision -1
1189      * - modify one file
1190      * - update at head
1191      * 
1192      * @throws VCSException 
1193      * @throws SVNException 
1194      * @throws IOException 
1195      */
1196     @Test
1197     public void testCheckFileStatusWithConflict() throws VCSException, SVNException,
1198             IOException {
1199 
1200         // log
1201         if (log.isInfoEnabled()) {
1202             log.info("testCheckFileStatusWithConflict()");
1203         }
1204 
1205         // chechout
1206         vcs.checkout(null, false);
1207 
1208         // modif on remote repo
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 },// File[] paths,
1215                 false, //boolean keepLocks,
1216                 "modify version", //String commitMessage,
1217                 null, //SVNProperties revisionProperties,
1218                 null,// String[] changelists,
1219                 false, //boolean keepChangelist,
1220                 false, //boolean force,
1221                 SVNDepth.INFINITY); //SVNDepth depth);
1222 
1223         // display : At revision 4
1224         log.debug("Commited, new revision is " + rev.getNewRevision());
1225 
1226         // do a new checkout at revision n-1
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(), // File file
1231                 revision, // SVNRevision revision
1232                 SVNDepth.INFINITY, // SVNDepth depth
1233                 false, // boolean allowUnversionedObstructions
1234                 false); // boolean depthIsSticky
1235         log.debug("Updated at revision " + newRevision);
1236 
1237         // modify one file
1238         File file2 = new File(vcs.getLocalRepository(), "scripts"
1239                 + File.separator + "version.txt");
1240         FileUtils.writeStringToFile(file2, "oooooo");
1241 
1242         // try to update...
1243         List<File> filesInConflict = vcs.checkFileStatus();
1244         Assert.assertNotNull(filesInConflict);
1245         Assert.assertEquals(1, filesInConflict.size());
1246         log.debug("Conflicts are : " + filesInConflict);
1247         
1248         // do it twice doesn't return results
1249         // checkFileStatus is doing a merge
1250         filesInConflict = vcs.checkFileStatus();
1251         Assert.assertNull(filesInConflict);
1252     }
1253 
1254     /**
1255      * Test file local status.
1256      * 
1257      * - Checkout
1258      * - make modification
1259      * - tests
1260      * 
1261      * @throws VCSException 
1262      * @throws SVNException 
1263      * @throws IOException 
1264      */
1265     @Test
1266     public void testGetLocalStatusModified() throws VCSException, SVNException,
1267             IOException {
1268 
1269         // log
1270         if (log.isInfoEnabled()) {
1271             log.info("testGetLocalStatusModified()");
1272         }
1273 
1274         // chechout
1275         vcs.checkout(null, false);
1276 
1277         // modif on remote repo
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      * Test file local status.
1287      * 
1288      * - Checkout
1289      * - delete file (file system delete)
1290      * - tests
1291      * 
1292      * @throws VCSException 
1293      * @throws SVNException 
1294      * @throws IOException 
1295      */
1296     @Test
1297     public void testGetLocalStatusMissing() throws VCSException, SVNException,
1298             IOException {
1299 
1300         // log
1301         if (log.isInfoEnabled()) {
1302             log.info("testGetLocalStatusMissing()");
1303         }
1304 
1305         // chechout
1306         vcs.checkout(null, false);
1307 
1308         // modif on remote repo
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 }