diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/CipherTypeTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/CipherTypeTest.java new file mode 100644 index 0000000..1ada781 --- /dev/null +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/CipherTypeTest.java @@ -0,0 +1,13 @@ +package com.czcb.scfs.api.core.cipher; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class CipherTypeTest { + + @Test + void getValue() { + Assertions.assertEquals("sm", CipherType.SM.getValue()); + Assertions.assertEquals("rsa", CipherType.RSA.getValue()); + } +} \ No newline at end of file diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/PemFileTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/PemFileTest.java index cca561d..41631f3 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/PemFileTest.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/PemFileTest.java @@ -54,7 +54,7 @@ class PemFileTest { String privateKey = PemFile.readPrivateKeyStringFromPath(file.getPath()); Assertions.assertNotNull(PemFile.loadPrivateKeyFromString(privateKey)); } finally { - file.delete(); + Assertions.assertTrue(file.delete()); } } @@ -75,4 +75,32 @@ class PemFileTest { void testLoadPrivateKeyFromStream() { Assertions.assertThrows(NullPointerException.class, () -> PemFile.loadPrivateKeyFromStream(null)); } + + @Test + void loadPrivateKeyFromAbsolutePathTest() throws IOException { + File file = File.createTempFile("Test.", "rsa_channel_private_key.pem"); + try (FileOutputStream outputStream = new FileOutputStream(file)) { + outputStream.write(KeyText.PRIVATE_TEXT_RSA.getBytes(StandardCharsets.UTF_8)); + outputStream.flush(); + + PrivateKey privateKey = PemFile.loadPrivateKeyFromAbsolutePath(file.getPath()); + Assertions.assertNotNull(privateKey); + } finally { + Assertions.assertTrue(file.delete()); + } + } + + @Test + void loadX509FromAbsolutePath() throws IOException { + File file = File.createTempFile("Test.", "rsa.pem"); + try (FileOutputStream outputStream = new FileOutputStream(file)) { + outputStream.write(KeyText.CERTIFICATE_TEXT_RSA.getBytes(StandardCharsets.UTF_8)); + outputStream.flush(); + + X509Certificate certificate = PemFile.loadX509FromAbsolutePath(file.getPath()); + Assertions.assertNotNull(certificate); + } finally { + Assertions.assertTrue(file.delete()); + } + } } \ No newline at end of file diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/StopWatchTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/StopWatchTest.java index 3221804..2393fab 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/StopWatchTest.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/util/StopWatchTest.java @@ -66,4 +66,22 @@ class StopWatchTest { Assertions.assertEquals(1, stopWatch.getTaskInfo().length); Assertions.assertNotEquals(0, stopWatch.getTaskInfo()[0].getTimeSeconds()); } + + @Test + void start4() { + StopWatch stopWatch = new StopWatch("11", false).start(); + Assertions.assertThrows(UnsupportedOperationException.class, stopWatch::getTaskInfo); + Assertions.assertThrows(IllegalStateException.class, stopWatch::getLastTaskInfo); + Assertions.assertThrows(IllegalStateException.class, stopWatch::getLastTaskTimeNanos); + Assertions.assertThrows(IllegalStateException.class, stopWatch::getLastTaskTimeMillis); + Assertions.assertThrows(IllegalStateException.class, stopWatch::getLastTaskName); + Assertions.assertTrue(stopWatch.isRunning()); + Assertions.assertThrows(IllegalStateException.class, stopWatch::start); + } + + @Test + void start5() { + StopWatch stopWatch = new StopWatch("11", false); + Assertions.assertThrows(IllegalStateException.class, stopWatch::stop); + } } \ No newline at end of file