diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-07 12:54:19 +0100 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-07 21:56:38 +0100 |
commit | 817338bc7da3127ff01e6736d284a081461f484b (patch) | |
tree | 071d310a8b2a50ab81e3ea07a33dfc2b760cb04a /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java | |
parent | 45f12914d2ba01cd0b7df7069e2879d4d7d275c6 (diff) |
Fix sonar issues
Change-Id: If699a0d8ba39238ff8e559567c8c5d44fb1e1d7c
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java')
-rw-r--r-- | nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java index 9ac38914..95bdc5f4 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java @@ -37,9 +37,13 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Part; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; +import static junit.framework.TestCase.fail; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip; @@ -48,7 +52,6 @@ import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestConverterApi extends TestBase { - @InjectMocks private ConverterApi converterApi; @Mock @@ -60,9 +63,10 @@ public class TestConverterApi extends TestBase { } /** + * test VNF package conversion success scenario */ @Test - public void test() throws Exception { + public void testConversion() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream actualOut = new PrintStream(bos, true); when(systemFunctions.out()).thenReturn(actualOut); @@ -97,8 +101,11 @@ public class TestConverterApi extends TestBase { assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray()); } + /** + * the HTML based converted page works + */ @Test - public void testDownloaderPage() throws Exception { + public void testConverterPage() throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream actualOut = new PrintStream(bos, true); when(httpResponse.getOutputStream()).thenReturn(new DelegatingServletOutputStream(actualOut)); @@ -106,9 +113,25 @@ public class TestConverterApi extends TestBase { //when converterApi.getUploadPageForConvertingVnfd(httpResponse); //verify - TestCase.assertTrue(Arrays.equals(TestUtil.loadFile("upload.html"), bos.toByteArray())); + assertTrue(Arrays.equals(TestUtil.loadFile("upload.html"), bos.toByteArray())); verify(httpResponse).addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bos.toByteArray().length)); - } + /** + * error is propagated if unable to extract package from HTTP request + */ + @Test + public void testUnableToExtractPackageToBeConverted() throws Exception{ + IOException expectedException = new IOException(); + when(httpRequest.getParts()).thenThrow(expectedException); + try { + converterApi.convert(httpResponse, httpRequest); + fail(); + } + catch (Exception e){ + verify(logger).error("Unable to extract package from REST parameters", expectedException); + assertEquals("Unable to extract package from REST parameters", e.getMessage()); + assertEquals(expectedException, e.getCause()); + } + } } |