public ConversationData() { this.localIdentifier = UUID.randomUUID().toString(); this.device = new Device(); this.person = new Person(); this.sdk = new Sdk(); this.appRelease = new AppRelease(); this.eventData = new EventData(); this.versionHistory = new VersionHistory(); }
public static AppRelease generateCurrentAppRelease(Context context, ApptentiveInternal apptentiveInternal) { AppRelease appRelease = new AppRelease(); String appPackageName = context.getPackageName(); int themeOverrideResId = context.getResources().getIdentifier("ApptentiveThemeOverride", "style", appPackageName); ApplicationInfo applicationInfo = RuntimeUtils.getApplicationInfo(context); appRelease.setAppStore(Util.getInstallerPackageName(context)); appRelease.setDebug(applicationInfo.isDebuggable()); appRelease.setIdentifier(appPackageName); if (apptentiveInternal != null) { appRelease.setInheritStyle(apptentiveInternal.isAppUsingAppCompatTheme()); } appRelease.setOverrideStyle(themeOverrideResId != 0); appRelease.setTargetSdkVersion(String.valueOf(applicationInfo.getTargetSdkVersion())); appRelease.setType("android"); appRelease.setVersionCode(applicationInfo.getVersionCode()); appRelease.setVersionName(applicationInfo.getVersionName()); return appRelease; }
@Test public void defaultValues() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testDefaultValues.json"); InteractionCriteria criteria = new InteractionCriteria(json); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), new Device(), new AppRelease()); assertNotNull("Criteria was null, but it shouldn't be.", criteria); assertTrue(criteria.isMet(fieldManager)); } }
@Test public void cornerCasesThatShouldBeTrue() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testCornerCasesThatShouldBeTrue.json"); InteractionCriteria criteria = new InteractionCriteria(json); EventData eventData = new EventData(); Device device = new Device(); device.getCustomData().put("key_with_null_value", null); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); assertNotNull("Criteria was null, but it shouldn't be.", criteria); assertTrue(criteria.isMet(fieldManager)); ApptentiveLog.e("Finished test."); }
private void doTest(String testFile) throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + testFile); InteractionCriteria criteria = new InteractionCriteria(json); Device device = new Device(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), device, new AppRelease()); device.getCustomData().put(" string_qwerty ", "qwerty"); device.getCustomData().put(" string with spaces ", "string with spaces"); /* TODO: It looks like we weren't trimming custom_data keys before storing them. What is the implication of doing that? We can't store a key under " key " and then retrieve it with "key" */ assertTrue(criteria.isMet(fieldManager)); } }
@Test public void cornerCasesThatShouldBeFalse() throws JSONException { ApptentiveLog.e("Running test: testCornerCasesThatShouldBeFalse()\n\n"); String json = loadTextAssetAsString(TEST_DATA_DIR + "testCornerCasesThatShouldBeFalse.json"); InteractionCriteria criteria = new InteractionCriteria(json); EventData eventData = new EventData(); Device device = new Device(); device.getCustomData().put("key_with_null_value", null); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); assertNotNull("Criteria was null, but it shouldn't be.", criteria); assertTrue(criteria.isMet(fieldManager)); ApptentiveLog.e("Finished test."); } }
private void migrateAppRelease() { String appReleaseString = prefs.getString(Constants.PREF_KEY_APP_RELEASE, null); if (appReleaseString != null) { try { com.apptentive.android.sdk.migration.v4_0_0.AppRelease appReleaseOld = new com.apptentive.android.sdk.migration.v4_0_0.AppRelease(appReleaseString); AppRelease appRelease = new AppRelease(); appRelease.setAppStore(appReleaseOld.getAppStore()); appRelease.setDebug(appReleaseOld.getDebug()); appRelease.setIdentifier(appReleaseOld.getIdentifier()); appRelease.setInheritStyle(appReleaseOld.getInheritStyle()); appRelease.setOverrideStyle(appReleaseOld.getOverrideStyle()); appRelease.setTargetSdkVersion(appReleaseOld.getTargetSdkVersion()); appRelease.setType(appReleaseOld.getType()); appRelease.setVersionCode(appReleaseOld.getVersionCode()); appRelease.setVersionName(appReleaseOld.getVersionName()); conversation.setAppRelease(appRelease); } catch (Exception e) { ApptentiveLog.e(CONVERSATION, e, "Error migrating AppRelease."); logException(e); } } }
@Test public void savingCodePointAndCheckingForApplicableInteraction() throws JSONException { if (isRunningOnEmulator()) { ApptentiveLog.e("Running on emulator. Skipping test."); return; } final int iterations = 100; String json = loadTextAssetAsString(TEST_DATA_DIR + "payloads/testListOfVariousInteractions.json"); InteractionCriteria criteria = new InteractionCriteria(json); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), new Device(), new AppRelease()); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "app.launch"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "app.launch"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "big.win"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "big.win"); long start = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { assertTrue(criteria.isMet(fieldManager)); } long end = System.currentTimeMillis(); long duration = end - start; double average = (double) duration / iterations; double limit = 20d; String message = String.format("Finished %d iterations in %,dms, average of %.2fms per run, limit was %.2fms", iterations, duration, average, limit); ApptentiveLog.e(message); assertTrue(message, average < limit); }
@Test public void criteriaProcessingPerformance() throws JSONException { if (isRunningOnEmulator()) { ApptentiveLog.e("Running on emulator. Skipping test."); return; } final int iterations = 100; String json = loadTextAssetAsString(TEST_DATA_DIR + "payloads/testListOfVariousInteractions.json"); InteractionCriteria criteria = new InteractionCriteria(json); VersionHistory versionHistory = new VersionHistory(); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, versionHistory, eventData, new Person(), new Device(), new AppRelease()); versionHistory.updateVersionHistory(Util.currentTimeSeconds(), versionCode, versionName); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "app.launch"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "app.launch"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "big.win"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "big.win"); long start = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { assertTrue(criteria.isMet(fieldManager)); } long end = System.currentTimeMillis(); long duration = end - start; double average = (double) duration / iterations; double limit = 7d; String message = String.format("Finished %d iterations in %,dms, average of %.2fms per run, limit was %.2fms", iterations, duration, average, limit); ApptentiveLog.e(message); assertTrue(message, average < limit); }
@Test public void queriesAgainstSdk() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testQueriesAgainstSdk.json"); InteractionCriteria criteria = new InteractionCriteria(json); Device device = new Device(); device.getCustomData().put("foo", "bar"); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); // 0 assertTrue(criteria.isMet(fieldManager)); // 1 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); // 2 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertFalse(criteria.isMet(fieldManager)); } }
@Test public void queriesAgainstDevice() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testQueriesAgainstDevice.json"); json = json.replace("\"OS_API_LEVEL\"", String.valueOf(Build.VERSION.SDK_INT)); InteractionCriteria criteria = new InteractionCriteria(json); Device device = DeviceManager.generateNewDevice(targetContext); device.getCustomData().put("foo", "bar"); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); // 0 assertTrue(criteria.isMet(fieldManager)); // 1 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); // 2 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertFalse(criteria.isMet(fieldManager)); // 3 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); // 4 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); }
private void doTest(String testFile) throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + testFile); InteractionCriteria criteria = new InteractionCriteria(json); Device device = new Device(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), device, new AppRelease()); Apptentive.DateTime dateTime = new Apptentive.DateTime(1000d); Apptentive.Version version = new Apptentive.Version(); version.setVersion("1.2.3"); device.getCustomData().put("number_5", 5); device.getCustomData().put("string_qwerty", "qwerty"); device.getCustomData().put("boolean_true", true); device.getCustomData().put("key_with_null_value", (String) null); device.getCustomData().put("datetime_1000", dateTime); device.getCustomData().put("version_1.2.3", version); assertTrue(criteria.isMet(fieldManager)); } }
@Test public void queriesAgainstPerson() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testQueriesAgainstPerson.json"); InteractionCriteria criteria = new InteractionCriteria(json); Person person = new Person(); person.setEmail("example@example.com"); person.getCustomData().put("foo", "bar"); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, person, new Device(), new AppRelease()); // 0 assertTrue(criteria.isMet(fieldManager)); // 1 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertFalse(criteria.isMet(fieldManager)); // 2 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); // 3 person.getCustomData().put("foo", "bar"); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); // 4 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertFalse(criteria.isMet(fieldManager)); // 5 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); }
FieldManager fieldManager = new FieldManager(targetContext, versionHistory, eventData, new Person(), new Device(), new AppRelease());
FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), new Device(), new AppRelease());
FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), new Device(), new AppRelease());
FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), new Device(), new AppRelease());
FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), new Device(), new AppRelease());
listenerFired = false; data.setAppRelease(new AppRelease()); assertTrue(listenerFired); listenerFired = false;