summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRHenigan <heniganr1@gmail.com>2020-06-17 11:46:56 -0400
committerRHenigan <heniganr1@gmail.com>2020-06-17 11:46:56 -0400
commit54fdad4f59107794e461ce5ec41191832bd2c2aa (patch)
tree7aea4ff3ad1af0658da57393d5b08b5b558e622d
parent65f9523cc5a3a5de52c42d49b01409d76a58fd8d (diff)
downloadsdl_android-54fdad4f59107794e461ce5ec41191832bd2c2aa.tar.gz
Refactor android tests that are order dependant
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java109
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java165
2 files changed, 160 insertions, 114 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java
index 776da6ccc..fa3f334e6 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/SdlConnection/SdlConnectionTest.java
@@ -1,6 +1,7 @@
package com.smartdevicelink.SdlConnection;
-import com.smartdevicelink.AndroidTestCase2;
+import android.support.test.runner.AndroidJUnit4;
+
import com.smartdevicelink.test.SdlUnitTestContants;
import com.smartdevicelink.test.util.DeviceUtil;
import com.smartdevicelink.transport.BTTransportConfig;
@@ -10,49 +11,54 @@ import com.smartdevicelink.transport.RouterServiceValidator;
import com.smartdevicelink.transport.USBTransportConfig;
import com.smartdevicelink.transport.enums.TransportType;
-public class SdlConnectionTest extends AndroidTestCase2 {
-
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.assertNull;
+import static junit.framework.TestCase.assertTrue;
+
+
+@RunWith(AndroidJUnit4.class)
+@FixMethodOrder(MethodSorters.JVM)
+public class SdlConnectionTest {
+
private static final String TAG = "SdlConnection Tests";
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- }
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
+ @Test
public void testForceConnectEvent(){
SdlConnection.enableLegacyMode(false, null);
assertNull(SdlConnectionTestClass.cachedMultiConfig);
-
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext);
+
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PERFORM_ALL_CHECKS);
- MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
SdlConnectionTestClass connection = new SdlConnectionTestClass(config,rsvp);
assertNotNull(SdlConnectionTestClass.cachedMultiConfig);
-
+
assertTrue(SdlConnectionTestClass.isLegacyModeEnabled());
-
+
assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
-
+
assertNotNull(SdlConnectionTestClass.cachedMultiConfig);
-
+
connection.forceHardwareConnectEvent(TransportType.MULTIPLEX);
assertFalse(connection.connected);
SdlConnectionTestClass.cachedMultiConfig.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
-
+
if(!DeviceUtil.isEmulator()) { // Cannot perform MBT operations in emulator
assertNotNull(SdlConnectionTestClass.cachedMultiConfig.getService());
assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
}
-
+
// Test for handling of null service
- MultiplexTransportConfig null_service_config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig null_service_config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
null_service_config.setService(null);
SdlConnectionTestClass null_service_connection = new SdlConnectionTestClass(null_service_config, null);
Exception exception = null;
@@ -61,15 +67,16 @@ public class SdlConnectionTest extends AndroidTestCase2 {
}catch(NullPointerException e){
exception = e;
}
-
+
assertNull(exception); // Failed, unhandled NPE
}
-
+
+ @Test
public void testMultiplexConstructor(){
SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext);
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
- MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
SdlConnection connection = new SdlConnection(config,rsvp);
if(DeviceUtil.isEmulator()){ // Cannot perform MBT operations in emulator
assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
@@ -77,12 +84,13 @@ public class SdlConnectionTest extends AndroidTestCase2 {
assertEquals(TransportType.MULTIPLEX, connection.getCurrentTransportType());
}
}
-
+
+ @Test
public void testMultiplexConstructorInsalledFrom(){
SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext);
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
- MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
SdlConnection connection = new SdlConnection(config,rsvp);
boolean didValidate = rsvp.validate();
if(didValidate){
@@ -92,12 +100,13 @@ public class SdlConnectionTest extends AndroidTestCase2 {
}
}
-
+
+ @Test
public void testMultiplexConstructorTrustedPackage(){
SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext);
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PACKAGE_CHECK);
- MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
SdlConnection connection = new SdlConnection(config,rsvp);
boolean didValidate = rsvp.validate();
if(didValidate){
@@ -107,12 +116,13 @@ public class SdlConnectionTest extends AndroidTestCase2 {
}
}
-
+
+ @Test
public void testMultiplexConstructorTrustedPackageAndVersion(){
SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext);
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
- MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
SdlConnection connection = new SdlConnection(config,rsvp);
boolean didValidate = rsvp.validate();
if(didValidate){
@@ -120,13 +130,15 @@ public class SdlConnectionTest extends AndroidTestCase2 {
}else{
assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
- } }
-
+ }
+ }
+
+ @Test
public void testMultiplexConstructorAllFlags(){
SdlConnection.enableLegacyMode(false, null);
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext);
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PERFORM_ALL_CHECKS);
- MultiplexTransportConfig config = new MultiplexTransportConfig(this.mContext,SdlUnitTestContants.TEST_APP_ID);
+ MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(),SdlUnitTestContants.TEST_APP_ID);
SdlConnection connection = new SdlConnection(config,rsvp);
boolean didValidate = rsvp.validate();
if(didValidate){
@@ -134,8 +146,10 @@ public class SdlConnectionTest extends AndroidTestCase2 {
}else{
assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
- } }
-
+ }
+ }
+
+ @Test
public void testBluetoothConstructor(){
SdlConnection.enableLegacyMode(false, null);
BTTransportConfig btConfig = new BTTransportConfig(true);
@@ -143,9 +157,10 @@ public class SdlConnectionTest extends AndroidTestCase2 {
assertEquals(TransportType.BLUETOOTH, connection.getCurrentTransportType());
}
+ @Test
public void testUsbConstructor(){
SdlConnection.enableLegacyMode(false, null);
- USBTransportConfig btConfig = new USBTransportConfig(mContext);
+ USBTransportConfig btConfig = new USBTransportConfig(getTargetContext());
SdlConnection connection = new SdlConnection(btConfig,null);
assertFalse(SdlConnection.isLegacyModeEnabled());
assertEquals(TransportType.USB, connection.getCurrentTransportType());
@@ -153,7 +168,7 @@ public class SdlConnectionTest extends AndroidTestCase2 {
SdlConnection connection2 = new SdlConnection(btConfig);
assertEquals(TransportType.USB, connection2.getCurrentTransportType());
}
-
+
protected class SdlConnectionTestClass extends SdlConnection{
protected boolean connected = false;
public SdlConnectionTestClass(BaseTransportConfig transportConfig) {
@@ -163,7 +178,7 @@ public class SdlConnectionTest extends AndroidTestCase2 {
protected SdlConnectionTestClass(BaseTransportConfig transportConfig,RouterServiceValidator rsvp){
super(transportConfig,rsvp);
}
-
+
@Override
public void onTransportConnected() {
super.onTransportConnected();
@@ -174,7 +189,7 @@ public class SdlConnectionTest extends AndroidTestCase2 {
public void onTransportDisconnected(String info) {
connected = false;
//Grab a currently running router service
- RouterServiceValidator rsvp2 = new RouterServiceValidator(mContext);
+ RouterServiceValidator rsvp2 = new RouterServiceValidator(getTargetContext());
rsvp2.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
assertTrue(rsvp2.validate());
assertNotNull(rsvp2.getService());
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
index 538d5fed4..8302ec53c 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
@@ -5,15 +5,20 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.ConditionVariable;
+import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
-import com.smartdevicelink.AndroidTestCase2;
import com.smartdevicelink.transport.RouterServiceValidator.TrustedAppStore;
import com.smartdevicelink.util.HttpRequestTask.HttpRequestTaskCallback;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -21,7 +26,17 @@ import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.Semaphore;
-public class RSVTestCase extends AndroidTestCase2 {
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.assertNull;
+import static junit.framework.TestCase.assertTrue;
+import static junit.framework.TestCase.fail;
+
+@RunWith(AndroidJUnit4.class)
+@FixMethodOrder(MethodSorters.JVM)
+public class RSVTestCase {
private static final String TAG = "RSVTestCase";
private static final long REFRESH_TRUSTED_APP_LIST_TIME_DAY = 3600000 * 24; // A day in ms
@@ -35,18 +50,12 @@ public class RSVTestCase extends AndroidTestCase2 {
*/
boolean liveTest = false;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- rsvp = new RouterServiceValidator(this.mContext);
+ @Before
+ public void setUp() throws Exception {
+ rsvp = new RouterServiceValidator(getTargetContext());
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
private static final Semaphore TRUSTED_LIST_LOCK = new Semaphore(1);
private void requestTListLock(){
@@ -72,45 +81,51 @@ public class RSVTestCase extends AndroidTestCase2 {
* These tests are a little strange because they don't test the logic behind the validation of each piece.
* However, they allow us to test
*/
-
+
+ @Test
public void testInstalledFrom(){
if(liveTest){
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
assertTrue(rsvp.validate());
}
}
-
+
+ @Test
public void testPackageCheck(){
if(liveTest){
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PACKAGE_CHECK);
assertTrue(rsvp.validate());
}
}
-
+
+ @Test
public void testVersionCheck(){
if(liveTest){
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_VERSION_CHECK);
assertTrue(rsvp.validate());
}
}
-
+
+ @Test
public void testNoFlags(){
if(liveTest){
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_NONE);
assertTrue(rsvp.validate());
}
}
-
+
+ @Test
public void testAllFlags(){
if(liveTest){
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_PERFORM_ALL_CHECKS);
assertTrue(rsvp.validate());
}
}
-
+
+ @Test
public void testSecuritySetting(){
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext()); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
try{
@@ -122,13 +137,14 @@ public class RSVTestCase extends AndroidTestCase2 {
}catch( IllegalAccessException e2){
fail(e2.getMessage());
}
- assertEquals(RouterServiceValidator.getSecurityLevel(mContext), MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
+ assertEquals(RouterServiceValidator.getSecurityLevel(getTargetContext()), MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
}
-
+
+ @Test
public void testHighSecurity(){
requestTListLock();
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext()); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -136,14 +152,15 @@ public class RSVTestCase extends AndroidTestCase2 {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_WEEK);
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(getTargetContext(), true, null, trustedListCallback));
}
-
+
+ @Test
public void testMediumSecurity(){
requestTListLock();
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext()); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_MED);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -151,14 +168,15 @@ public class RSVTestCase extends AndroidTestCase2 {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_WEEK);
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(getTargetContext(), true, null, trustedListCallback));
}
-
+
+ @Test
public void testLowSecurity(){
requestTListLock();
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext()); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_LOW);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -166,14 +184,15 @@ public class RSVTestCase extends AndroidTestCase2 {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_MONTH);
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(getTargetContext(), true, null, trustedListCallback));
}
-
+
+ @Test
public void testNoSecurity(){
requestTListLock();
- RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
+ RouterServiceValidator rsvp = new RouterServiceValidator(getTargetContext()); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -181,7 +200,7 @@ public class RSVTestCase extends AndroidTestCase2 {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_WEEK);
- assertFalse(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
+ assertFalse(RouterServiceValidator.createTrustedListRequest(getTargetContext(), true, null, trustedListCallback));
//This should always return true
assertTrue(rsvp.validate());
@@ -205,54 +224,59 @@ public class RSVTestCase extends AndroidTestCase2 {
}
return false;
}
-
+
+ @Test
public void testJsonRecovery(){
assertNotNull(rsvp.stringToJson(null));
assertNotNull(rsvp.stringToJson("asdf235vq32{]]"));
}
-
+
+ @Test
public void testInvalidateList(){
requestTListLock();
assertFalse(RouterServiceValidator.invalidateList(null));
- assertTrue(RouterServiceValidator.invalidateList(mContext));
+ assertTrue(RouterServiceValidator.invalidateList(getTargetContext()));
releaseTListLock();
}
-
+
+ @Test
public void testGetTrustedList(){
requestTListLock();
assertNull(RouterServiceValidator.getTrustedList(null));
- assertNotNull(RouterServiceValidator.getTrustedList(mContext));
+ assertNotNull(RouterServiceValidator.getTrustedList(getTargetContext()));
releaseTListLock();
}
-
+
+ @Test
public void testSetTrustedList(){
requestTListLock();
assertFalse(RouterServiceValidator.setTrustedList(null,null));
- assertFalse(RouterServiceValidator.setTrustedList(mContext,null));
+ assertFalse(RouterServiceValidator.setTrustedList(getTargetContext(),null));
assertFalse(RouterServiceValidator.setTrustedList(null,"test"));
- assertTrue(RouterServiceValidator.setTrustedList(mContext,"test"));
- assertTrue(RouterServiceValidator.setTrustedList(mContext,TEST));
- assertTrue(RouterServiceValidator.setTrustedList(mContext,TEST+TEST+TEST+TEST+TEST));
+ assertTrue(RouterServiceValidator.setTrustedList(getTargetContext(),"test"));
+ assertTrue(RouterServiceValidator.setTrustedList(getTargetContext(),TEST));
+ assertTrue(RouterServiceValidator.setTrustedList(getTargetContext(),TEST+TEST+TEST+TEST+TEST));
StringBuilder builder = new StringBuilder();
for(int i = 0; i<1000; i++){
builder.append(TEST);
}
- assertTrue(RouterServiceValidator.setTrustedList(mContext,builder.toString()));
+ assertTrue(RouterServiceValidator.setTrustedList(getTargetContext(),builder.toString()));
releaseTListLock();
}
-
+
+ @Test
public void testTrustedListSetAndGet(){
requestTListLock();
- assertTrue(RouterServiceValidator.setTrustedList(mContext,TEST));
- String retVal = RouterServiceValidator.getTrustedList(mContext);
+ assertTrue(RouterServiceValidator.setTrustedList(getTargetContext(),TEST));
+ String retVal = RouterServiceValidator.getTrustedList(getTargetContext());
assertNotNull(retVal);
assertTrue(TEST.equals(retVal));
@@ -260,32 +284,34 @@ public class RSVTestCase extends AndroidTestCase2 {
for(int i = 0; i<1000; i++){
builder.append(TEST);
}
- assertTrue(RouterServiceValidator.setTrustedList(mContext,builder.toString()));
- retVal = RouterServiceValidator.getTrustedList(mContext);
+ assertTrue(RouterServiceValidator.setTrustedList(getTargetContext(),builder.toString()));
+ retVal = RouterServiceValidator.getTrustedList(getTargetContext());
assertNotNull(retVal);
assertTrue(builder.toString().equals(retVal));
releaseTListLock();
}
-
+
+ @Test
public void testInvalidationSequence(){
requestTListLock();
- assertTrue(RouterServiceValidator.invalidateList(mContext));
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, false, null, trustedListCallback));
+ assertTrue(RouterServiceValidator.invalidateList(getTargetContext()));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(getTargetContext(), false, null, trustedListCallback));
}
-
+
+ @Test
public void testAppStorePackages(){
assertTrue(TrustedAppStore.isTrustedStore(TrustedAppStore.PLAY_STORE.packageString));
assertTrue(TrustedAppStore.isTrustedStore("com.xiaomi.market"));
assertFalse(TrustedAppStore.isTrustedStore("test"));
assertFalse(TrustedAppStore.isTrustedStore(null));
- rsvp = new RouterServiceValidator(this.mContext);
+ rsvp = new RouterServiceValidator(getTargetContext());
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
- PackageManager packageManager = mContext.getPackageManager();
+ PackageManager packageManager = getTargetContext().getPackageManager();
List<PackageInfo> packages = packageManager.getInstalledPackages(0);
String appStore;
for(PackageInfo info: packages){
@@ -297,9 +323,10 @@ public class RSVTestCase extends AndroidTestCase2 {
assertFalse(rsvp.wasInstalledByAppStore(null));
}
-
+
+ @Test
public void testVersionBlackList(){
- rsvp = new RouterServiceValidator(this.mContext);
+ rsvp = new RouterServiceValidator(getTargetContext());
JSONArray array = new JSONArray();
for(int i=0; i<25; i++){
if(i%3 == 0){
@@ -315,6 +342,7 @@ public class RSVTestCase extends AndroidTestCase2 {
}
static boolean didFinish = false;
+ @Test
public void testGetAndCheckList(){
requestTListLock();
@@ -343,7 +371,7 @@ public class RSVTestCase extends AndroidTestCase2 {
}
};
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext,true, cb));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(getTargetContext(),true, cb));
//Now wait for call to finish
synchronized(REQUEST_LOCK){
try {
@@ -360,11 +388,12 @@ public class RSVTestCase extends AndroidTestCase2 {
/**
* Test to check that we can save our last request which actually houses all the previous known sdl enabled apps
*/
+ @Test
public void testRequestChange(){
requestTListLock();
- RouterServiceValidator.setLastRequest(mContext, null);
- assertNull(RouterServiceValidator.getLastRequest(mContext));
+ RouterServiceValidator.setLastRequest(getTargetContext(), null);
+ assertNull(RouterServiceValidator.getLastRequest(getTargetContext()));
JSONObject object = null;
try {
@@ -373,11 +402,11 @@ public class RSVTestCase extends AndroidTestCase2 {
e.printStackTrace();
}
assertNotNull(object);
- assertFalse(object.equals(RouterServiceValidator.getLastRequest(mContext)));
+ assertFalse(object.equals(RouterServiceValidator.getLastRequest(getTargetContext())));
- assertTrue(RouterServiceValidator.setLastRequest(mContext, object.toString()));
+ assertTrue(RouterServiceValidator.setLastRequest(getTargetContext(), object.toString()));
- String oldRequest = RouterServiceValidator.getLastRequest(mContext);
+ String oldRequest = RouterServiceValidator.getLastRequest(getTargetContext());
assertNotNull(oldRequest);
assertTrue(object.toString().equals(oldRequest));
@@ -390,9 +419,9 @@ public class RSVTestCase extends AndroidTestCase2 {
e.printStackTrace();
}
assertNotNull(object);
- assertFalse(object.equals(RouterServiceValidator.getLastRequest(mContext)));
+ assertFalse(object.equals(RouterServiceValidator.getLastRequest(getTargetContext())));
//Clear it for next test
- RouterServiceValidator.setLastRequest(mContext, null);
+ RouterServiceValidator.setLastRequest(getTargetContext(), null);
releaseTListLock();
}
@@ -401,6 +430,7 @@ public class RSVTestCase extends AndroidTestCase2 {
* Test app's router validation. Validation should fail when the given context and ComponentName object are from different packages and security setting is not OFF
* and app is not on trusted list. Validation should pass when the given context and ComponentName object are from the same package.
*/
+ @Test
public void testAppSelfValidation() {
class RouterServiceValidatorTest extends RouterServiceValidator{
@@ -419,12 +449,12 @@ public class RSVTestCase extends AndroidTestCase2 {
}
// Fail, different package name for context and service and app security setting is not OFF and app is not on trusted list
- RouterServiceValidatorTest rsvpFail = new RouterServiceValidatorTest(this.mContext, new ComponentName("anything", mContext.getClass().getSimpleName()));
+ RouterServiceValidatorTest rsvpFail = new RouterServiceValidatorTest(getTargetContext(), new ComponentName("anything", getTargetContext().getClass().getSimpleName()));
rsvpFail.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
assertFalse(rsvpFail.validate());
// Success, same package name for context and service
- RouterServiceValidatorTest rsvpPass = new RouterServiceValidatorTest(this.mContext, new ComponentName(mContext.getPackageName(), mContext.getClass().getSimpleName()));
+ RouterServiceValidatorTest rsvpPass = new RouterServiceValidatorTest(getTargetContext(), new ComponentName(getTargetContext().getPackageName(), getTargetContext().getClass().getSimpleName()));
rsvpPass.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
assertTrue(rsvpPass.validate());
}
@@ -432,8 +462,9 @@ public class RSVTestCase extends AndroidTestCase2 {
/**
* Unit test for validateAsync.
*/
+ @Test
public void testValidateAsync() {
- final MultiplexTransportConfig config = new MultiplexTransportConfig(mContext, APP_ID, MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
+ final MultiplexTransportConfig config = new MultiplexTransportConfig(getTargetContext(), APP_ID, MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
final RouterServiceValidator validator = new RouterServiceValidator(config);
final ConditionVariable cond = new ConditionVariable();
validator.validateAsync(new RouterServiceValidator.ValidationStatusCallback() {
@@ -447,7 +478,7 @@ public class RSVTestCase extends AndroidTestCase2 {
cond.block();
// next, test for FLAG_MULTI_SECURITY_OFF
- final MultiplexTransportConfig config2 = new MultiplexTransportConfig(mContext, APP_ID, MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
+ final MultiplexTransportConfig config2 = new MultiplexTransportConfig(getTargetContext(), APP_ID, MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
final RouterServiceValidator validator2 = new RouterServiceValidator(config2);
cond.close();
validator2.validateAsync(new RouterServiceValidator.ValidationStatusCallback() {