use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class IgnoredFileScenarioTest method testIgnoredFileRegex.
@Test
public void testIgnoredFileRegex() throws Exception {
// Scenario: A ignores files with a regular expression, creates it then ups, B should not have the file
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Create ignore file and reload it
File syncanyIgnore = clientA.getLocalFile(Config.FILE_IGNORE);
TestFileUtil.createFileWithContent(syncanyIgnore, "regex:.*.bak");
clientA.getConfig().getIgnoredFiles().loadPatterns();
// A new/up
clientA.createNewFile("ignoredfile.bak");
clientA.up();
clientB.down();
// The ignored file should not exist at B
assertTrue(clientA.getLocalFile("ignoredfile.bak").exists());
assertFalse(clientB.getLocalFile("ignoredfile.bak").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue200ScenarioTest method testIssue200.
@Test
public void testIssue200() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFolder("folder");
clientA.createNewFile("folder/file");
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.changeFile("folder/file");
clientA.upWithForceChecksum();
clientB.deleteFile("folder/file");
clientB.down();
assertTrue(clientB.getLocalFile("folder/file").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue374Pre1965DateScenarioTest method testIssue316CleanupThenDeleteFile.
@Test
public void testIssue316CleanupThenDeleteFile() throws Exception {
/*
* This test simulates files with a timestamp before 1965 (unix time < 0).
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
clientA.createNewFile("pre1965.txt");
Date dateBefore1965 = new SimpleDateFormat("dd-MM-yyyy").parse("31-12-1964");
Files.setLastModifiedTime(clientA.getLocalFile("pre1965.txt").toPath(), FileTime.fromMillis(dateBefore1965.getTime()));
clientA.upWithForceChecksum();
// This was throwing an exception in FileSystemAction.setLastModified()
clientB.down();
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class ManySyncUpsAndDatabaseFileCleanupScenarioTest method testManySyncUpsAndDatabaseFileCleanup.
@Test
public void testManySyncUpsAndDatabaseFileCleanup() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
// ROUND 1: many sync up (no cleanup expected here)
for (int i = 1; i <= 15; i++) {
clientA.createNewFile("file" + i, 1);
clientA.up();
}
for (int i = 1; i <= 15; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// ROUND 2: 1x sync up (cleanup expected!)
clientA.createNewFile("file16", 1);
clientA.up();
// Force cleanup
clientA.cleanup();
for (int i = 1; i <= 15; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists());
}
for (int i = 17; i <= 17; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// ROUND 3: many sync up (no cleanup expected here)
for (int i = 17; i <= 30; i++) {
clientA.createNewFile("file" + i, 1);
clientA.up();
}
for (int i = 1; i <= 16; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists());
}
for (int i = 17; i <= 31; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// ROUND 4: 1x sync up (cleanup expected!)
clientA.createNewFile("file31", 1);
clientA.up();
CleanupOperationOptions options = new CleanupOperationOptions();
options.setForce(true);
// Force cleanup
clientA.cleanup(options);
for (int i = 1; i <= 32; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists());
}
for (int i = 33; i <= 33; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// Tear down
TestClient clientB = new TestClient("B", testConnection);
clientB.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class RenameFileWithDiffModifiedDateScenarioTest method testChangedModifiedDate.
@Test
public void testChangedModifiedDate() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
// A, create two files with identical content and change mod. date of one of them
clientA.createNewFile("A-file1.jpg", 50 * 1024);
clientA.copyFile("A-file1.jpg", "A-file1-with-different-modified-date.jpg");
clientA.getLocalFile("A-file1.jpg").setLastModified(0);
clientA.up();
// B, down, then move BOTH files
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientB.moveFile("A-file1.jpg", "A-file1-moved.jpg");
clientB.moveFile("A-file1-with-different-modified-date.jpg", "A-file1-with-different-modified-date-moved.jpg");
clientB.up();
TestSqlDatabase clientDatabaseB = clientB.loadLocalDatabase();
PartialFileHistory file1Orig = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-moved.jpg");
PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-with-different-modified-date-moved.jpg");
assertNotNull(file1Orig);
assertNotNull(file1WithDiffLastModDate);
FileVersion fileVersion1OrigV1 = file1Orig.getFileVersion(1);
FileVersion fileVersion1OrigV2 = file1Orig.getFileVersion(2);
FileVersion fileVersion1WithDiffLastModDateV1 = file1WithDiffLastModDate.getFileVersion(1);
FileVersion fileVersion1WithDiffLastModDateV2 = file1WithDiffLastModDate.getFileVersion(2);
assertNotNull(fileVersion1OrigV1);
assertNotNull(fileVersion1OrigV2);
assertNotNull(fileVersion1WithDiffLastModDateV1);
assertNotNull(fileVersion1WithDiffLastModDateV2);
assertEquals("A-file1.jpg", fileVersion1OrigV1.getName());
assertEquals("A-file1-moved.jpg", fileVersion1OrigV2.getName());
assertEquals("A-file1-with-different-modified-date.jpg", fileVersion1WithDiffLastModDateV1.getName());
assertEquals("A-file1-with-different-modified-date-moved.jpg", fileVersion1WithDiffLastModDateV2.getName());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations