Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Migrate Internal Config class to kotlin #538

Open
wants to merge 2 commits into
base: blackout-2024
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,19 @@ class MParticleTest : BaseCleanStartedEachTest() {
startMParticle()
MParticle.getInstance()!!.Messaging().enablePushNotifications(senderId)
var fetchedSenderId: String? =
MParticle.getInstance()!!.mInternal.getConfigManager().getPushSenderId()
MParticle.getInstance()!!.mInternal.getConfigManager().pushSenderId
Assert.assertTrue(
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled() ?: false
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled ?: false
)
Assert.assertEquals(senderId, fetchedSenderId)
val otherSenderId = "senderIdLogPushRegistration"
MParticle.getInstance()!!.logPushRegistration("instanceId", otherSenderId)
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().getPushSenderId()
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().pushSenderId
Assert.assertEquals(otherSenderId, fetchedSenderId)
MParticle.getInstance()!!.Messaging().disablePushNotifications()
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().getPushSenderId()
fetchedSenderId = MParticle.getInstance()!!.mInternal.getConfigManager().pushSenderId
Assert.assertFalse(
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled() ?: false
MParticle.getInstance()!!.mInternal.getConfigManager().isPushEnabled ?: false
)
Assert.assertNull(fetchedSenderId)
}
Expand Down Expand Up @@ -342,7 +342,7 @@ class MParticleTest : BaseCleanStartedEachTest() {
Assert.assertTrue(databaseJson.getJSONArray("messages").length() > 0)
Assert.assertEquals(6, allTables.size.toLong())
Assert.assertTrue(
10 < (MParticle.getInstance()!!.mInternal.getConfigManager().getMpids()?.size ?: 0)
10 < (MParticle.getInstance()!!.mInternal.getConfigManager().mpids?.size ?: 0)
)

// Set strict mode, so if we get any warning or error messages during the reset/restart phase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,38 @@ class ConfigManagerInstrumentedTest : BaseAbstractTest() {
val loadedKitLocal = AndroidUtils.Mutable(false)
setCachedConfig(simpleConfigWithKits)
mServer.setupConfigDeferred()
val configLoadedListener = ConfigLoadedListener { configType, isNew ->
if (!isNew) {
when (configType) {
ConfigType.CORE -> {
if (loadedCoreLocal.value) {
Assert.fail("core config already loaded")
} else {
Logger.error("LOADED CACHED Core")
loadedCoreLocal.value = true
val configLoadedListener = object : ConfigLoadedListener {
override fun onConfigUpdated(configType: ConfigType, isNew: Boolean) {
if (!isNew) {
when (configType) {
ConfigType.CORE -> {
if (loadedCoreLocal.value) {
Assert.fail("core config already loaded")
} else {
Logger.error("LOADED CACHED Core")
loadedCoreLocal.value = true
}
if (loadedKitLocal.value) {
Assert.fail("kit config already loaded")
} else {
Logger.error("LOADED CACHED Kit")
loadedKitLocal.value = true
}
}
if (loadedKitLocal.value) {

ConfigType.KIT -> if (loadedKitLocal.value) {
Assert.fail("kit config already loaded")
} else {
Logger.error("LOADED CACHED Kit")
loadedKitLocal.value = true
}
}
ConfigType.KIT -> if (loadedKitLocal.value) {
Assert.fail("kit config already loaded")
} else {
Logger.error("LOADED CACHED Kit")
loadedKitLocal.value = true
}
}
if (loadedCoreLocal.value && loadedKitLocal.value) {
latch.countDown()
}
Logger.error("KIT = " + loadedKitLocal.value + " Core: " + loadedCoreLocal.value)
}
if (loadedCoreLocal.value && loadedKitLocal.value) {
latch.countDown()
}
Logger.error("KIT = " + loadedKitLocal.value + " Core: " + loadedCoreLocal.value)
}
val options = MParticleOptions.builder(mContext)
.credentials("key", "secret")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class ConfigMigrationTest : BaseCleanInstallEachTest() {
}

private fun setOldConfigState(config: JSONObject) {
ConfigManager.getInstance(mContext).getKitConfigPreferences().edit()
.remove(ConfigManager.KIT_CONFIG_KEY)
ConfigManager.getInstance(mContext).kitConfigPreferences?.edit()
?.remove(ConfigManager.KIT_CONFIG_KEY)
ConfigManager.getPreferences(mContext).edit()
.putString(oldConfigSharedprefsKey, config.toString()).apply()
}
Expand All @@ -144,7 +144,7 @@ class ConfigMigrationTest : BaseCleanInstallEachTest() {
assertNull(JSONObject(configString).optJSONArray(ConfigManager.KEY_EMBEDDED_KITS))
assertEquals(
config.optString(ConfigManager.KEY_EMBEDDED_KITS, JSONArray().toString()),
ConfigManager.getInstance(mContext).kitConfigPreferences.getString(
ConfigManager.getInstance(mContext).kitConfigPreferences?.getString(
ConfigManager.KIT_CONFIG_KEY,
JSONArray().toString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ class ConfigStalenessCheckTest : BaseCleanInstallEachTest() {
fun MParticleOptions.Builder.addCredentials() = this.credentials("apiKey", "apiSecret")

fun ConfigManager.onNewConfig(callback: () -> Unit) {
addConfigUpdatedListener { configType, isNew ->
if (isNew && configType == ConfigManager.ConfigType.CORE) {
callback()
addConfigUpdatedListener(object : ConfigManager.ConfigLoadedListener {
override fun onConfigUpdated(configType: ConfigManager.ConfigType, isNew: Boolean) {
if (isNew && configType == ConfigManager.ConfigType.CORE) {
callback()
}
}
}
})
}
}
Loading
Loading