diff options
author | 2022-05-17 21:40:59 +0530 | |
---|---|---|
committer | 2022-05-21 00:33:38 +0530 | |
commit | dfbae36928e95b9232cb879d880ac6e3e3e01520 (patch) | |
tree | ab85465d5247c399a2871ba8e14386e1de2a6814 /src/test/java/org/onap/dcae/ApplicationSettingsTest.java | |
parent | 715355b2b8bf7fe05e949df234e03d05e1554477 (diff) |
CodeCoverage improvement for dcaegen2-collectors-restconf
Issue-ID: DCAEGEN2-3166
Signed-off-by: Mukesh Paliwal <mukesh.paliwal1@huawei.com>
Change-Id: I03de7bf0cef8eb2c2545cad9c342745c3f0e06b9
Diffstat (limited to 'src/test/java/org/onap/dcae/ApplicationSettingsTest.java')
-rw-r--r-- | src/test/java/org/onap/dcae/ApplicationSettingsTest.java | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java index d16953a..4661283 100644 --- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java +++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * Copyright (C) 2018-2019 Huawei. All rights reserved. + * Copyright (C) 2018-2022 Huawei. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -116,6 +116,27 @@ public class ApplicationSettingsTest { } @Test + public void shouldLoadPropertiesFromFile() throws IOException { + // given + String[] cliArguments = {"-section.subSection1", "abc"}; + File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter"); + Files.write(tempConfFile.toPath(), singletonList("section.subSection1=zxc")); + tempConfFile.deleteOnExit(); + + // when + ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine); + String actuallyOverridenByCliParam = configurationAccessor.getStringDirectly("section.subSection1"); + + // then + assertEquals("abc", actuallyOverridenByCliParam); + + configurationAccessor.loadPropertiesFromFile(); + + boolean auth = configurationAccessor.clientTlsAuthenticationEnabled(); + assertEquals(auth, false); + } + + @Test public void shouldReturnDefaultHttpPort() throws IOException { // when int applicationPort = fromTemporaryConfiguration().httpPort(); @@ -306,6 +327,20 @@ public class ApplicationSettingsTest { } @Test + public void shouldConfigurationFileLocation() throws IOException { + + try { + String[] cliArguments = {"-param1", "param1value", "-param2", "param2value"}; + // when + ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine); + Path path = configurationAccessor.configurationFileLocation(); + assertTrue(path.endsWith("collector.properties")); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test public void shouldrccKeystorePathExistDefault() throws IOException { // when String path = fromTemporaryConfiguration().rccKeystoreFileLocation(); @@ -368,6 +403,56 @@ public class ApplicationSettingsTest { assertEquals(stream, null); } + @Test + public void shouldGetStringDirectly() { + // given + String[] cliArguments = {"-param1", "param1value"}; + + // when + ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine); + String param1value = configurationAccessor.getStringDirectly("param1"); + + // then + assertEquals("param1value", param1value); + } + + @Test + public void shouldAddOrUpdate() { + // given + String[] cliArguments = {"-param1", "param1value"}; + + // when + ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine); + configurationAccessor.addOrUpdate("collector.rcc.test", null); + configurationAccessor.addOrUpdate("collector.rcc.test", "1"); + } + + @Test + public void shouldControllerConfigFileLocation() throws IOException { + // given + String[] cliArguments = {"-param1", "param1value"}; + + // when + ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine); + String param1value = configurationAccessor.controllerConfigFileLocation(); + + // then + assertTrue(param1value.endsWith("ont_config.json")); + } + + @Test + public void shouldConfigurationUpdateFrequency() throws IOException { + // given + String[] cliArguments = {"-param1", "param1value"}; + + // when + ApplicationSettings configurationAccessor = new ApplicationSettings(cliArguments, CLIUtils::processCmdLine); + int param1value = configurationAccessor.configurationUpdateFrequency(); + + // then + assertEquals(5, param1value); + } + private static ApplicationSettings fromTemporaryConfiguration(String... fileLines) throws IOException { File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter"); @@ -382,4 +467,4 @@ public class ApplicationSettingsTest { private String sanitizePath(String path) { return Paths.get(path).toString(); } -}
\ No newline at end of file +} |