Adding unit tests case infrastructure to core and adding unit testcases for ArtifactsParser.java

feature/appm-store/pbac
inoshperera 6 years ago
parent 2011843736
commit 61c0ebc995

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

@ -28,7 +28,6 @@ import net.dongliu.apk.parser.bean.ApkMeta;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.wso2.carbon.device.application.mgt.core.exception.ParsingException;
import java.io.ByteArrayOutputStream;
@ -128,9 +127,7 @@ public class ArtifactsParser {
out.close();
}
if (stream != null) {
stream.close();
}
} catch (IOException e) {
}

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