diff options
author | 2020-08-04 12:56:12 +0200 | |
---|---|---|
committer | 2020-08-21 11:15:31 +0200 | |
commit | 158248d9e2006e8e5f5c181f07b5aac57cb9ddd0 (patch) | |
tree | c198dfd629a8ff4f2f96286d8c6445d2cec1c999 /csarvalidation/src/test/java/org/onap | |
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/src/test/java/org/onap')
-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 |
2 files changed, 71 insertions, 18 deletions
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; |