Merge pull request #3 from inoshperera/application-mgt-new

Unit test case adding to core
feature/appm-store/pbac
Dharmakeerhi Lasantha 6 years ago committed by GitHub
commit 625589decc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -103,6 +103,20 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<jacoco-agent.destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</jacoco-agent.destfile>
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

@ -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;

@ -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);
}
}

@ -20,4 +20,9 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="ApplicationManagementCore">
<test name="Util classes tests" preserve-order="true">
<classes>
<class name="org.wso2.carbon.device.application.mgt.core.ArtifactParserTest"/>
</classes>
</test>
</suite>
Loading…
Cancel
Save