From a6cdbb856bc7067774270b6c7bf78caee95a400e Mon Sep 17 00:00:00 2001 From: inoshperera Date: Sun, 16 Sep 2018 17:26:20 +0530 Subject: [PATCH] Adding unit test for StorageManagementUtilTest.java --- .../StorageManagementUtilTest.java | 76 +++++++++++++++++++ .../src/test/resources/testng.xml | 1 + 2 files changed, 77 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/StorageManagementUtilTest.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/StorageManagementUtilTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/StorageManagementUtilTest.java new file mode 100644 index 0000000000..c857b0a67b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/StorageManagementUtilTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * WSO2 Inc. licenses this file to you 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. + * + */ + +package org.wso2.carbon.device.application.mgt.core; + +import org.junit.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.wso2.carbon.device.application.mgt.common.exception.ResourceManagementException; +import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + + +public class StorageManagementUtilTest { + private static final String TEMP_FOLDER = "src/test/resources/util/temp"; + private static final String APK_FILE = "src/test/resources/util/app-debug.apk"; + private static final String APK_FILE_NAME = "/app-debug.apk"; + + @BeforeMethod + public void before() throws IOException { + File file = new File(TEMP_FOLDER); + if (file.exists()) { + StorageManagementUtil.deleteDir(file); + } + } + + @Test + public void testCreateArtifactDirectory() { + try { + StorageManagementUtil.createArtifactDirectory(TEMP_FOLDER); + } catch (ResourceManagementException e) { + e.printStackTrace(); + Assert.fail("Directory creation failed."); + } + } + + @Test + public void testSaveFile() throws IOException, ResourceManagementException { + StorageManagementUtil.createArtifactDirectory(TEMP_FOLDER); + InputStream apk = new FileInputStream(APK_FILE); + StorageManagementUtil.saveFile(apk, TEMP_FOLDER + APK_FILE_NAME); + File file = new File(TEMP_FOLDER + APK_FILE_NAME); + if(!file.exists()) { + Assert.fail("File saving failed."); + } + } + + @AfterMethod + public void deleteFileTest() throws IOException, ResourceManagementException { + File file = new File(TEMP_FOLDER); + StorageManagementUtil.deleteDir(file); + if(file.exists()) { + Assert.fail("File deleting failed."); + } + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml index ca512950bc..9a69c5a87f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/testng.xml @@ -23,6 +23,7 @@ + \ No newline at end of file