diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-03-01 13:35:53 +0100 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-03-01 13:36:47 +0100 |
commit | 176c445bbeb5e47011ff2ca4816c00dd0f6ea779 (patch) | |
tree | d759d004aaf58aa38a29b1e9656c28786ca423f2 /src/test/java/org/onap/aai/babel/TestApplication.java | |
parent | 811169825805a7160a6dd28abb281f64a4a56c71 (diff) |
Update aai-parent in babel to 1.13.3
- update aai-parent from 1.9.4 to 1.13.3
- update spring-boot from 2.1 to 2.4
- migrate junit 4 to junit 5
Issue-ID: AAI-3791
Change-Id: I849c830f9f0addfb2d4d48d20f038afd401858d2
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/test/java/org/onap/aai/babel/TestApplication.java')
-rw-r--r-- | src/test/java/org/onap/aai/babel/TestApplication.java | 100 |
1 files changed, 44 insertions, 56 deletions
diff --git a/src/test/java/org/onap/aai/babel/TestApplication.java b/src/test/java/org/onap/aai/babel/TestApplication.java index 200b0e2..c8065a2 100644 --- a/src/test/java/org/onap/aai/babel/TestApplication.java +++ b/src/test/java/org/onap/aai/babel/TestApplication.java @@ -21,76 +21,85 @@ package org.onap.aai.babel; +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import org.eclipse.jetty.util.security.Password; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.ExpectedException; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContextException; @SpringBootTest(classes = BabelApplication.class) public class TestApplication { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - /** * Initialize System Properties. */ - @Before + @BeforeEach public void init() { System.setProperty("APP_HOME", "."); System.setProperty("CONFIG_HOME", "src/test/resources"); System.setProperty("server.ssl.key-store", "src/test/resources/auth/keystore.jks"); } - @Test(expected = Test.None.class /* no exception expected */) + @Test public void testApplicationStarts() { - System.setProperty("KEY_STORE_PASSWORD", "password"); - BabelApplication.main(new String[] {}); - BabelApplication.exit(); + assertDoesNotThrow(() -> { + System.setProperty("KEY_STORE_PASSWORD", "password"); + BabelApplication.main(new String[]{}); + BabelApplication.exit(); + }); } - @Test(expected = Test.None.class /* no exception expected */) + @Test public void testApplicationStartsWithObfuscatedPassword() { - System.setProperty("KEY_STORE_PASSWORD", Password.obfuscate("password")); - BabelApplication.main(new String[] {}); - BabelApplication.exit(); + assertDoesNotThrow(() -> { + System.setProperty("KEY_STORE_PASSWORD", Password.obfuscate("password")); + BabelApplication.main(new String[]{}); + BabelApplication.exit(); + }); } @Test public void testApplicationWithNullArgs() { - System.setProperty("KEY_STORE_PASSWORD", "test"); - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Args must not be null"); - BabelApplication.main(null); + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + System.setProperty("KEY_STORE_PASSWORD", "test"); + BabelApplication.main(null); + }); + assertTrue(exception.getMessage().contains("Args must not be null")); } @Test public void testApplicationWithEmptyKeyStorePassword() { - System.setProperty("KEY_STORE_PASSWORD", ""); - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set"); - BabelApplication.main(new String[] {}); + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + System.setProperty("KEY_STORE_PASSWORD", ""); + BabelApplication.main(new String[]{}); + }); + assertTrue(exception.getMessage().contains("roperty KEY_STORE_PASSWORD not set")); } @Test public void testApplicationWithNullKeyStorePassword() { - System.clearProperty("KEY_STORE_PASSWORD"); - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set"); - BabelApplication.main(new String[] {}); + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + System.clearProperty("KEY_STORE_PASSWORD"); + BabelApplication.main(new String[]{}); + }); + assertTrue(exception.getMessage().contains("roperty KEY_STORE_PASSWORD not set")); } @Test public void testApplicationWithIncorrectKeyStorePassword() { - System.setProperty("KEY_STORE_PASSWORD", "test"); - final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect"); - expectedEx.expectCause(expectedCause); - BabelApplication.main(new String[] {}); + Throwable exception = assertThrows(ApplicationContextException.class, () -> { + System.setProperty("KEY_STORE_PASSWORD", "test"); + BabelApplication.main(new String[]{}); + }); } /** @@ -101,31 +110,10 @@ public class TestApplication { @Test public void testApplicationWithBlankObfuscatedKeyStorePassword() { // Note that "OBF:" is correctly deobfuscated and results in an empty string. - System.setProperty("KEY_STORE_PASSWORD", "OBF:"); - final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect"); - expectedEx.expectCause(expectedCause); - BabelApplication.main(new String[] {}); - } - - private static class CauseMatcher extends TypeSafeMatcher<Throwable> { - - private final Class<? extends Throwable> type; - private final String expectedMessage; - - public CauseMatcher(Class<? extends Throwable> type, String expectedMessage) { - this.type = type; - this.expectedMessage = expectedMessage; - } - - @Override - protected boolean matchesSafely(Throwable item) { - return item.getClass().isAssignableFrom(type) && item.getMessage().contains(expectedMessage); - } - - @Override - public void describeTo(Description description) { - description.appendValue(type).appendText(" and message ").appendValue(expectedMessage); - } + Throwable exception = assertThrows(ApplicationContextException.class, () -> { + System.setProperty("KEY_STORE_PASSWORD", "OBF:"); + BabelApplication.main(new String[]{}); + }); } } |