diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-11 12:28:26 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-11 12:28:26 +0000 |
commit | 2d6183e8ea302309d7a52fa6f7d0b4e2f0141348 (patch) | |
tree | 8883cde68ca56dec27298fd5018a75a73578e908 | |
parent | fbd05f86edf3e4710ab454780581f0ee40e152f6 (diff) |
Additional JUnit tests for code coverage
Improve code coverage to address Sonar code smells.
Include a dummy keystore file to allow the Spring Boot Application to
start up without error.
Change-Id: Ifab33a67e5d051baacfad91d3f317a8fb8b0a669
Issue-ID: AAI-2212
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
-rw-r--r-- | License.txt | 4 | ||||
-rw-r--r-- | src/test/java/org/onap/aai/babel/TestApplication.java | 105 | ||||
-rw-r--r-- | src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java | 55 | ||||
-rw-r--r-- | src/test/resources/auth/keystore.jks | bin | 0 -> 2206 bytes |
4 files changed, 162 insertions, 2 deletions
diff --git a/License.txt b/License.txt index 5ce31aa..50054e3 100644 --- a/License.txt +++ b/License.txt @@ -1,8 +1,8 @@ ============LICENSE_START======================================================= org.onap.aai ================================================================================ -Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. -Copyright © 2017-2019 European Software Marketing Ltd. +Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. +Copyright (c) 2017-2019 European Software Marketing Ltd. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/test/java/org/onap/aai/babel/TestApplication.java b/src/test/java/org/onap/aai/babel/TestApplication.java new file mode 100644 index 0000000..2821dc1 --- /dev/null +++ b/src/test/java/org/onap/aai/babel/TestApplication.java @@ -0,0 +1,105 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.babel; + +import java.io.IOException; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest(classes = BabelApplication.class) +public class TestApplication { + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Before + 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 + public void testApplicationStarts() { + System.setProperty("KEY_STORE_PASSWORD", "password"); + BabelApplication.main(new String[] {}); + } + + @Test + public void testApplicationWithNullArgs() { + System.setProperty("KEY_STORE_PASSWORD", "test"); + expectedEx.expect(IllegalArgumentException.class); + expectedEx.expectMessage("Args must not be null"); + BabelApplication.main(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[] {}); + } + + @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[] {}); + } + + @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[] {}); + } + + 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); + } + } + +} diff --git a/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java new file mode 100644 index 0000000..404fb19 --- /dev/null +++ b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java @@ -0,0 +1,55 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.babel.xml.generator; + +import java.io.IOException; +import java.util.Collections; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.babel.testdata.CsarTest; +import org.onap.aai.babel.util.ArtifactTestUtils; +import org.onap.aai.babel.xml.generator.data.Artifact; + +/** + * Direct tests of the @{link ModelGenerator} implementation class (to improve code coverage). Not all methods are + * tested here. Most use cases are covered by direct tests of @{link CsarToXmlConverter}. + */ +public class TestModelGenerator { + + static { + System.setProperty("APP_HOME", "."); + } + + @Before + public void setup() { + new ArtifactTestUtils().setGeneratorSystemProperties(); + } + + @Test + public void testDefaultServiceVersion() throws XmlArtifactGenerationException, IOException { + Artifact ymlFile = new Artifact(null, null, null, null); + new ModelGenerator().generateArtifacts(CsarTest.SD_WAN_CSAR_FILE.getContent(), + Collections.singletonList(ymlFile)); + } + + +} diff --git a/src/test/resources/auth/keystore.jks b/src/test/resources/auth/keystore.jks Binary files differnew file mode 100644 index 0000000..037769b --- /dev/null +++ b/src/test/resources/auth/keystore.jks |