diff options
author | Roshan Pius <rpius@google.com> | 2020-03-19 09:08:16 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-03-19 09:27:00 -0700 |
commit | cfae7fe0e506ee5f353c91caeb78325a4e57f0dd (patch) | |
tree | 8a8b0ffbf8f50155c098509fcaa769f1cf71da86 /tests | |
parent | 4ea546fce83b7a8b0f3b966d0bc821c613356e73 (diff) |
Add a class for caching settings migration data
This avoids calling the method multiple times on first bootup.
Bug: 151888061
Test: atest com.android.server.wifi
Change-Id: I9c92861ebb026d8305aeb0e29b388e4b1037cfaa
Diffstat (limited to 'tests')
3 files changed, 38 insertions, 26 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java index 56ba8878f..a1b917431 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java @@ -30,16 +30,14 @@ import android.util.BackupUtils; import androidx.test.filters.SmallTest; -import com.android.dx.mockito.inline.extended.ExtendedMockito; import com.android.server.wifi.util.ApConfigUtil; +import com.android.server.wifi.util.SettingsMigrationDataHolder; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.MockitoSession; -import org.mockito.quality.Strictness; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -55,6 +53,7 @@ import java.util.List; public class SoftApBackupRestoreTest extends WifiBaseTest { @Mock private Context mContext; + @Mock private SettingsMigrationDataHolder mSettingsMigrationDataHolder; @Mock private WifiMigration.SettingsMigrationData mOemMigrationData; private SoftApBackupRestore mSoftApBackupRestore; private final ArrayList<MacAddress> mTestBlockedList = new ArrayList<>(); @@ -72,8 +71,6 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { private static final int TEST_CHANNEL = 40; private static final boolean TEST_HIDDEN = false; - MockitoSession mSession; - /** * Asserts that the WifiConfigurations equal to SoftApConfiguration. * This only compares the elements saved @@ -100,20 +97,14 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mSession = ExtendedMockito.mockitoSession() - .mockStatic(WifiMigration.class, withSettings().lenient()) - .strictness(Strictness.LENIENT) - .startMocking(); - when(WifiMigration.loadFromSettings(any(Context.class))) - .thenReturn(mOemMigrationData); + when(mSettingsMigrationDataHolder.retrieveData()).thenReturn(mOemMigrationData); when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true); - mSoftApBackupRestore = new SoftApBackupRestore(mContext); + mSoftApBackupRestore = new SoftApBackupRestore(mContext, mSettingsMigrationDataHolder); } @After public void tearDown() throws Exception { - mSession.finishMocking(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java index 04955f806..739987106 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java @@ -26,7 +26,6 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.Mockito.withSettings; import android.content.Context; import android.net.MacAddress; @@ -37,8 +36,8 @@ import android.util.Xml; import androidx.test.filters.SmallTest; -import com.android.dx.mockito.inline.extended.ExtendedMockito; import com.android.internal.util.FastXmlSerializer; +import com.android.server.wifi.util.SettingsMigrationDataHolder; import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil; import org.junit.After; @@ -47,8 +46,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.MockitoSession; -import org.mockito.quality.Strictness; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; @@ -187,21 +184,17 @@ public class SoftApStoreDataTest extends WifiBaseTest { @Mock private Context mContext; @Mock SoftApStoreData.DataSource mDataSource; @Mock private WifiMigration.SettingsMigrationData mOemMigrationData; - MockitoSession mSession; + @Mock private SettingsMigrationDataHolder mSettingsMigrationDataHolder; SoftApStoreData mSoftApStoreData; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mSession = ExtendedMockito.mockitoSession() - .mockStatic(WifiMigration.class, withSettings().lenient()) - .strictness(Strictness.LENIENT) - .startMocking(); - when(WifiMigration.loadFromSettings(any(Context.class))) + when(mSettingsMigrationDataHolder.retrieveData()) .thenReturn(mOemMigrationData); when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true); - mSoftApStoreData = new SoftApStoreData(mContext, mDataSource); + mSoftApStoreData = new SoftApStoreData(mContext, mSettingsMigrationDataHolder, mDataSource); TEST_BLOCKEDLIST.add(MacAddress.fromString(TEST_BLOCKED_CLIENT)); TEST_ALLOWEDLIST.add(MacAddress.fromString(TEST_ALLOWED_CLIENT)); } @@ -213,7 +206,6 @@ public class SoftApStoreDataTest extends WifiBaseTest { public void cleanup() { TEST_BLOCKEDLIST.clear(); TEST_ALLOWEDLIST.clear(); - mSession.finishMocking(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java index 2471e090e..e2e2575d8 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java @@ -25,8 +25,10 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.validateMockitoUsage; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; import android.content.Context; +import android.net.wifi.WifiMigration; import android.os.Handler; import android.os.test.TestLooper; import android.util.Xml; @@ -35,6 +37,7 @@ import androidx.test.filters.SmallTest; import com.android.internal.util.FastXmlSerializer; import com.android.server.wifi.WifiSettingsConfigStore.Key; +import com.android.server.wifi.util.SettingsMigrationDataHolder; import com.android.server.wifi.util.XmlUtil; import org.junit.After; @@ -61,6 +64,8 @@ public class WifiSettingsConfigStoreTest extends WifiBaseTest { @Mock private Context mContext; @Mock + private SettingsMigrationDataHolder mSettingsMigrationDataHolder; + @Mock private WifiConfigStore mWifiConfigStore; @Mock private WifiConfigManager mWifiConfigManager; @@ -75,7 +80,7 @@ public class WifiSettingsConfigStoreTest extends WifiBaseTest { mLooper = new TestLooper(); mWifiSettingsConfigStore = new WifiSettingsConfigStore(mContext, new Handler(mLooper.getLooper()), - mWifiConfigManager, mWifiConfigStore); + mSettingsMigrationDataHolder, mWifiConfigManager, mWifiConfigStore); } /** @@ -124,6 +129,30 @@ public class WifiSettingsConfigStoreTest extends WifiBaseTest { storeDataCaptor.getValue().deserializeData(in, in.getDepth(), -1, null); assertTrue(mWifiSettingsConfigStore.get(WIFI_VERBOSE_LOGGING_ENABLED)); + // verify that we did not trigger migration. + verifyNoMoreInteractions(mSettingsMigrationDataHolder); + } + + @Test + public void testLoadFromMigration() throws Exception { + ArgumentCaptor<WifiConfigStore.StoreData> storeDataCaptor = ArgumentCaptor.forClass( + WifiConfigStore.StoreData.class); + verify(mWifiConfigStore).registerStoreData(storeDataCaptor.capture()); + assertNotNull(storeDataCaptor.getValue()); + + WifiMigration.SettingsMigrationData migrationData = mock( + WifiMigration.SettingsMigrationData.class); + when(mSettingsMigrationDataHolder.retrieveData()).thenReturn(migrationData); + when(migrationData.isVerboseLoggingEnabled()).thenReturn(true); + + // indicate that there is not data in the store file to trigger migration. + storeDataCaptor.getValue().resetData(); + storeDataCaptor.getValue().deserializeData(null, -1, -1, null); + mLooper.dispatchAll(); + + assertTrue(mWifiSettingsConfigStore.get(WIFI_VERBOSE_LOGGING_ENABLED)); + // Trigger store file write after migration. + verify(mWifiConfigManager).saveToStore(true); } private XmlPullParser createSettingsTestXmlForParsing(Key key, Object value) |