Author: chatellier Date: 2009-02-04 14:58:44 +0000 (Wed, 04 Feb 2009) New Revision: 1787 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java Log: MOdification de certains parametres, pour pesser les lock... Ajout de tests. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2009-02-04 10:31:59 UTC (rev 1786) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/vcs/VCSSVN.java 2009-02-04 14:58:44 UTC (rev 1787) @@ -962,7 +962,7 @@ long newRevision = updateClient.doUpdate(localFile, // File file SVNRevision.HEAD, // SVNRevision revision recurse ? SVNDepth.INFINITY : SVNDepth.FILES, // SVNDepth depth - false, // boolean allowUnversionedObstructions + true, // boolean allowUnversionedObstructions false); // boolean depthIsSticky if (log.isInfoEnabled()) { @@ -1097,7 +1097,7 @@ //getSVNManager().getUpdateClient().doSwitch( // localRoot, newUrl, SVNRevision.HEAD, true); - // svnkit 1.3 code + // svnkit 1.2 code SVNUpdateClient updateClient = getSVNManager() .getUpdateClient(); long newRevision = updateClient.doSwitch(localRoot, // File path @@ -1105,9 +1105,13 @@ SVNRevision.HEAD, // SVNRevision pegRevision SVNRevision.HEAD, // SVNRevision revision SVNDepth.INFINITY, // SVNDepth depth - false, // boolean allowUnversionedObstructions - true);// boolean depthIsSticky + true, // boolean allowUnversionedObstructions + false);// boolean depthIsSticky + // chatellier: allowUnversionedObstructions must be true + // if there is unversionned file or folder in repo, update will fail + // with org.tmatesoft.svn.core.SVNException: svn: Unable to lock 'xxx' + if (log.isInfoEnabled()) { log.info(_("isisfish.vcs.vcssvn.global.torevision", newRevision)); } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-02-04 10:31:59 UTC (rev 1786) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-02-04 14:58:44 UTC (rev 1787) @@ -35,6 +35,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.tmatesoft.svn.core.SVNCommitInfo; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNURL; @@ -43,8 +44,11 @@ import org.tmatesoft.svn.core.wc.SVNCopySource; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNStatus; +import org.tmatesoft.svn.core.wc.SVNUpdateClient; import org.tmatesoft.svn.core.wc.SVNWCClient; +import fr.ifremer.isisfish.IsisFish; + /** * Class de test VCS. * @@ -60,35 +64,38 @@ /** Class logger */ private static Log log = LogFactory.getLog(VCSSVNTest.class); - + public static final String TMPDIR = System.getProperty("java.io.tmpdir"); - + public static final String FILECONTENTTAG = "Version 3.1.0"; public static final String FILECONTENTTRUNK = "Version 3.2.0"; - + protected static File template; protected static File remoteRepo; protected static File localRepo; protected static File localRepoTrunk; - + protected VCSSVN vcs = null; - + /** * Constructor. */ public VCSSVNTest() { - + } - + /** * Static test init. + * @throws Exception */ @BeforeClass - public static void init() { - template = new File(TMPDIR + "/testsvn-template"); - remoteRepo = new File(TMPDIR + "/testsvn-repo"); - localRepo = new File(TMPDIR + "/testsvn-local"); - localRepoTrunk = new File(TMPDIR + "/testsvn-localTrunk"); + public static void init() throws Exception { + IsisFish.init(); + + template = new File(TMPDIR, "testsvn-template"); + remoteRepo = new File(TMPDIR, "testsvn-repo"); + localRepo = new File(TMPDIR, "testsvn-local"); + localRepoTrunk = new File(TMPDIR, "testsvn-localTrunk"); } /** @@ -110,7 +117,7 @@ FileUtil.deleteRecursively(localRepoTrunk); } } - + /** * Init call before each test. * @throws IOException @@ -118,62 +125,61 @@ */ @Before public void setUp() throws IOException, SVNException { - + // un peu de nettoyage clean(); - + // creation de l'instance de notre VCS pour les tests // on le fait au debut pour que la l'init de la lib svn soit fait // par la classe elle meme et ainsi tester que ca marche - vcs = new VCSSVN( - localRepo, - "file", - "", - remoteRepo.getAbsolutePath() + "/isis-fish-data", - null, - "", ""); - + vcs = new VCSSVN(localRepo, "file", "", remoteRepo.getAbsolutePath() + + "/isis-fish-data", null, "", ""); + // Creation d'un repo local avec un trunk et un tag // durant le test, on modifie version.txt pour utiliser // fileContentTrunk et modifier le contenu. On peut alors tester // le changement de tag en fonction du contenu du fichier - + // creation d'un template de directory - new File(template, "regions" + File.separator + "DemoRegion" + File.separator + "data").mkdirs(); - new File(template, "simulations" + File.separator + "simu1" + File.separator + "data").mkdirs(); + new File(template, "regions" + File.separator + "DemoRegion" + + File.separator + "data").mkdirs(); + new File(template, "simulations" + File.separator + "simu1" + + File.separator + "data").mkdirs(); new File(template, "scripts").mkdirs(); - FileUtil.writeString(new File(template, "scripts" + File.separator + "version.txt"), FILECONTENTTAG); + FileUtil.writeString(new File(template, "scripts" + File.separator + + "version.txt"), FILECONTENTTAG); // creation du repo pour les tests SVNRepositoryFactory.createLocalRepository(remoteRepo, false, true); - + // ajout de source dans le repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnRoot = svnURL.appendPath("isis-fish-data", false); SVNURL svnTrunk = svnRoot.appendPath("trunk", false); SVNURL svnTags = svnRoot.appendPath("tags", false); - + SVNClientManager svnManager = SVNClientManager.newInstance(); // creation de l'arborescence - svnManager.getCommitClient().doMkDir(new SVNURL[]{svnRoot, svnTrunk, svnTags}, "add dir"); + svnManager.getCommitClient().doMkDir( + new SVNURL[] { svnRoot, svnTrunk, svnTags }, "add dir"); //svnManager.getCommitClient().doImport(template, svnTrunk, "initial import", true, true); - svnManager.getCommitClient().doImport(template, svnTrunk, "initial import", null, true, true, SVNDepth.INFINITY); + svnManager.getCommitClient().doImport(template, svnTrunk, + "initial import", null, true, true, SVNDepth.INFINITY); // 1.1.x svnManager.getCopyClient().doCopy(svnTrunk, SVNRevision.HEAD, svnTags.appendPath("3.1.0", false), false, true, "Create tag"); - SVNCopySource source = new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, svnTrunk); - - svnManager.getCopyClient().doCopy( - new SVNCopySource[]{source}, - svnTags.appendPath("3.1.0", false), - false, /*isMove*/ + SVNCopySource source = new SVNCopySource(SVNRevision.HEAD, + SVNRevision.HEAD, svnTrunk); + + svnManager.getCopyClient().doCopy(new SVNCopySource[] { source }, + svnTags.appendPath("3.1.0", false), false, /*isMove*/ true, /*makeParents*/ true, /*failWhenDstExists*/ - "Create tag", - null); + "Create tag", null); } - + /** * After each test. */ @@ -182,57 +188,58 @@ // un peu de nettoyage //clean(); } - + /** * Test of getSVNManager method, of class VCSSVN. */ @Test public void testgetSVNManager() { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testgetSVNManager()"); } - + SVNClientManager result = vcs.getSVNManager(); Assert.assertNotNull(result); } - + /** * Test of getRemoteURL method, of class VCSSVN. * @throws SVNException */ @Test public void testgetRemoteURL() throws SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testgetRemoteURL()"); } - - SVNURL expResult = SVNURL.create("file", null, "", -1, - remoteRepo.getAbsolutePath() + "/" + "isis-fish-data", true); + + SVNURL expResult = SVNURL.create("file", null, "", -1, remoteRepo + .getAbsolutePath() + + "/" + "isis-fish-data", true); SVNURL result = vcs.getRemoteURL(); Assert.assertEquals(expResult, result); } - + /** * Test of isVersionnableAbleFile method, of class VCSSVN. */ @Test public void testIsVersionnableAbleFile() { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsVersionnableAbleFile()"); } - + // un fichier special, on refuse File file = new File(".svn"); boolean result = vcs.isVersionnableAbleFile(file); Assert.assertFalse(result); - + // Pas dans le repository local, on refuse file = new File("Toto.java"); result = vcs.isVersionnableAbleFile(file); @@ -242,33 +249,33 @@ file = new File(vcs.getLocalRepository(), "Toto.java"); result = vcs.isVersionnableAbleFile(file); Assert.assertEquals(true, result); - + // match pas (svn ignore) file = new File(vcs.getLocalRepository(), "libaudio.la"); result = vcs.isVersionnableAbleFile(file); Assert.assertFalse(result); - + // match pas (svn ignore) file = new File(vcs.getLocalRepository(), "libaudio.lo"); result = vcs.isVersionnableAbleFile(file); Assert.assertFalse(result); - + // match (svn ignore) file = new File(vcs.getLocalRepository(), "libaudio.lads"); result = vcs.isVersionnableAbleFile(file); Assert.assertTrue(result); - + // match pas (svn ignore) file = new File(vcs.getLocalRepository(), "libaudio.lads~"); result = vcs.isVersionnableAbleFile(file); Assert.assertFalse(result); - + // match pas (svn ignore) file = new File(vcs.getLocalRepository(), "commit.rev1234.rej"); result = vcs.isVersionnableAbleFile(file); Assert.assertFalse(result); } - + /** * Test of checkout method, of class VCSSVN. * @throws IOException @@ -276,133 +283,140 @@ */ @Test public void testAll() throws IOException, VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsVersionnableAbleFile()"); } - + // trunk contient une copie complete de trunk, elle permet de test // status lors que l'on fait des commits sur le trunk sur instance - VCSSVN trunk = new VCSSVN( - localRepoTrunk, - "file", - "", - remoteRepo.getAbsolutePath() + "/" + "isis-fish-data", - null, - "", ""); - + VCSSVN trunk = new VCSSVN(localRepoTrunk, "file", "", remoteRepo + .getAbsolutePath() + + "/" + "isis-fish-data", null, "", ""); + trunk.checkout(null, true); // on ne checkout rien juste le .svn dans le repertoire racine vcs.checkout(null, false); Assert.assertTrue(vcs.getLocalRepository().exists()); Assert.assertTrue(vcs.getTag().startsWith("/trunk")); - + // update scripts dir vcs.update(new File(vcs.getLocalRepository(), "scripts"), true); - File version = new File(vcs.getLocalRepository(), "scripts" + File.separator + "version.txt"); + File version = new File(vcs.getLocalRepository(), "scripts" + + File.separator + "version.txt"); Assert.assertTrue(version.exists()); Assert.assertEquals(FILECONTENTTAG, FileUtil.readAsString(version)); - + // modification du fichier version.txt FileUtil.writeString(version, FILECONTENTTRUNK); vcs.commit(null, "modif du fichier version"); Assert.assertEquals(FILECONTENTTRUNK, FileUtil.readAsString(version)); - + // recuperation de DemoRegion - File demo = new File(vcs.getLocalRepository(), "regions" + File.separator + "DemoRegion"); + File demo = new File(vcs.getLocalRepository(), "regions" + + File.separator + "DemoRegion"); vcs.update(demo, true); Assert.assertTrue(demo.exists()); - + // suppression de DemoRegion vcs.delete(Arrays.asList(demo), "suppression d'une region"); Assert.assertFalse(demo.exists()); - + // ajout d'un fichier sur le trunk avant passage sur le tag File fileToAdd = new File(vcs.getLocalRepository(), "newfile.txt"); String lecontent = "Le nouveau fichier"; FileUtil.writeString(fileToAdd, lecontent); vcs.add(Arrays.asList(fileToAdd), "ajout d'un fichier"); - + // test switchTag vcs.setTag(new VersionNumber(3, 1, 0)); Assert.assertTrue(vcs.getTag().startsWith("/tags/3.1.0")); Assert.assertEquals(FILECONTENTTAG, FileUtil.readAsString(version)); Assert.assertTrue(demo.exists()); - + // recherche du status des fichiers - File fileVersion = new File(trunk.getLocalRepository(), "scripts" + File.separator + "version.txt"); - File fileDeleted = new File(trunk.getLocalRepository(), "regions" + File.separator + "DemoRegion"); - Map<File, SVNStatus> map = trunk.getRemoteStatus(trunk.getLocalRepository(), true); + File fileVersion = new File(trunk.getLocalRepository(), "scripts" + + File.separator + "version.txt"); + File fileDeleted = new File(trunk.getLocalRepository(), "regions" + + File.separator + "DemoRegion"); + Map<File, SVNStatus> map = trunk.getRemoteStatus(trunk + .getLocalRepository(), true); Assert.assertEquals(2, map.size()); // version.txt modifie, DemoRegion supprimee Assert.assertTrue(map.containsKey(fileVersion)); Assert.assertTrue(map.containsKey(fileDeleted)); - + // modif dans repo trunk de version pour qu'il y ait un conflit FileUtil.writeString(fileVersion, "Le nouveau content de version"); - + // update global du repo trunk List<File> conflictFile = trunk.update(null, true); - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("conflictFile: " + conflictFile.toString()); } Assert.assertEquals(1, conflictFile.size()); Assert.assertTrue(conflictFile.contains(fileVersion)); - + File fileAdded = new File(trunk.getLocalRepository(), "newfile.txt"); Assert.assertEquals(lecontent, FileUtil.readAsString(fileAdded)); Assert.assertFalse(fileDeleted.exists()); // recherche du status des fichiers en remote, il ne doit plus y avoir de diff - Map<File, SVNStatus> map2 = trunk.getRemoteStatus(trunk.getLocalRepository(), true); + Map<File, SVNStatus> map2 = trunk.getRemoteStatus(trunk + .getLocalRepository(), true); Assert.assertEquals(0, map2.size()); // il doit toujours y avoir version.txt qui est modifier localement - Map<File, SVNStatus> map3 = trunk.getLocalStatus(trunk.getLocalRepository(), true); + Map<File, SVNStatus> map3 = trunk.getLocalStatus(trunk + .getLocalRepository(), true); Assert.assertEquals(1, map3.size()); Assert.assertTrue(map3.containsKey(fileVersion)); - + // on commit le fichier version.txt pour verifier qu'en local et remote // il n'y a plus de modif - trunk.commit(Arrays.asList(fileVersion), "Commit fichier version, avec les conflits"); - Map<File, SVNStatus> map4 = trunk.getRemoteStatus(trunk.getLocalRepository(), true); + trunk.commit(Arrays.asList(fileVersion), + "Commit fichier version, avec les conflits"); + Map<File, SVNStatus> map4 = trunk.getRemoteStatus(trunk + .getLocalRepository(), true); Assert.assertEquals(0, map4.size()); - Map<File, SVNStatus> map5 = trunk.getLocalStatus(trunk.getLocalRepository(), true); + Map<File, SVNStatus> map5 = trunk.getLocalStatus(trunk + .getLocalRepository(), true); Assert.assertEquals(0, map5.size()); } - + /** * Test of add method, of class VCSSVN. * @throws VCSException */ @Test public void testAdd() throws VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testAdd()"); } - + List<File> files = new ArrayList<File>(); String msg = ""; // checkout a TAG - vcs.checkout(new VersionNumber(3, 1, 0),false); + vcs.checkout(new VersionNumber(3, 1, 0), false); try { vcs.add(files, msg); - - Assert.fail("Une exception aurait du etre leve, car instance est" + - " sur un tag, donc en readonly"); + + Assert.fail("Une exception aurait du etre leve, car instance est" + + " sur un tag, donc en readonly"); } catch (VCSException e) { // l'exception est normal et fait partie du test - if(log.isDebugEnabled()) { - log.debug("VCSException has normally been thrown : " + e.getMessage()); + if (log.isDebugEnabled()) { + log.debug("VCSException has normally been thrown : " + + e.getMessage()); } } } - + /** * Verifie la connexion et si le protocole a change, switch le repository * pour utiliser le nouveau protocole. Si on est en mode interface (mode @@ -412,12 +426,12 @@ */ @Test public void testCheckProtocol() throws VCSException { - + vcs.checkout(null, false); - + vcs.checkProtocol(); } - + /** * Return all changelog between local file version and remote repository * file version. @@ -427,40 +441,45 @@ * */ @Ignore - public void testGetChanglog() throws VCSException, IOException, SVNException { - + public void testGetChanglog() throws VCSException, IOException, + SVNException { + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetChanglog()"); } - - File firstFile = new File(vcs.getLocalRepository() + File.separator + "scripts" + File.separator + "version.txt"); - File secondFile = new File(vcs.getLocalRepository() + File.separator + "simulations" + File.separator + "simu1" + File.separator + "simulation.properties"); + + File firstFile = new File(vcs.getLocalRepository() + File.separator + + "scripts" + File.separator + "version.txt"); + File secondFile = new File(vcs.getLocalRepository() + File.separator + + "simulations" + File.separator + "simu1" + File.separator + + "simulation.properties"); List<File> files = new ArrayList<File>(); files.add(firstFile); files.add(secondFile); - + Map<File, String> expResult = new HashMap<File, String>(); expResult.put(new File("ooo"), "eee"); - + // first, checkout trunk vcs.checkout(null, true); - + // now, make a modification, on LOCAL repo FileUtil.writeString(firstFile, "version 3.2.1"); FileUtil.writeString(secondFile, "name = test1"); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getWCClient().doAdd( - secondFile, // File path + svnManager.getWCClient().doAdd(secondFile, // File path true, // boolean force false, // boolean mkdir true, // boolean climbUnversionedParents SVNDepth.FILES, // SVNDepth depth false, // boolean includeIgnored true); // boolean makeParents - svnManager.getCommitClient().doCommit(new File[]{firstFile, secondFile}, false, - "mise a jour de la version", null, null, false, true, SVNDepth.INFINITY); - + svnManager.getCommitClient().doCommit( + new File[] { firstFile, secondFile }, false, + "mise a jour de la version", null, null, false, true, + SVNDepth.INFINITY); + Map<File, String> result = vcs.getChanglog(files); Assert.assertEquals(expResult, result); } @@ -472,21 +491,22 @@ */ @Test public void testGetDiff() throws VCSException, IOException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetDiff()"); } - - File firstFile = new File(vcs.getLocalRepository() + File.separator + "scripts" + File.separator + "version.txt"); - + + File firstFile = new File(vcs.getLocalRepository() + File.separator + + "scripts" + File.separator + "version.txt"); + vcs.checkout(null, true); - + // now, make a modification, on LOCAL repo FileUtil.writeString(firstFile, "Version 3.2.1"); String result = vcs.getDiff(firstFile); - + // quelques tests sur la sortie, pas // d'égalité parfaite Assert.assertTrue(result.indexOf("version.txt") > 0); @@ -501,14 +521,14 @@ */ @Test public void testGetFileList() throws VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetFileList()"); } vcs.checkout(null, true); - + File directory = null; List<String> expResult = new ArrayList<String>(3); expResult.add("regions"); @@ -517,7 +537,7 @@ List<String> result = vcs.getFileList(directory); Assert.assertEquals(expResult, result); } - + /** * Test of getFileList method, of class VCSSVN. * @throws VCSException @@ -525,28 +545,27 @@ */ @Test public void testGetFileList2() throws VCSException, SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetFileList2()"); } vcs.checkout(null, true); - + // add new directory File newDir = new File(vcs.getLocalRepository() + "/testadddir"); newDir.mkdir(); - + SVNWCClient wcClient = vcs.getSVNManager().getWCClient(); - wcClient.doAdd( - newDir, // File path + wcClient.doAdd(newDir, // File path true, // boolean force false, // boolean mkdir true, // boolean climbUnversionedParents SVNDepth.FILES, // SVNDepth depth false, // boolean includeIgnored true); // boolean makeParents - + // previous added dir, should not appear in list File directory = null; List<String> expResult = new ArrayList<String>(3); @@ -567,22 +586,23 @@ */ @Test public void testGetFileList3() throws VCSException, SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetFileList3()"); } - + // checkout current trunk vcs.checkout(null, true); // now, make a modification, on REMOTE repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false) - .appendPath("trunk", false) - .appendPath("test", false); + .appendPath("trunk", false).appendPath("test", false); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getCommitClient().doMkDir(new SVNURL[]{svnURLNewDir}, "add test dir"); + svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir }, + "add test dir"); // previous added dir, should appear in list File directory = null; @@ -594,7 +614,7 @@ List<String> result = vcs.getFileList(directory); Assert.assertEquals(expResult, result); } - + /** * Test of getUpdatedFile method, of class VCSSVN. * @throws VCSException @@ -602,32 +622,35 @@ * @throws SVNException */ @Test - public void testGetUpdatedFile() throws VCSException, IOException, SVNException { - + public void testGetUpdatedFile() throws VCSException, IOException, + SVNException { + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetUpdatedFile()"); } - + List<File> expResult = new ArrayList<File>(); - expResult.add(new File(vcs.getLocalRepository().getAbsolutePath() + File.separator + "test")); + expResult.add(new File(vcs.getLocalRepository().getAbsolutePath() + + File.separator + "test")); expResult.add(vcs.getLocalRepository()); - + // checkout current trunk vcs.checkout(null, true); - + // now, make a modification, on REMOTE repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false) - .appendPath("trunk", false) - .appendPath("test", false); + .appendPath("trunk", false).appendPath("test", false); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getCommitClient().doMkDir(new SVNURL[]{svnURLNewDir}, "add test dir"); - + svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir }, + "add test dir"); + List<File> result = vcs.getUpdatedFile(); Assert.assertEquals(expResult, result); } - + /** * Test of getUpdatedFile method, of class VCSSVN. * @throws VCSException @@ -635,21 +658,22 @@ * @throws SVNException */ @Test - public void testGetUpdatedFileEmptyResult() throws VCSException, IOException, SVNException { - + public void testGetUpdatedFileEmptyResult() throws VCSException, + IOException, SVNException { + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetUpdatedFile()"); } List<File> expResult = new ArrayList<File>(); - + // checkout current trunk vcs.checkout(null, true); - + List<File> result = vcs.getUpdatedFile(); Assert.assertEquals(expResult, result); - + } /** @@ -660,27 +684,28 @@ */ @Test public void testHaveUpdate() throws VCSException, SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testHaveUpdate()"); } // checkout current trunk vcs.checkout(null, true); - + // now, make a modification, on REMOTE repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false) - .appendPath("trunk", false) - .appendPath("test", false); + .appendPath("trunk", false).appendPath("test", false); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getCommitClient().doMkDir(new SVNURL[]{svnURLNewDir}, "add test dir"); - + svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir }, + "add test dir"); + boolean result = vcs.haveUpdate(); Assert.assertTrue(result); } - + /** * Ask if there are some new or modified files on server. * @@ -689,15 +714,15 @@ */ @Test public void testHaveNoUpdate() throws VCSException, SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testHaveNoUpdate()"); } // checkout current trunk vcs.checkout(null, true); - + boolean result = vcs.haveUpdate(); Assert.assertFalse(result); } @@ -707,9 +732,9 @@ */ @Test public void testIsConnected() { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsConnected()"); } @@ -723,38 +748,39 @@ */ @Test public void testIsOnRemote() throws VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsOnRemote()"); } vcs.checkout(null, false); - + File file = null; boolean result = vcs.isOnRemote(file); Assert.assertTrue(result); } - + /** * Test of isOnRemote method, of class VCSSVN. * @throws VCSException */ @Test public void testIsOnRemote2() throws VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsOnRemote2()"); } vcs.checkout(null, false); - - File file = new File(vcs.getLocalRepository() + File.separator + "scripts" + File.separator + "version.txt"); + + File file = new File(vcs.getLocalRepository() + File.separator + + "scripts" + File.separator + "version.txt"); boolean result = vcs.isOnRemote(file); Assert.assertTrue(result); } - + /** * Test of isOnRemote method, of class VCSSVN. * @throws VCSException @@ -762,27 +788,28 @@ */ @Test public void testIsOnRemote3() throws VCSException, SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsOnRemote3()"); } vcs.checkout(null, false); - + // now, make a modification, on REMOTE repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false) - .appendPath("trunk", false) - .appendPath("test", false); + .appendPath("trunk", false).appendPath("test", false); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getCommitClient().doMkDir(new SVNURL[]{svnURLNewDir}, "add test dir"); - + svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir }, + "add test dir"); + File file = new File(vcs.getLocalRepository() + File.separator + "test"); boolean result = vcs.isOnRemote(file); Assert.assertTrue(result); } - + /** * Test of isOnRemote method, of class VCSSVN. * @throws VCSException @@ -790,27 +817,29 @@ */ @Test public void testIsOnRemote4() throws VCSException, SVNException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsOnRemote4()"); } vcs.checkout(null, false); - + // now, make a modification, on REMOTE repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false) - .appendPath("trunk", false) - .appendPath("scripts", false); + .appendPath("trunk", false).appendPath("scripts", false); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getCommitClient().doDelete(new SVNURL[]{svnURLNewDir}, "del scripts dir"); - - File file = new File(vcs.getLocalRepository() + File.separator + "scripts"); + svnManager.getCommitClient().doDelete(new SVNURL[] { svnURLNewDir }, + "del scripts dir"); + + File file = new File(vcs.getLocalRepository() + File.separator + + "scripts"); boolean result = vcs.isOnRemote(file); Assert.assertFalse(result); } - + /** * Test of isOnRemote method, of class VCSSVN. * @throws VCSException @@ -818,21 +847,22 @@ * @throws IOException */ @Test - public void testIsOnRemote5() throws VCSException, SVNException, IOException { - + public void testIsOnRemote5() throws VCSException, SVNException, + IOException { + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsOnRemote5()"); } vcs.checkout(null, false); - + // modif on local repo - File file = new File(vcs.getLocalRepository() + File.separator + "test.txt"); + File file = new File(vcs.getLocalRepository() + File.separator + + "test.txt"); FileUtil.writeString(file, "name = test1"); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getWCClient().doAdd( - file, // File path + svnManager.getWCClient().doAdd(file, // File path true, // boolean force false, // boolean mkdir true, // boolean climbUnversionedParents @@ -850,18 +880,18 @@ */ @Test public void testIsTag() throws VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testGetDiff()"); } - VersionNumber version = new VersionNumber(3,1,0); + VersionNumber version = new VersionNumber(3, 1, 0); boolean expResult = true; boolean result = vcs.isTag(version); Assert.assertEquals(expResult, result); - version = new VersionNumber(3,2,0); + version = new VersionNumber(3, 2, 0); expResult = false; result = vcs.isTag(version); Assert.assertEquals(expResult, result); @@ -873,20 +903,20 @@ */ @Test public void testIsUpToDate() throws VCSException { - + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsUpToDate()"); } vcs.checkout(null, false); - + File file = null; boolean result = vcs.isUpToDate(file); Assert.assertTrue(result); - + } - + /** * Test of isUpToDate method, of class VCSSVN. * @throws VCSException @@ -894,22 +924,23 @@ * @throws SVNException */ @Test - public void testIsUpToDate2() throws VCSException, IOException, SVNException { - + public void testIsUpToDate2() throws VCSException, IOException, + SVNException { + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsUpToDate2()"); } // chechout vcs.checkout(null, false); - + // modif on local repo - File file = new File(vcs.getLocalRepository() + File.separator + "test.txt"); + File file = new File(vcs.getLocalRepository() + File.separator + + "test.txt"); FileUtil.writeString(file, "name = test1"); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getWCClient().doAdd( - file, // File path + svnManager.getWCClient().doAdd(file, // File path true, // boolean force false, // boolean mkdir true, // boolean climbUnversionedParents @@ -919,9 +950,9 @@ boolean result = vcs.isUpToDate(file); Assert.assertFalse(result); - + } - + /** * Test of isUpToDate method, of class VCSSVN. * @throws VCSException @@ -929,27 +960,98 @@ * @throws SVNException */ @Test - public void testIsUpToDate3() throws VCSException, IOException, SVNException { - + public void testIsUpToDate3() throws VCSException, IOException, + SVNException { + // log - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { log.info("testIsUpToDate3()"); } // chechout vcs.checkout(null, false); - + // now, make a modification, on REMOTE repo - SVNURL svnURL = SVNURL.parseURIDecoded("file://" + remoteRepo.getAbsolutePath()); + SVNURL svnURL = SVNURL.parseURIDecoded("file://" + + remoteRepo.getAbsolutePath()); SVNURL svnURLNewDir = svnURL.appendPath("isis-fish-data", false) - .appendPath("trunk", false) - .appendPath("test", false); + .appendPath("trunk", false).appendPath("test", false); SVNClientManager svnManager = SVNClientManager.newInstance(); - svnManager.getCommitClient().doMkDir(new SVNURL[]{svnURLNewDir}, "add test dir"); + svnManager.getCommitClient().doMkDir(new SVNURL[] { svnURLNewDir }, + "add test dir"); File file = new File(vcs.getLocalRepository() + File.separator + "test"); boolean result = vcs.isUpToDate(file); Assert.assertFalse(result); + + } + + /** + * Test an update with a local locked file. + * + * - Checkout + * - commit modification + * - update at revision -1 + * - lock one file + * - update at head + * + * @throws VCSException + * @throws SVNException + * @throws IOException + */ + @Test + public void testUpdateWithLock() throws VCSException, SVNException, + IOException { + + // log + if (log.isInfoEnabled()) { + log.info("testUpdateWithLock()"); + } + + // chechout + vcs.checkout(null, false); + + // modif on remote repo + File file = new File(vcs.getLocalRepository(), "scripts" + + File.separator + "version.txt"); + FileUtil.writeString(file, "aaaaaz"); + SVNClientManager svnManager = SVNClientManager.newInstance(); + SVNCommitInfo rev = svnManager.getCommitClient().doCommit( + new File[] { file },// File[] paths, + false, //boolean keepLocks, + "modify version", //String commitMessage, + null, //SVNProperties revisionProperties, + null,// String[] changelists, + false, //boolean keepChangelist, + false, //boolean force, + SVNDepth.INFINITY); //SVNDepth depth); + + // display : At revision 4 + log.debug("Commited, new revision is " + rev.getNewRevision()); + + // do a new checkout at revision n-1 + SVNRevision revision = SVNRevision.create(rev.getNewRevision() - 1); + SVNClientManager svnManagerLocal = vcs.getSVNManager(); + SVNUpdateClient updateClient = svnManagerLocal.getUpdateClient(); + long newRevision = updateClient.doUpdate(vcs.getLocalRepository(), // File file + revision, // SVNRevision revision + SVNDepth.INFINITY, // SVNDepth depth + false, // boolean allowUnversionedObstructions + false); // boolean depthIsSticky + log.debug("Updated at revision " + newRevision); + + // lock that file + /*File[] filesLocal = { new File(vcs.getLocalRepository(), "scripts" + + File.separator + "version.txt") }; + SVNWCClient wcClient = svnManagerLocal.getWCClient(); + wcClient.doLock(filesLocal, true, "add lock");*/ + + Map<File, SVNStatus> files = vcs.getRemoteStatus(null, true); + log.info("Will update file = " + files.keySet()); + Assert.assertTrue("Must be one file updated", files.size() == 1); + // try to update... + List<File> filesInConflict = vcs.update(null, true); + Assert.assertTrue("No file should be in conflit", filesInConflict.isEmpty()); } } \ No newline at end of file