diff options
author | Bogumil Zebek <bogumil.zebek@nokia.com> | 2020-08-04 12:56:12 +0200 |
---|---|---|
committer | Zebek Bogumil <bogumil.zebek@nokia.com> | 2020-08-21 11:15:31 +0200 |
commit | 158248d9e2006e8e5f5c181f07b5aac57cb9ddd0 (patch) | |
tree | c198dfd629a8ff4f2f96286d8c6445d2cec1c999 /csarvalidation | |
parent | 8cbf161905d50a97fd78f28fb14b08bbd75c3abe (diff) |
Migrate from java 8 to java 11
Change-Id: If146dc0d99541a8a14ecc5e504c49a5c433a262f
Issue-ID: VNFSDK-631
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Diffstat (limited to 'csarvalidation')
-rw-r--r-- | csarvalidation/pom.xml | 95 | ||||
-rw-r--r-- | csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java | 25 | ||||
-rw-r--r-- | csarvalidation/src/test/java/org/onap/validation/csar/CsarValidatorTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java) | 78 | ||||
-rw-r--r-- | csarvalidation/src/test/java/org/onap/validation/csar/ValidationExceptionTest.java (renamed from csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java) | 11 |
4 files changed, 147 insertions, 62 deletions
diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml index 12250c2..0e8cfd4 100644 --- a/csarvalidation/pom.xml +++ b/csarvalidation/pom.xml @@ -34,11 +34,29 @@ </repository> </repositories> + <properties> + <log4j-slf4j-impl.version>2.13.0</log4j-slf4j-impl.version> + <snakeyaml.version>1.26</snakeyaml.version> + <jackson-core.version>2.9.4</jackson-core.version> + <junit.version>4.12</junit.version> + <commons-lang3.version>3.2.1</commons-lang3.version> + <commons-io.version>2.5</commons-io.version> + <bcpkix-jdk15on.version>1.61</bcpkix-jdk15on.version> + <cli-framework.version>5.0.3</cli-framework.version> + <cli-main.version>5.0.2</cli-main.version> + <assertj-core.version>3.11.1</assertj-core.version> + <lombok.version>1.18.2</lombok.version> + <commons-collections.version>3.2.2</commons-collections.version> + <maven-war-plugin.version>2.6</maven-war-plugin.version> + <maven-dependency-plugin.version>3.0.0</maven-dependency-plugin.version> + <mockito-core.version>3.5.0</mockito-core.version> + </properties> + <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> - <version>2.13.0</version> + <version>${log4j-slf4j-impl.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> @@ -49,42 +67,37 @@ <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> - <version>1.26</version> + <version>${snakeyaml.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> - <version>2.9.4</version> + <version>${jackson-core.version}</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> + <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.2.1</version> + <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> - <version>2.5</version> + <version>${commons-io.version}</version> </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpkix-jdk15on</artifactId> - <version>1.61</version> + <version>${bcpkix-jdk15on.version}</version> </dependency> <dependency> <groupId>org.onap.cli</groupId> <artifactId>cli-framework</artifactId> - <version>5.0.3</version> + <version>${cli-framework.version}</version> <exclusions> <exclusion> <groupId>commons-codec</groupId> @@ -97,32 +110,42 @@ <artifactId>commons-codec</artifactId> <version>1.14</version> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + </dependency> + <dependency> + <artifactId>commons-collections</artifactId> + <groupId>commons-collections</groupId> + <version>${commons-collections.version}</version> + </dependency> + <!-- TEST dependencies --> <dependency> - <groupId>org.onap.cli</groupId> - <artifactId>cli-main</artifactId> - <version>5.0.2</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <version>3.11.1</version> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito-core.version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>1.18.2</version> + <groupId>org.onap.cli</groupId> + <artifactId>cli-main</artifactId> + <version>${cli-main.version}</version> + <scope>test</scope> </dependency> <dependency> - <artifactId>commons-collections</artifactId> - <groupId>commons-collections</groupId> - <version>3.2.2</version> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>${assertj-core.version}</version> + <scope>test</scope> </dependency> - </dependencies> <profiles> @@ -135,7 +158,6 @@ </profile> </profiles> - <build> <finalName>${project.artifactId}-${project.version}</finalName> @@ -143,7 +165,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> - <version>3.0.2</version> + <version>${maven-jar-plugin.version}</version> <configuration> <archive> <manifest> @@ -153,20 +175,11 @@ </archive> </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> - <version>3.0.0</version> + <version>${maven-dependency-plugin.version}</version> <executions> <execution> <id>copy-artifact</id> @@ -205,7 +218,7 @@ <plugin> <artifactId>maven-war-plugin</artifactId> - <version>2.6</version> + <version>${maven-war-plugin.version}</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java index 86952b1..0478758 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java @@ -97,16 +97,35 @@ public class CsarValidator { } } + static class CsarValidatorSeam { + public String validateCsarMeta() { + return CsarValidator.validateCsarMeta(); + } + + public String validateAndScanToscaMeta(){ + return CsarValidator.validateAndScanToscaMeta(); + } + + public String validateMainService() { + return CsarValidator.validateMainService(); + } + + } + /** * @return true if all validations are successful */ public static String validateCsar() { + return CsarValidator.validateCsarContent(new CsarValidatorSeam()); + } + + static String validateCsarContent(CsarValidatorSeam csarValidatorSeam) { - String vsm = validateCsarMeta(); + String vsm = csarValidatorSeam.validateCsarMeta(); - String vtm = validateAndScanToscaMeta(); + String vtm = csarValidatorSeam.validateAndScanToscaMeta(); - String vms = validateMainService(); + String vms = csarValidatorSeam.validateMainService(); //String r02454 = r02454(); diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/csar/CsarValidatorTest.java index 2fe3640..bd363fc 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csar/CsarValidatorTest.java @@ -1,23 +1,27 @@ -/** +/* * Copyright 2017 Huawei Technologies Co., Ltd. - * + * Copyright 2020 Nokia + * <p> * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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. + * */ -package org.onap.validation.csarvalidationtest; +package org.onap.validation.csar; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import java.io.File; import java.io.FileInputStream; @@ -30,11 +34,12 @@ import java.util.regex.Pattern; import java.util.zip.ZipException; import java.util.zip.ZipFile; -import org.junit.Test; -import org.onap.validation.csar.CommonConstants; -import org.onap.validation.csar.CsarValidator; -import org.onap.validation.csar.FileUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +@RunWith(MockitoJUnitRunner.class) public class CsarValidatorTest { String regex = "^\\/[a-zA-Z]\\:\\/"; @@ -155,12 +160,20 @@ public class CsarValidatorTest { } @Test - public void testCloseInputStream() { + public void testCloseInputStreamForNonExistingDirectory() { InputStream dir = null; FileUtil.closeInputStream(dir); assertTrue(true); } + @Test(expected = ValidationException.class) + public void testCloseInputStream() throws IOException { + InputStream inputStream = mock(InputStream.class); + Mockito.doThrow(new IOException()).when(inputStream).close(); + FileUtil.closeInputStream(inputStream); + assertTrue(true); + } + @Test public void testCloseZipFile() throws ZipException, IOException { File file = new File(sample1); @@ -177,6 +190,13 @@ public class CsarValidatorTest { } + @Test(expected = ValidationException.class) + public void testCloseFileStream_reportErrorWhenIOExceptionOccurs() throws IOException { + FileInputStream fileInputStream = mock(FileInputStream.class); + Mockito.doThrow(new IOException()).when(fileInputStream).close(); + FileUtil.closeFileStream(fileInputStream); + } + @Test public void testCloseOutptutStream() { OutputStream dir4 = new OutputStream() { @@ -190,6 +210,13 @@ public class CsarValidatorTest { assertTrue(true); } + @Test(expected = ValidationException.class) + public void testCloseOutptutStream_reportErrorWhenIOExceptionOccurs() throws IOException { + OutputStream outputStream = mock(OutputStream.class); + Mockito.doThrow(new IOException()).when(outputStream).close(); + FileUtil.closeOutputStream(outputStream); + } + private void testValidateCsarMeta(CsarValidator cv) { String result = CsarValidator.validateCsarMeta(); assertEquals(true, result == CommonConstants.SUCCESS_STR); @@ -223,6 +250,31 @@ public class CsarValidatorTest { } @Test + public void testValidateCsar_csarMetaFailed() { + CsarValidator.CsarValidatorSeam csarValidatorSeam = mock(CsarValidator.CsarValidatorSeam.class); + Mockito.when(csarValidatorSeam.validateCsarMeta()).thenReturn("FAIL"); + Mockito.when(csarValidatorSeam.validateAndScanToscaMeta()).thenReturn("SUCCESS"); + Mockito.when(csarValidatorSeam.validateMainService()).thenReturn("FAIL"); + + + String res=CsarValidator.validateCsarContent(csarValidatorSeam); + assertEquals("FAIL OR FAIL",res); + + } + + @Test + public void testValidateCsar_toscaMetaFailed() { + CsarValidator.CsarValidatorSeam csarValidatorSeam = mock(CsarValidator.CsarValidatorSeam.class); + Mockito.when(csarValidatorSeam.validateCsarMeta()).thenReturn("SUCCESS"); + Mockito.when(csarValidatorSeam.validateAndScanToscaMeta()).thenReturn("FAIL"); + Mockito.when(csarValidatorSeam.validateMainService()).thenReturn("SUCCESS"); + + + String res=CsarValidator.validateCsarContent(csarValidatorSeam); + assertEquals("FAIL",res); + } + + @Test public void testDeleteDir(){ String dstPath = "./dstPathForTest1"; File dst = new File(dstPath); diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java b/csarvalidation/src/test/java/org/onap/validation/csar/ValidationExceptionTest.java index 8ab498e..fcbc439 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csar/ValidationExceptionTest.java @@ -1,20 +1,21 @@ -/** - * Copyright 2017 Huawei Technologies Co., Ltd. +/* + * Copyright 2020 Nokia * <p> * 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 * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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. + * */ -package org.onap.validation.csarvalidationtest; +package org.onap.validation.csar; import static org.junit.Assert.assertTrue; |