/*******************************************************************************
* Copyright (c) 2013, Perforce Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
package com.perforce.p4java.extension.path.test;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.perforce.p4java.extension.path.PathStringFormat;
import com.perforce.p4java.extension.path.PerforcePath;
import com.perforce.p4java.extension.path.PerforcePathFactory;
/**
*
* @since 2012.1
*/
public class PerforcePathFactoryTest {
private static final String DEPOT_BASE = "//depot/foo/";
private static final String DEPOT_FILENAME = "bar.txt";
private static final String DEPOT_REVISION_1 = "#1";
private static final String DEPOT_REVISION_HEAD = "#head";
@Test
public void getDepotPathWithRevision() {
PerforcePath path = PerforcePathFactory.getPath(DEPOT_BASE
+ DEPOT_FILENAME + DEPOT_REVISION_1);
Assert.assertEquals(DEPOT_BASE, path.getBasePath());
Assert.assertEquals(DEPOT_FILENAME, path.getFileName());
Assert.assertEquals(DEPOT_REVISION_1, path.getRevisionString());
}
@Test
public void getPathWithExplicitHeadRevisionSpecifier() {
PerforcePath path = PerforcePathFactory.getPath(DEPOT_BASE
+ DEPOT_FILENAME + DEPOT_REVISION_HEAD);
Assert.assertEquals(DEPOT_BASE, path.getBasePath());
Assert.assertEquals(DEPOT_FILENAME, path.getFileName());
Assert.assertEquals(DEPOT_REVISION_HEAD, path.getRevisionString());
}
@Test
public void getPathWithNoRevisionSpecifier() {
PerforcePath path = PerforcePathFactory.getPath(DEPOT_BASE
+ DEPOT_FILENAME);
Assert.assertEquals(DEPOT_BASE, path.getBasePath());
Assert.assertEquals(DEPOT_FILENAME, path.getFileName());
Assert.assertEquals("", path.getRevisionString());
}
@Test
public void getPathFromFolder() {
String folderPath = "//depot/foo";
PerforcePath path = PerforcePathFactory.getFolderPath(folderPath);
Assert.assertEquals(folderPath + "/", path.getBasePath());
Assert.assertEquals("", path.getFileName());
Assert.assertEquals("", path.getRevisionString());
}
@Test
public void getPathFromFolderWithTrailingSlash() {
String folderPath = "//depot/foo/";
PerforcePath path = PerforcePathFactory.getFolderPath(folderPath);
Assert.assertEquals(folderPath, path.getBasePath());
Assert.assertEquals("", path.getFileName());
Assert.assertEquals("", path.getRevisionString());
}
@Test
public void getPathFromFolderWithRecursiveMatch() {
String folderPath = "//depot/foo";
PerforcePath path = PerforcePathFactory.getFolderPath(folderPath
+ "/...");
Assert.assertEquals(folderPath + "/", path.getBasePath());
Assert.assertEquals("", path.getFileName());
Assert.assertEquals("...", path.getRevisionString());
}
@Test
public void getPathFromFolderWithSingleLevelMatch() {
String folderPath = "//depot/foo";
PerforcePath path = PerforcePathFactory
.getFolderPath(folderPath + "/*");
Assert.assertEquals(folderPath + "/", path.getBasePath());
Assert.assertEquals("", path.getFileName());
Assert.assertEquals("*", path.getRevisionString());
}
@Test
public void testDoubleQuote() {
// job067795
String depotPath = "//depot/folder%2525/*";
PerforcePath path = PerforcePathFactory.getFolderPath(depotPath);
Assert.assertEquals("//depot/folder%25/", path.getBasePath());
path = PerforcePathFactory.getPath(depotPath);
Assert.assertEquals("//depot/folder%25/", path.getBasePath());
String clientPath = "//depot/folder%%/*";
depotPath = PathStringFormat.ESCAPE.modify(clientPath);
Assert.assertEquals("//depot/folder%25%25/%2A", depotPath);
path = PerforcePathFactory.getPath(depotPath);
Assert.assertEquals("//depot/folder%%/", path.getBasePath());
Assert.assertEquals("*", path.getFileName());
}
}