@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, version); return true; } }, "add custom device data");
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, value); return true; } }, "add custom device data");
@Override protected boolean execute(Conversation conversation) { conversation.getPerson().getCustomData().put(key, version); return true; } }, "add custom person data");
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, dateTime); return true; } }, "add custom device data");
@Override protected boolean execute(Conversation conversation) { conversation.getPerson().getCustomData().put(key, value); return true; } }, "add custom person data");
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, value); return true; } }, "add custom device data");
@Override protected boolean execute(Conversation conversation) { conversation.getPerson().getCustomData().put(key, dateTime); return true; } }, "add custom person data");
@Override protected boolean execute(Conversation conversation) { conversation.getPerson().getCustomData().put(key, value); return true; } }, "add custom person data");
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, trim(value)); return true; } }, "add custom device data");
@Override protected boolean execute(Conversation conversation) { conversation.getPerson().getCustomData().put(key, trim(value)); return true; } }, "add custom person data");
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)); } }
conversation.getDevice().getCustomData().put(key, variantName);
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 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."); }
@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."); } }
@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)); }
@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)); }
@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)); } }