From 2be23d1f915c1c3dda4b79e4a43a05a4b94128d0 Mon Sep 17 00:00:00 2001 From: Murali-P Date: Fri, 7 Apr 2017 13:17:41 +0530 Subject: Fix unit test coverage issue Resolved:VNFSDK-21 VNF SDK Function tests Change-Id: I148ed2c00c27ddb0fd42d3313e1d18f31477066e Signed-off-by: Murali-P --- .../functest/resource/CommonManagerTest.java | 157 +++++++++++---------- 1 file changed, 80 insertions(+), 77 deletions(-) (limited to 'vnf-sdk-function-test/src/test') diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java index 052462e..664cbb8 100644 --- a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java +++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java @@ -16,8 +16,8 @@ package org.openo.vnfsdk.functest.resource; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.FileInputStream; @@ -27,24 +27,24 @@ import java.io.InputStream; import java.net.URL; import java.util.HashMap; import java.util.Map; + import javax.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; +import org.openo.vnfsdk.functest.FileUtil; import org.openo.vnfsdk.functest.responsehandler.VnfFuncTestResponseHandler; import org.openo.vnfsdk.functest.util.ZipCompressor; import mockit.Mock; import mockit.MockUp; -import org.openo.vnfsdk.functest.FileUtil; - public class CommonManagerTest { private CommonManager commonManger; private String instanceId; - + private String funcTestId = "59d1e651-df9f-4008-902f-e3b377e6ec30"; private Response response = null; @@ -54,78 +54,6 @@ public class CommonManagerTest { commonManger = new CommonManager(); } - @Test - public void testUploadFuncTestPackage() { - URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript"); - String zipFileName = url.getPath() + ".zip"; - - new MockUp() { - @Mock - public String[] getDirectory(String directory) { - File file = new File( "temp" ); - return file.list(); - } - }; - - try { - InputStream mockInputStream = new FileInputStream(zipFileName); - response = commonManger.uploadFuncTestPackage( mockInputStream, funcTestId ); - assertNotNull( response ); - assertEquals( 200 , response.getStatus() ); - } catch( Exception e ) { - e.printStackTrace(); - } - } - - @Test - public void testGetOperationResult() { - try { - response = commonManger.getOperationResult( funcTestId ); - assertNotNull( response ); - assertEquals( 200 , response.getStatus() ); - } catch( Exception e ) { - e.printStackTrace(); - } - } - - @Test - public void testDownloadResults() { - try { - response = commonManger.downloadResults( funcTestId ); - /*assertNotNull( response ); - assertEquals( 200 , response.getStatus() ); */ - } catch( Exception e ) { - e.printStackTrace(); - } - } - - @Test - public void testStoreChunkFileInLocal() { - URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript"); - String zipFileName = url.getPath() + ".zip"; - - try { - InputStream mockInputStream = new FileInputStream(zipFileName); - String chunkFilePath = commonManger.storeChunkFileInLocal( "src/test/resources", "chunkFileInLocal" , mockInputStream ); - assertNotNull( chunkFilePath ); - } catch( Exception e ) { - e.printStackTrace(); - } - } - - @Test - public void testSetEnvironment() { - try { - - String jsonInput = - "{\"remoteIp\":\"192.168.4.47\",\"userName\":\"root\",\"password\":\"root123\", \"path\":\"/src/test/resources\"}"; - response = commonManger.setEnvironment(jsonInput); - assertNotNull(response); - } catch(Exception e) { - e.printStackTrace(); - } - } - @Test public void testexecuteFunc() throws FileNotFoundException { @@ -159,7 +87,82 @@ public class CommonManagerTest { @Test public void testQueryResultWhenInstanceIdAbsent() { - Response response = commonManger.queryResultByFuncTest( funcTestId ); + Response response = commonManger.queryResultByFuncTest(funcTestId); assertNotNull(response); } + + @Test + public void testUploadFuncTestPackage() { + URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript"); + String zipFileName = url.getPath() + ".zip"; + + new MockUp() { + + @Mock + public String[] getDirectory(String directory) { + File file = new File("temp"); + return file.list(); + } + }; + + try { + InputStream mockInputStream = new FileInputStream(zipFileName); + response = commonManger.uploadFuncTestPackage(mockInputStream, funcTestId); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testGetOperationResult() { + try { + response = commonManger.getOperationResult(funcTestId); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testDownloadResults() { + try { + response = commonManger.downloadResults(funcTestId); + assertNotNull(response); + assertEquals(200, response.getStatus()); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testStoreChunkFileInLocal() { + URL url = Thread.currentThread().getContextClassLoader().getResource("RobotScript"); + String zipFileName = url.getPath() + ".zip"; + + try { + InputStream mockInputStream = new FileInputStream(zipFileName); + String chunkFilePath = + commonManger.storeChunkFileInLocal("src/test/resources", "chunkFileInLocal", mockInputStream); + assertNotNull(chunkFilePath); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testSetEnvironment() { + try { + + String jsonInput = + "{\"remoteIp\":\"192.168.4.47\",\"userName\":\"root\",\"password\":\"root123\", \"path\":\"/src/test/resources\"}"; + response = commonManger.setEnvironment(jsonInput); + assertNotNull(response); + } catch(Exception e) { + e.printStackTrace(); + } + } + } -- cgit 1.2.3-korg