@Test public void testAddConsentState() 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); batch.addConsentState(null); batch.addConsentState(ConsentState.builder().build()); JSONObject consent = batch.optJSONObject("con"); assertNotNull(consent); batch.addConsentState( ConsentState.builder().addGDPRConsentState("foo purpose", GDPRConsent.builder(true) .timestamp(10L) .location("foo location") .hardwareId("foo hardware id") .document("foo document") .build()) .setCCPAConsentState(CCPAConsent.builder(true) .timestamp(20L) .location("bar location") .hardwareId("bar hardware id") .document("bar document") .build()) .build() ); JSONObject consentJSON = batch.optJSONObject(Constants.MessageKey.CONSENT_STATE); assertNotNull(consent); consent = consentJSON.optJSONObject(Constants.MessageKey.CONSENT_STATE_GDPR); assertNotNull(consent); consent = consent.getJSONObject("foo purpose"); assertNotNull(consent); assertEquals(true, consent.getBoolean(Constants.MessageKey.CONSENT_STATE_CONSENTED)); assertEquals((long)10, consent.getLong(Constants.MessageKey.CONSENT_STATE_TIMESTAMP)); assertEquals("foo location", consent.getString(Constants.MessageKey.CONSENT_STATE_LOCATION)); assertEquals("foo hardware id", consent.getString(Constants.MessageKey.CONSENT_STATE_HARDWARE_ID)); assertEquals("foo document", consent.getString(Constants.MessageKey.CONSENT_STATE_DOCUMENT)); consent = consentJSON.optJSONObject(Constants.MessageKey.CONSENT_STATE_CCPA); assertNotNull(consent); consent = consent.getJSONObject(Constants.MessageKey.CCPA_CONSENT_KEY); assertNotNull(consent); assertEquals(true, consent.getBoolean(Constants.MessageKey.CONSENT_STATE_CONSENTED)); assertEquals((long)20, consent.getLong(Constants.MessageKey.CONSENT_STATE_TIMESTAMP)); assertEquals("bar location", consent.getString(Constants.MessageKey.CONSENT_STATE_LOCATION)); assertEquals("bar hardware id", consent.getString(Constants.MessageKey.CONSENT_STATE_HARDWARE_ID)); assertEquals("bar document", consent.getString(Constants.MessageKey.CONSENT_STATE_DOCUMENT)); }
public void addConsentState(ConsentState consentState) { if (consentState != null) { try { JSONObject state = new JSONObject(); this.put(Constants.MessageKey.CONSENT_STATE, state); Map<String, GDPRConsent> gdprState = consentState.getGDPRConsentState(); if (gdprState != null) { JSONObject gdpr = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_GDPR, gdpr); for (Map.Entry<String, GDPRConsent> entry : gdprState.entrySet()) { ConsentInstance consent = entry.getValue(); if (consent != null) { addConsentStateJSON(gdpr, entry.getKey(), entry.getValue()); } } } CCPAConsent ccpaConsent = consentState.getCCPAConsentState(); if (ccpaConsent != null) { JSONObject ccpa = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_CCPA, ccpa); addConsentStateJSON(ccpa, Constants.MessageKey.CCPA_CONSENT_KEY, ccpaConsent); } } catch (JSONException ignored) { } } }
MessageBatch extends JSONObject { public void addConsentState(ConsentState consentState) { if (consentState != null) { try { JSONObject state = new JSONObject(); this.put(Constants.MessageKey.CONSENT_STATE, state); Map<String, GDPRConsent> gdprState = consentState.getGDPRConsentState(); if (gdprState != null) { JSONObject gdpr = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_GDPR, gdpr); for (Map.Entry<String, GDPRConsent> entry : gdprState.entrySet()) { ConsentInstance consent = entry.getValue(); if (consent != null) { addConsentStateJSON(gdpr, entry.getKey(), entry.getValue()); } } } CCPAConsent ccpaConsent = consentState.getCCPAConsentState(); if (ccpaConsent != null) { JSONObject ccpa = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_CCPA, ccpa); addConsentStateJSON(ccpa, Constants.MessageKey.CCPA_CONSENT_KEY, ccpaConsent); } } catch (JSONException ignored) { } } } }
MessageBatch extends JSONObject { public void addConsentState(ConsentState consentState) { if (consentState != null) { try { JSONObject state = new JSONObject(); this.put(Constants.MessageKey.CONSENT_STATE, state); Map<String, GDPRConsent> gdprState = consentState.getGDPRConsentState(); if (gdprState != null) { JSONObject gdpr = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_GDPR, gdpr); for (Map.Entry<String, GDPRConsent> entry : gdprState.entrySet()) { ConsentInstance consent = entry.getValue(); if (consent != null) { addConsentStateJSON(gdpr, entry.getKey(), entry.getValue()); } } } CCPAConsent ccpaConsent = consentState.getCCPAConsentState(); if (ccpaConsent != null) { JSONObject ccpa = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_CCPA, ccpa); addConsentStateJSON(ccpa, Constants.MessageKey.CCPA_CONSENT_KEY, ccpaConsent); } } catch (JSONException ignored) { } } } protected  MessageBatch(); }
MessageBatch extends JSONObject { public void addConsentState(ConsentState consentState) { if (consentState != null) { try { JSONObject state = new JSONObject(); this.put(Constants.MessageKey.CONSENT_STATE, state); Map<String, GDPRConsent> gdprState = consentState.getGDPRConsentState(); if (gdprState != null) { JSONObject gdpr = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_GDPR, gdpr); for (Map.Entry<String, GDPRConsent> entry : gdprState.entrySet()) { ConsentInstance consent = entry.getValue(); if (consent != null) { addConsentStateJSON(gdpr, entry.getKey(), entry.getValue()); } } } CCPAConsent ccpaConsent = consentState.getCCPAConsentState(); if (ccpaConsent != null) { JSONObject ccpa = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_CCPA, ccpa); addConsentStateJSON(ccpa, Constants.MessageKey.CCPA_CONSENT_KEY, ccpaConsent); } } catch (JSONException ignored) { } } } 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 void addConsentState(ConsentState consentState) { if (consentState != null) { try { JSONObject state = new JSONObject(); this.put(Constants.MessageKey.CONSENT_STATE, state); Map<String, GDPRConsent> gdprState = consentState.getGDPRConsentState(); if (gdprState != null) { JSONObject gdpr = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_GDPR, gdpr); for (Map.Entry<String, GDPRConsent> entry : gdprState.entrySet()) { ConsentInstance consent = entry.getValue(); if (consent != null) { addConsentStateJSON(gdpr, entry.getKey(), entry.getValue()); } } } CCPAConsent ccpaConsent = consentState.getCCPAConsentState(); if (ccpaConsent != null) { JSONObject ccpa = new JSONObject(); state.put(Constants.MessageKey.CONSENT_STATE_CCPA, ccpa); addConsentStateJSON(ccpa, Constants.MessageKey.CCPA_CONSENT_KEY, ccpaConsent); } } catch (JSONException ignored) { } } } 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);  }