package com.perforce.p4simulink.test; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileWriter; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import org.junit.Test; import com.mathworks.cmlink.api.FileState; import com.mathworks.cmlink.api.LocalStatus; import com.mathworks.cmlink.util.interactor.NullApplicationInteractor; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4simulink.P4Adapter; import com.perforce.p4simulink.connection.Config; import com.perforce.p4simulink.workspace.P4FileState; 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"); Config config = new Config(configFile); config.load(true); config.setPassword("Password"); 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 | |
---|---|---|---|---|---|
#2 | 11899 | Paul Allen | Inprogress development - moved work to branch | ||
#1 | 11898 | Paul Allen |
Populate -o //guest/perforce_software/p4sl/main/... //guest/paul_allen/p4sl/.... |
||
//guest/perforce_software/p4sl/main/src/test/java/com/perforce/p4simulink/test/BasicTest.java | |||||
#12 | 11681 | Paul Allen |
Fixes to unit tests. - Fixed paths for testMove in OverrideTests - Removed adding of target before a move. - Closing of resources; writer - Added missing serialisation ID - removed unused variables. |
||
#11 | 11672 | Paul Allen |
Tidy up formatting and imports. No functional change. |
||
#10 | 11658 | Paul Allen |
Additional unit/functional tests. Transferred from p4://perforce.perforce.com:1666@980860 |
||
#9 | 11654 | Paul Allen |
Additional unit tests for @Override methods, refactored test classes. Transferred from p4://perforce.perforce.com:1666@976891 |
||
#8 | 11645 | Paul Allen |
Refactoring and additional work on UI: Removed Connection class and went with global server/client objects. Implemented panes for connection, depot path and passwords. Passwords are only requested when required. Transferred from p4://perforce.perforce.com:1666@957149 |
||
#7 | 11644 | Paul Allen |
Paul's changes: Refactor getAddress and getAddressForConfig to getPort and getP4JavaURI. There were a few cases when the wrong value was written + getPort was not working. Password had a null password object (now initilised) P4PaswordPane needs some work - must talk to Perfoce to see if it needs a pass or is already logged in. There are still sync -f (this is very bad) Think I miss understood the checkout method after finding and reading the JavaDoc. You were right to start. Looks like a p4 edit. Would like to set a break point and find out when it is used. Elliot's changes: * Changed export() to use p4 'print' * Connect/login now looks for P4TICKETS env var * Config no longer stores P4PASSWD or P4TICKETS * Removed P4TICKET functionality (was only for P4Jenkins) * Ensured we're using a global IServer object * checkout() now uses editFiles() (opens all files for edit) * Changed all "sync -f" to plain "sync" * Removed final client update with force flag * Removed error dialogues regarding login issues * Investigated use of P4IGNORE - I'll need to write my own filter, no big deal Transferred from p4://perforce.perforce.com:1666@955247 |
||
#6 | 11643 | Paul Allen |
Unshelved from pending changelist '953729': Paul: Added: - getWorkspaceState() -- run a p4 status - getOpenedState() -- run p4 opened - getIgnoreState() -- run p4 add -n Modified: - add() -- seemed to call reopen? - P4FileState -- simple constructor for state Elliot: * global client and changelist object within the adapter * removed repeated client updates and changelist refreshes * removed 'reopen' in add * added calls to 'edit' where appropriate file states are found * made 'checkout' a pure sync, with no edits * commented a bunch of the @Override methods * added a call to haveList in getFileState so we can see versions of files in the project * changed the connection pane to look like p4v's * refactored a bit of the dialogue code, added calls to prompt for password (like p4v) * changed all log.trace() calls to log.debug() so the log file messiness can be controlled more easily Functionality that now works properly: * open project from source control, with properly-configured .p4config file * add new project to source control, with properly-configured .p4config file * add * edit * commit * revert * compare reversions (opens Simulink diff tool) Things to work on: * dialogues (particularily the password one, but the connection one is a bit dodge-y) * remove from project (possibly always making the Simulink project meta-data editable will fix this - it *almost* works) - the current issue is Simulink needs to edit the meta-data, but Perforce has made the files read-only, so Simulink throws up on itself Transferred from p4://perforce.perforce.com:1666@954622 |
||
#5 | 11642 | Paul Allen |
More fixes from discussion with Paul and after looking at other integrations work. Transferred from p4://perforce.perforce.com:1666@953553 |
||
#4 | 11640 | Paul Allen |
Fixes to project integrity checks within Simulink. Transferred from p4://perforce.perforce.com:1666@952945 |
||
#3 | 11634 | Paul Allen |
Debugging actual adapter functionality and starting to integrate with Simulink. Transferred from p4://perforce.perforce.com:1666@938961 |
||
#2 | 11633 | Paul Allen |
Various fixes including workaround for no “admin” commands in p4java. Transferred from p4://perforce.perforce.com:1666@938159 |
||
#1 | 11632 | Paul Allen |
Added commons-exec library, server startup/shutdown for unit tests, fixed a bunch of NPEs. Transferred from p4://perforce.perforce.com:1666@937331 |