From 4a1d885afa7217b47d6183488c3dc6537cef05b6 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 23 Jan 2021 14:10:32 +0800 Subject: Version 1.4.6 (preview): added metadata for incremental backup (need integrated test and display implementation) --- .../IncBakupBackwardCompatibilityTest.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java (limited to 'src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java') diff --git a/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java new file mode 100644 index 0000000..d50b264 --- /dev/null +++ b/src/test/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBakupBackwardCompatibilityTest.java @@ -0,0 +1,45 @@ +package com.keuin.kbackupfabric.backup.incremental.serializer; + +import com.keuin.kbackupfabric.backup.incremental.ObjectCollection2; +import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionFactory; +import com.keuin.kbackupfabric.backup.incremental.ObjectCollectionSerializer; +import com.keuin.kbackupfabric.backup.incremental.identifier.Sha256Identifier; +import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.ZoneOffset; + +import static org.junit.Assert.*; + +public class IncBakupBackwardCompatibilityTest { + + private final String customName = "test_backup"; + private final LocalDateTime backupTime = LocalDateTime.of(2000, 1, 1, 1, 1, 1, 1); + + private final Path testRoot = Paths.get(".\\testfile\\IncBackupBackwardCompatibilityTest"); + private final File indexFile = new File(testRoot.toString(), new IncrementalBackupFileNameEncoder().encode(customName, backupTime)); + + @Test + public void testBackwardCompatibility() throws IOException { + + if (!testRoot.toFile().isDirectory()) { + if (!testRoot.toFile().mkdirs()) + fail("Cannot initialize test environment: cannot create path."); + } + + // now we make an old-style backup index file + ObjectCollectionFactory factory = + new ObjectCollectionFactory<>(Sha256Identifier.getFactory(), 1, 0); + ObjectCollection2 collection = factory.fromDirectory(testRoot.toFile()); + ObjectCollectionSerializer.toFile(collection, indexFile); + SavedIncrementalBackup info = IncBackupInfoSerializer.fromFile(indexFile); + assertEquals(collection, info.getObjectCollection()); + assertEquals(customName, info.getBackupName()); + assertTrue(backupTime.toEpochSecond(ZoneOffset.UTC) - info.getBackupTime().toLocalDateTime().toEpochSecond(ZoneOffset.UTC) <= 2); + } +} -- cgit v1.2.3