From 2d6183e8ea302309d7a52fa6f7d0b4e2f0141348 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Mon, 11 Mar 2019 12:28:26 +0000 Subject: [PATCH] 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 --- License.txt | 4 +- .../java/org/onap/aai/babel/TestApplication.java | 105 +++++++++++++++++++++ .../babel/xml/generator/TestModelGenerator.java | 55 +++++++++++ src/test/resources/auth/keystore.jks | Bin 0 -> 2206 bytes 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/onap/aai/babel/TestApplication.java create mode 100644 src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java create mode 100644 src/test/resources/auth/keystore.jks 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 { + + private final Class type; + private final String expectedMessage; + + public CauseMatcher(Class 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 new file mode 100644 index 0000000000000000000000000000000000000000..037769b53f28fdd1d0a6998c2eabc7fe7d0b4bd9 GIT binary patch literal 2206 zcmcJQ={wX77sqGDjBPT-*vf8n7aD$clgpN+QnoOb;xVP{OSZBkMi`A+TPDUYr-7^X6RVd(QR!?k(*tfj}V0L4ki2Z}9b? zU^jnXoTuMG%cG^gCL9EUfdD-8CxGDORpbOi!3q$5Fc=1c;-Ry{A_207G{r!D#3`4z z7%tr`Zl3N)#?tH1N{RayCVSfWv4*RASm|bu<`5xUIa1EoXm}-`hvcLUt zvu-X5KML>FGwLHct~K8+_($G?+>_*mu%aw?-;|GT<+&ykhfZIPB^hKTuy%T2c2$gq zSdXOb($dCmlTgvAHpxf;u`FRp2i;uV!B7lM6H><;a@L$-p6+9tQM<|(AX;Qdu^@w8 z_u+j$UufHgqo0`Cu$0H<8}ILtts6gYm zFfIS*{oFiVrp3p)j8=BMbCO~&_xRy%LL{v^Al~~ z7pxvW0tr&EIQFofIO(yk@B2Aw#njxO<1+En&4(on>`U(J%}P|KmPT@cYdC$NH~E-h zU>^rIr2CoMOA&WojWYR&0oCLIYSUBnrMKQT*^$h&eL)3r;07Um+@XzbL>Vb@OohiZ zyknNqOR#Aw%Sm~nkjj=xAklw;ab&T)FvEjuiF=kom|#zh#8e@AEz9#cUG>$6K3A6l z=i*WqSoQT&Vz&rkwoc@na=XbxqJnV}2>r~A6@9p;%d2$+Eaj?iU$Q(MoK^c+ z#!4}^V|KVd&lilQ?R1t+1ObFSMVtIhnXgCnWQ~a!Ga2kih;3ER_f;3YRe#D&QqCCX zXR^X;oa9Za@$KTlvs!iX#h5A(=Ie&4as~6`lq=4uSTTsy1;zcjI&yT+QG@2p%oNVj z-($pe#W+U~)vaCIp;lr(NeB3gpy&I*nUBL2L|&TnVP!=o*I_78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