Search in sources :

Example 1 with ApplicationSqlDao

use of org.syncany.database.dao.ApplicationSqlDao in project syncany by syncany.

the class ApplicationDaoTest method testShutdown.

@Test
public void testShutdown() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Prepare
    ApplicationSqlDao applicationDao = new ApplicationSqlDao(databaseConnection);
    List<DatabaseRemoteFile> expectedKnownDatabases = Arrays.asList(new DatabaseRemoteFile[] { new DatabaseRemoteFile("database-A-0000000001") });
    applicationDao.writeKnownRemoteDatabases(expectedKnownDatabases);
    // Run & Test
    assertTrue(new File(testConfig.getDatabaseFile() + ".lck").exists());
    applicationDao.shutdown();
    assertFalse(new File(testConfig.getDatabaseFile() + ".lck").exists());
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : Config(org.syncany.config.Config) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Connection(java.sql.Connection) ApplicationSqlDao(org.syncany.database.dao.ApplicationSqlDao) File(java.io.File) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Test(org.junit.Test)

Example 2 with ApplicationSqlDao

use of org.syncany.database.dao.ApplicationSqlDao in project syncany by syncany.

the class ApplicationDaoTest method testGetKnownDatabases.

@Test
public void testGetKnownDatabases() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    TestSqlUtil.runSqlFromResource(databaseConnection, "test.insert.set3.sql");
    ApplicationSqlDao applicationDao = new ApplicationSqlDao(databaseConnection);
    List<DatabaseRemoteFile> actualKnownDatabases = applicationDao.getKnownDatabases();
    // Test
    assertTrue(CollectionUtil.containsExactly(Arrays.asList(new DatabaseRemoteFile[] { new DatabaseRemoteFile("database-B-0000000001"), new DatabaseRemoteFile("database-B-0000000002"), new DatabaseRemoteFile("database-B-0000000003") }), actualKnownDatabases));
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : Config(org.syncany.config.Config) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Connection(java.sql.Connection) ApplicationSqlDao(org.syncany.database.dao.ApplicationSqlDao) Test(org.junit.Test)

Example 3 with ApplicationSqlDao

use of org.syncany.database.dao.ApplicationSqlDao in project syncany by syncany.

the class ApplicationDaoTest method testPersistAndGetKnownDatabases.

@Test
public void testPersistAndGetKnownDatabases() throws Exception {
    // Setup
    Config testConfig = TestConfigUtil.createTestLocalConfig();
    Connection databaseConnection = testConfig.createDatabaseConnection();
    // Run
    ApplicationSqlDao applicationDao = new ApplicationSqlDao(databaseConnection);
    List<DatabaseRemoteFile> expectedKnownDatabases = Arrays.asList(new DatabaseRemoteFile[] { new DatabaseRemoteFile("database-A-0000000001"), new DatabaseRemoteFile("database-V-0000000001"), new DatabaseRemoteFile("database-B-0000000001"), new DatabaseRemoteFile("database-A-0000000002") });
    applicationDao.writeKnownRemoteDatabases(expectedKnownDatabases);
    List<DatabaseRemoteFile> actualKnownDatabases = applicationDao.getKnownDatabases();
    // Test
    assertTrue(CollectionUtil.containsExactly(expectedKnownDatabases, actualKnownDatabases));
    // Tear down
    databaseConnection.close();
    TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
Also used : Config(org.syncany.config.Config) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) Connection(java.sql.Connection) ApplicationSqlDao(org.syncany.database.dao.ApplicationSqlDao) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)3 Test (org.junit.Test)3 Config (org.syncany.config.Config)3 ApplicationSqlDao (org.syncany.database.dao.ApplicationSqlDao)3 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)3 File (java.io.File)1