diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 04d246bb4cc..73d7905adf2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -103,6 +103,20 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 2.18 + + + src/test/resources/testng.xml + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + file:src/test/resources/log4j.properties + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java index f7fa79de60e..09b37e4e789 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ArtifactsParser.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.UUID; +import java.nio.file.Files; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ArtifactParserTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ArtifactParserTest.java new file mode 100644 index 00000000000..a8bb924ad5b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/ArtifactParserTest.java @@ -0,0 +1,69 @@ +/* + * 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 com.dd.plist.NSDictionary; +import net.dongliu.apk.parser.bean.ApkMeta; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.wso2.carbon.device.application.mgt.core.exception.ParsingException; +import org.wso2.carbon.device.application.mgt.core.util.ArtifactsParser; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; + +public class ArtifactParserTest { + private static final String APK_FILE = "src/test/resources/util/app-debug.apk"; + private static final String APK_FILE_INVALID = "src/test/resources/util/app-debug1.apk"; + private static final String IPA_FILE = "src/test/resources/util/iOSMDMAgent.ipa"; + private static final String IPA_FILE_INVALID = "src/test/resources/util/iOSMDMAgent1.ipa"; + + @Test + public void testReadAndroidManifestFile() throws FileNotFoundException, ParsingException { + InputStream apk = new FileInputStream(APK_FILE); + ApkMeta apkMeta = ArtifactsParser.readAndroidManifestFile(apk); + Assert.assertEquals(apkMeta.getVersionName(), "1.0", "APK version name extraction failed."); + Assert.assertEquals(apkMeta.getPackageName(), "com.games.inosh.myapplication", + "APK package name extraction failed."); + } + + @Test(expectedExceptions = java.io.FileNotFoundException.class) + public void testReadAndroidManifestInvalidFile() throws FileNotFoundException, ParsingException { + InputStream apk = new FileInputStream(APK_FILE_INVALID); + ArtifactsParser.readAndroidManifestFile(apk); + } + + @Test + public void testReadiOSManifestFile() throws FileNotFoundException, ParsingException { + InputStream ipa = new FileInputStream(IPA_FILE); + NSDictionary ipaDictionary = ArtifactsParser.readiOSManifestFile(ipa); + Assert.assertEquals(ipaDictionary.objectForKey(ArtifactsParser.IPA_BUNDLE_IDENTIFIER_KEY).toString(), + "org.wso2.carbon.emm.ios.agent.inosh", "IPA bundle ID extraction failed."); + Assert.assertEquals(ipaDictionary.objectForKey(ArtifactsParser.IPA_BUNDLE_VERSION_KEY).toString(), + "GA", "IPA file version name extraction failed."); + } + + @Test(expectedExceptions = java.io.FileNotFoundException.class) + public void testReadiOSManifestInvalidFile() throws FileNotFoundException, ParsingException { + InputStream ipa = new FileInputStream(IPA_FILE_INVALID); + ArtifactsParser.readiOSManifestFile(ipa); + } +} 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 0af96a3777a..ca512950bcb 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 @@ -20,4 +20,9 @@ + + + + + \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/app-debug.apk b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/app-debug.apk new file mode 100644 index 00000000000..52bb95ed215 Binary files /dev/null and b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/app-debug.apk differ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/iOSMDMAgent.ipa b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/iOSMDMAgent.ipa new file mode 100644 index 00000000000..13af8f3cdb8 Binary files /dev/null and b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/resources/util/iOSMDMAgent.ipa differ