Skip to content

Commit

Permalink
refactor: Migrate Internal Config class to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansi-mParticle committed Feb 5, 2025
1 parent 38adc3c commit 3a5292e
Show file tree
Hide file tree
Showing 8 changed files with 1,539 additions and 1,488 deletions.
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

0 comments on commit 3a5292e

Please sign in to comment.