@Test public void testCreate() throws Exception { MParticle mockMp = Mockito.mock(MParticle.class); Mockito.when(mockMp.getEnvironment()).thenReturn(MParticle.Environment.Development); MParticle.setInstance(mockMp); ConfigManager manager = new ConfigManager(new MockContext(), MParticle.Environment.Production, "some api key", "some api secret"); boolean sessionHistory = true; BatchId batchId = new BatchId(manager.getMpid(), null, null, null); MessageBatch batch = MessageBatch.create( sessionHistory, manager,new JSONObject(), batchId); assertNotNull(batch.getString("dt")); assertNotNull(batch.getString("id")); assertNotNull(batch.getDouble("ct")); assertNotNull(batch.getString("sdk")); assertNotNull(batch.getBoolean("oo")); assertNotNull(batch.getDouble("uitl")); assertNotNull(batch.getDouble("stl")); assertNotNull(batch.getJSONObject("ck")); if (manager.getProviderPersistence() != null) { assertNotNull(batch.getJSONObject("cms")); } sessionHistory = false; batch = MessageBatch.create( sessionHistory, manager,new JSONObject(), batchId); assertNotNull(batch.getString("dt")); assertNotNull(batch.getString("id")); assertNotNull(batch.getDouble("ct")); assertNotNull(batch.getString("sdk")); assertNotNull(batch.getBoolean("oo")); assertNotNull(batch.getDouble("uitl")); assertNotNull(batch.getDouble("stl")); assertNotNull(batch.getJSONObject("ck")); if (manager.getProviderPersistence() != null) { assertNotNull(batch.getJSONObject("cms")); } batch = MessageBatch.create( sessionHistory, manager,new JSONObject(), batchId); assertFalse(batch.has("pb")); }
public static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId) throws JSONException { MessageBatch uploadMessage = new MessageBatch(); if (BuildConfig.MP_DEBUG) { uploadMessage.put(Constants.MessageKey.ECHO, true); } uploadMessage.put(Constants.MessageKey.TYPE, Constants.MessageType.REQUEST_HEADER); uploadMessage.put(Constants.MessageKey.ID, UUID.randomUUID().toString()); uploadMessage.put(Constants.MessageKey.TIMESTAMP, System.currentTimeMillis()); uploadMessage.put(Constants.MessageKey.MPARTICLE_VERSION, Constants.MPARTICLE_VERSION); uploadMessage.put(Constants.MessageKey.OPT_OUT_HEADER, configManager.getOptedOut()); uploadMessage.put(Constants.MessageKey.CONFIG_UPLOAD_INTERVAL, configManager.getUploadInterval()/1000); uploadMessage.put(Constants.MessageKey.CONFIG_SESSION_TIMEOUT, configManager.getSessionTimeout()/1000); uploadMessage.put(Constants.MessageKey.MPID, String.valueOf(batchId.getMpid())); uploadMessage.put(Constants.MessageKey.SANDBOX, configManager.getEnvironment().equals(MParticle.Environment.Development)); uploadMessage.put(Constants.MessageKey.DEVICE_APPLICATION_STAMP, configManager.getDeviceApplicationStamp()); if (history) { String deletedAttr = configManager.getUserStorage(batchId.getMpid()).getDeletedUserAttributes(); if (deletedAttr != null) { uploadMessage.put(Constants.MessageKey.DELETED_USER_ATTRIBUTES, new JSONArray(deletedAttr)); configManager.getUserStorage().deleteDeletedUserAttributes(); } } uploadMessage.put(Constants.MessageKey.COOKIES, cookies); uploadMessage.put(Constants.MessageKey.PROVIDER_PERSISTENCE, configManager.getProviderPersistence()); uploadMessage.put(Constants.MessageKey.INTEGRATION_ATTRIBUTES, configManager.getIntegrationAttributes()); uploadMessage.addConsentState(configManager.getConsentState(batchId.getMpid())); uploadMessage.addDataplanContext(batchId.getDataplanId(), batchId.getDataplanVersion()); return uploadMessage; }
MessageBatch extends JSONObject { public static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId) throws JSONException { MessageBatch uploadMessage = new MessageBatch(); if (BuildConfig.MP_DEBUG) { uploadMessage.put(Constants.MessageKey.ECHO, true); } uploadMessage.put(Constants.MessageKey.TYPE, Constants.MessageType.REQUEST_HEADER); uploadMessage.put(Constants.MessageKey.ID, UUID.randomUUID().toString()); uploadMessage.put(Constants.MessageKey.TIMESTAMP, System.currentTimeMillis()); uploadMessage.put(Constants.MessageKey.MPARTICLE_VERSION, Constants.MPARTICLE_VERSION); uploadMessage.put(Constants.MessageKey.OPT_OUT_HEADER, configManager.getOptedOut()); uploadMessage.put(Constants.MessageKey.CONFIG_UPLOAD_INTERVAL, configManager.getUploadInterval()/1000); uploadMessage.put(Constants.MessageKey.CONFIG_SESSION_TIMEOUT, configManager.getSessionTimeout()/1000); uploadMessage.put(Constants.MessageKey.MPID, String.valueOf(batchId.getMpid())); uploadMessage.put(Constants.MessageKey.SANDBOX, configManager.getEnvironment().equals(MParticle.Environment.Development)); uploadMessage.put(Constants.MessageKey.DEVICE_APPLICATION_STAMP, configManager.getDeviceApplicationStamp()); if (history) { String deletedAttr = configManager.getUserStorage(batchId.getMpid()).getDeletedUserAttributes(); if (deletedAttr != null) { uploadMessage.put(Constants.MessageKey.DELETED_USER_ATTRIBUTES, new JSONArray(deletedAttr)); configManager.getUserStorage().deleteDeletedUserAttributes(); } } uploadMessage.put(Constants.MessageKey.COOKIES, cookies); uploadMessage.put(Constants.MessageKey.PROVIDER_PERSISTENCE, configManager.getProviderPersistence()); uploadMessage.put(Constants.MessageKey.INTEGRATION_ATTRIBUTES, configManager.getIntegrationAttributes()); uploadMessage.addConsentState(configManager.getConsentState(batchId.getMpid())); uploadMessage.addDataplanContext(batchId.getDataplanId(), batchId.getDataplanVersion()); return uploadMessage; } }
MessageBatch extends JSONObject { public static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId) throws JSONException { MessageBatch uploadMessage = new MessageBatch(); if (BuildConfig.MP_DEBUG) { uploadMessage.put(Constants.MessageKey.ECHO, true); } uploadMessage.put(Constants.MessageKey.TYPE, Constants.MessageType.REQUEST_HEADER); uploadMessage.put(Constants.MessageKey.ID, UUID.randomUUID().toString()); uploadMessage.put(Constants.MessageKey.TIMESTAMP, System.currentTimeMillis()); uploadMessage.put(Constants.MessageKey.MPARTICLE_VERSION, Constants.MPARTICLE_VERSION); uploadMessage.put(Constants.MessageKey.OPT_OUT_HEADER, configManager.getOptedOut()); uploadMessage.put(Constants.MessageKey.CONFIG_UPLOAD_INTERVAL, configManager.getUploadInterval()/1000); uploadMessage.put(Constants.MessageKey.CONFIG_SESSION_TIMEOUT, configManager.getSessionTimeout()/1000); uploadMessage.put(Constants.MessageKey.MPID, String.valueOf(batchId.getMpid())); uploadMessage.put(Constants.MessageKey.SANDBOX, configManager.getEnvironment().equals(MParticle.Environment.Development)); uploadMessage.put(Constants.MessageKey.DEVICE_APPLICATION_STAMP, configManager.getDeviceApplicationStamp()); if (history) { String deletedAttr = configManager.getUserStorage(batchId.getMpid()).getDeletedUserAttributes(); if (deletedAttr != null) { uploadMessage.put(Constants.MessageKey.DELETED_USER_ATTRIBUTES, new JSONArray(deletedAttr)); configManager.getUserStorage().deleteDeletedUserAttributes(); } } uploadMessage.put(Constants.MessageKey.COOKIES, cookies); uploadMessage.put(Constants.MessageKey.PROVIDER_PERSISTENCE, configManager.getProviderPersistence()); uploadMessage.put(Constants.MessageKey.INTEGRATION_ATTRIBUTES, configManager.getIntegrationAttributes()); uploadMessage.addConsentState(configManager.getConsentState(batchId.getMpid())); uploadMessage.addDataplanContext(batchId.getDataplanId(), batchId.getDataplanVersion()); return uploadMessage; } protected  MessageBatch(); }
MessageBatch extends JSONObject { public static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId) throws JSONException { MessageBatch uploadMessage = new MessageBatch(); if (BuildConfig.MP_DEBUG) { uploadMessage.put(Constants.MessageKey.ECHO, true); } uploadMessage.put(Constants.MessageKey.TYPE, Constants.MessageType.REQUEST_HEADER); uploadMessage.put(Constants.MessageKey.ID, UUID.randomUUID().toString()); uploadMessage.put(Constants.MessageKey.TIMESTAMP, System.currentTimeMillis()); uploadMessage.put(Constants.MessageKey.MPARTICLE_VERSION, Constants.MPARTICLE_VERSION); uploadMessage.put(Constants.MessageKey.OPT_OUT_HEADER, configManager.getOptedOut()); uploadMessage.put(Constants.MessageKey.CONFIG_UPLOAD_INTERVAL, configManager.getUploadInterval()/1000); uploadMessage.put(Constants.MessageKey.CONFIG_SESSION_TIMEOUT, configManager.getSessionTimeout()/1000); uploadMessage.put(Constants.MessageKey.MPID, String.valueOf(batchId.getMpid())); uploadMessage.put(Constants.MessageKey.SANDBOX, configManager.getEnvironment().equals(MParticle.Environment.Development)); uploadMessage.put(Constants.MessageKey.DEVICE_APPLICATION_STAMP, configManager.getDeviceApplicationStamp()); if (history) { String deletedAttr = configManager.getUserStorage(batchId.getMpid()).getDeletedUserAttributes(); if (deletedAttr != null) { uploadMessage.put(Constants.MessageKey.DELETED_USER_ATTRIBUTES, new JSONArray(deletedAttr)); configManager.getUserStorage().deleteDeletedUserAttributes(); } } uploadMessage.put(Constants.MessageKey.COOKIES, cookies); uploadMessage.put(Constants.MessageKey.PROVIDER_PERSISTENCE, configManager.getProviderPersistence()); uploadMessage.put(Constants.MessageKey.INTEGRATION_ATTRIBUTES, configManager.getIntegrationAttributes()); uploadMessage.addConsentState(configManager.getConsentState(batchId.getMpid())); uploadMessage.addDataplanContext(batchId.getDataplanId(), batchId.getDataplanVersion()); return uploadMessage; } protected  MessageBatch(); static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId); void addConsentState(ConsentState consentState); void addDataplanContext(String dataplanId, Integer dataplanVersion); void addSessionHistoryMessage(JSONObject message); void addMessage(JSONObject message); void addReportingMessage(JSONObject reportingMessage); void setAppInfo(JSONObject appInfo); void setDeviceInfo(JSONObject deviceInfo); JSONObject getAppInfo(); JSONObject getDeviceInfo(); JSONArray getSessionHistoryMessages(); JSONArray getMessages(); void setIdentities(JSONArray identities); void setUserAttributes(JSONObject userAttributes); long getMessageLengthBytes(); void incrementMessageLengthBytes(long bytes); }
MessageBatch extends JSONObject { public static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId) throws JSONException { MessageBatch uploadMessage = new MessageBatch(); if (BuildConfig.MP_DEBUG) { uploadMessage.put(Constants.MessageKey.ECHO, true); } uploadMessage.put(Constants.MessageKey.TYPE, Constants.MessageType.REQUEST_HEADER); uploadMessage.put(Constants.MessageKey.ID, UUID.randomUUID().toString()); uploadMessage.put(Constants.MessageKey.TIMESTAMP, System.currentTimeMillis()); uploadMessage.put(Constants.MessageKey.MPARTICLE_VERSION, Constants.MPARTICLE_VERSION); uploadMessage.put(Constants.MessageKey.OPT_OUT_HEADER, configManager.getOptedOut()); uploadMessage.put(Constants.MessageKey.CONFIG_UPLOAD_INTERVAL, configManager.getUploadInterval()/1000); uploadMessage.put(Constants.MessageKey.CONFIG_SESSION_TIMEOUT, configManager.getSessionTimeout()/1000); uploadMessage.put(Constants.MessageKey.MPID, String.valueOf(batchId.getMpid())); uploadMessage.put(Constants.MessageKey.SANDBOX, configManager.getEnvironment().equals(MParticle.Environment.Development)); uploadMessage.put(Constants.MessageKey.DEVICE_APPLICATION_STAMP, configManager.getDeviceApplicationStamp()); if (history) { String deletedAttr = configManager.getUserStorage(batchId.getMpid()).getDeletedUserAttributes(); if (deletedAttr != null) { uploadMessage.put(Constants.MessageKey.DELETED_USER_ATTRIBUTES, new JSONArray(deletedAttr)); configManager.getUserStorage().deleteDeletedUserAttributes(); } } uploadMessage.put(Constants.MessageKey.COOKIES, cookies); uploadMessage.put(Constants.MessageKey.PROVIDER_PERSISTENCE, configManager.getProviderPersistence()); uploadMessage.put(Constants.MessageKey.INTEGRATION_ATTRIBUTES, configManager.getIntegrationAttributes()); uploadMessage.addConsentState(configManager.getConsentState(batchId.getMpid())); uploadMessage.addDataplanContext(batchId.getDataplanId(), batchId.getDataplanVersion()); return uploadMessage; } protected  MessageBatch(); static MessageBatch create(boolean history, ConfigManager configManager, JSONObject cookies, BatchId batchId); void addConsentState(ConsentState consentState); void addDataplanContext(String dataplanId, Integer dataplanVersion); void addSessionHistoryMessage(JSONObject message); void addMessage(JSONObject message); void addReportingMessage(JSONObject reportingMessage); void setAppInfo(JSONObject appInfo); void setDeviceInfo(JSONObject deviceInfo); JSONObject getAppInfo(); JSONObject getDeviceInfo(); JSONArray getSessionHistoryMessages(); JSONArray getMessages(); void setIdentities(JSONArray identities); void setUserAttributes(JSONObject userAttributes); long getMessageLengthBytes(); void incrementMessageLengthBytes(long bytes);  }