package com.perforce.p4simulink; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; import com.mathworks.cmlink.sdk.tests.util.FileCreation; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4simulink.connection.P4Config; public class P4SimulinkTest { protected static String PWD = System.getProperty("user.dir") + "/"; protected static String P4BIN = "p4-bin/"; protected final static String P4ROOT = "tmp-p4root"; protected final static String P4PORT = "localhost:1999"; protected final static P4TestServer p4d = new P4TestServer(PWD + P4BIN, P4ROOT, P4PORT); protected final static P4AdapterFactory factory = new P4AdapterFactory(); protected final static File TESTDIR = new File("test"); protected final static File TESTDIR2 = new File("test2"); @Before public void setup() throws Exception { FileUtils.forceMkdir(TESTDIR2); FileUtils.forceMkdir(TESTDIR); setupServer(); startServer(); } private void setupServer() throws Exception { System.out.println("Setting up p4d"); File ckp = new File("src/test/resources/checkpoint.gz"); assertTrue(ckp.exists()); File depot = new File("src/test/resources/depot.tar.gz"); assertTrue(depot.exists()); p4d.clean(); File root = new File(P4ROOT); assertTrue(root.exists()); p4d.restore(ckp); p4d.upgrade(); p4d.extract(depot); } private void startServer() throws Exception { File configFile = new File(TESTDIR.getAbsolutePath() + "/../.testconfig"); configFile.createNewFile(); FileWriter writer = new FileWriter(configFile); writer.write("P4USER=admin\nP4PORT=localhost:1999\nP4CLIENT=simulink.ws"); writer.flush(); writer.close(); p4d.start(); } @After public void teardown() throws Exception { p4d.stop(); p4d.clean(); cleanup(); } @After public void cleanup() throws Exception { FileUtils.deleteDirectory(TESTDIR); FileUtils.forceMkdir(TESTDIR); FileUtils.deleteDirectory(TESTDIR2); FileUtils.forceMkdir(TESTDIR2); } public static boolean containsFiles(List<IFileSpec> depotFiles, Collection<File> files) { HashSet<String> filenames = new HashSet<>(); for (File file : files) { filenames.add(file.getAbsolutePath()); } int count = 0; for (IFileSpec spec : depotFiles) { String localPath = spec.getLocalPathString(); if (localPath != null && !localPath.isEmpty() && filenames.contains(localPath)) { count++; } } return count == files.size(); } protected Collection<File> createAndGenerateFiles(String[] filenames) throws IOException { Collection<File> files = new ArrayList<>(); for (String name : filenames) { files.add(new File(TESTDIR.getAbsolutePath() + "/" + name)); } FileCreation.createFilesContainingText(files); return files; } protected void verifyFiles(Collection<File> files) { if (files != null && files.size() > 0) { for (File file : files) { assertTrue(file.exists()); } } } protected P4Config generateTestConfig() { // add them to the repository /* P4Config config = new P4Config(); return config.setUser("admin").setPassword("Password") .setPort("127.0.0.1:1999").setClient("simulink.ws") .setLoaded(true);*/ return null; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 11899 | Paul Allen | Inprogress development - moved work to branch | ||
//guest/paul_allen/p4sl/src/test/java/com/perforce/p4simulink/test/P4SimulinkTest.java | |||||
#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/P4SimulinkTest.java | |||||
#5 | 11673 | Paul Allen |
Fix BasicTest execution. The setup and teardown methods guarantee order, the @Before and @After annotations do not. Closed writter resource. |
||
#4 | 11672 | Paul Allen |
Tidy up formatting and imports. No functional change. |
||
#3 | 11661 | Paul Allen |
Finishing up unit tests. Transferred from p4://perforce.perforce.com:1666@985194 |
||
#2 | 11658 | Paul Allen |
Additional unit/functional tests. Transferred from p4://perforce.perforce.com:1666@980860 |
||
#1 | 11654 | Paul Allen |
Additional unit tests for @Override methods, refactored test classes. Transferred from p4://perforce.perforce.com:1666@976891 |