package com.perforce.p4simulink;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.Test;
import sun.security.krb5.Config;
import com.perforce.p4simulink.connection.P4Config;
public class BasicTest extends P4SimulinkTest {
@Test
public void testCheckP4d() throws Exception {
int ver = p4d.getVersion();
assertTrue(ver >= 20121);
}
@Test
public void testLoadConfig() throws Exception {
File configFile = new File(TESTDIR.getAbsolutePath()
+ "/../.testconfig");
P4Config config = new P4Config(configFile.toPath());
// assertTrue(config.getP4JavaURI() != null);
assertTrue(config.getUser() != null);
}
/*
* @Test public void testBasicOperations() throws Exception { cleanup();
*
* // create some files for add String[] filenames = new String[] {
* "Main/foo.txt", "Main/bar.txt" }; Collection<File> files =
* createAndGenerateFiles(filenames);
*
* // add them to the repository Config config = generateTestConfig();
* P4Adapter p4 = (P4Adapter) factory.getAdapterForThisSandboxDir(TESTDIR,
* new NullApplicationInteractor(), config); p4.setDepotPath("//depot/...");
* p4.login(); IClient client = p4.getClient("simulink.ws", true);
* client.setHostName(""); client.update();
*
* // get file states and ensure that the files are currently not under //
* version control Map<File, FileState> states = p4.getFileState(files); for
* (File file : states.keySet()) { P4FileState state = (P4FileState)
* states.get(file); assertTrue(state.getLocalStatus() ==
* LocalStatus.NOT_UNDER_CM); }
*
* p4.add(files); p4.checkin(files, "");
*
* // files should now be "UNMODIFIED" states = p4.getFileState(files); for
* (File file : states.keySet()) { P4FileState state = (P4FileState)
* states.get(file); assertTrue(state.getLocalStatus() ==
* LocalStatus.UNMODIFIED); }
*
* cleanup();
*
* // see if they exist by checking them out and ensuring the ones we added
* // are present p4.getDepotFiles(files); verifyFiles(files);
*
* // clean up cleanup();
*
* // now open for edit and change the contents of the files files =
* createAndGenerateFiles(filenames); p4.getLatest(); p4.checkout(files);
*
* for (File file : files) { file.setWritable(true); FileWriter writer = new
* FileWriter(file); writer.append("\nEditing this file."); writer.close();
* } p4.getFileState(files); p4.checkin(files, "Edited"); cleanup();
*
* // get list of files and their current revisions List<IFileSpec>
* reconciled = p4.getDepotFiles("//depot/Main/..."); for (IFileSpec spec :
* reconciled) { String localPath = spec.getLocalPathString(); if (localPath
* == null || localPath.isEmpty()) { continue; }
*
* if (localPath.endsWith(filenames[0]) || localPath.endsWith(filenames[1]))
* { int endRev = spec.getEndRevision(); assertTrue(endRev == 2); } }
*
* cleanup();
*
* // file removal tests // ensure that they exist in the depot int found =
* 0; List<IFileSpec> specs = p4.getDepotFiles(); for (IFileSpec spec :
* specs) { String localPath = spec.getLocalPathString(); if (localPath ==
* null || localPath.isEmpty()) { continue; }
*
* if (localPath.endsWith(filenames[0]) || localPath.endsWith(filenames[1]))
* { found++; } }
*
* assertTrue(found == 2);
*
* // now mark them for delete and submit p4.remove(files);
* p4.submitCurrent();
*
* // check for their existence again, and ensure they are gone found = 0;
* specs = p4.getDepotFiles(); for (IFileSpec spec : specs) { String
* localPath = spec.getLocalPathString(); if (localPath == null ||
* localPath.isEmpty()) { continue; }
*
* if (localPath.endsWith(filenames[0]) || localPath.endsWith(filenames[1]))
* { found++; } }
*
* assertTrue(found == 0);
*
* // re-add the files files = createAndGenerateFiles(filenames);
* p4.add(files); p4.checkin(files, ""); p4.getLatest();
*
* // test tags p4.addTag(files, "Tag1", "Adding tag1"); File[] filesArray =
* files.toArray(new File[files.size()]); Collection<String> tags =
* p4.getTags(filesArray[0]); assertTrue(tags.contains("Tag1"));
* assertTrue(tags.size() == 1);
*
* p4.removeTag(files, "Tag1", "Removing tag1"); tags =
* p4.getTags(filesArray[0]); assertTrue(tags.isEmpty());
*
* // test file moves File bar = new File(TESTDIR.getAbsolutePath() +
* "/Main/bar.txt"); File baz = new File(TESTDIR.getAbsolutePath() +
* "/Main/baz.txt"); p4.moveFile(bar, baz);
*
* // ensure we can find the new one, but not the old boolean oldFound =
* false; boolean newFound = false; files = new ArrayList<>();
* files.add(bar); files.add(baz); try { p4.checkin(files, ""); } catch
* (Exception e) { e.printStackTrace(); } p4.getLatest(); specs =
* p4.getDepotFiles(); for (IFileSpec spec : specs) { String localPath =
* spec.getLocalPathString(); if (localPath == null || localPath.isEmpty())
* { continue; }
*
* if (localPath.equalsIgnoreCase(bar.getAbsolutePath())) { oldFound = true;
* }
*
* if (localPath.equalsIgnoreCase(baz.getAbsolutePath())) { newFound = true;
* } }
*
* assertTrue(!oldFound && newFound); }
*/
}
# |
Change |
User |
Description |
Committed |
|
#1
|
11899 |
Paul Allen |
Inprogress development - moved work to branch |
|
|