urbanairship-core/src/test/java/com/urbanairship/push/ChannelRegistrationPayloadTest.java
@Test
    public void testAsJsonFullPayloadAnalyticsEnabled() throws JSONException {
        payload = new ChannelRegistrationPayload.Builder()
                .setOptIn(testOptIn)
                .setBackgroundEnabled(testBackgroundEnabled)
                .setAlias(testAlias)
                .setDeviceType(testDeviceType)
                .setPushAddress(testPushAddress)
                .setTags(testSetTags, testTags)
                .setUserId(testUserId)
                .setApid(testApid)
                .setLanguage(testLanguage)
                .setTimezone(testTimezone)
                .setCountry(testCountry)
                .build();

        JsonMap body = payload.toJsonValue().getMap();

        // Top level fields
        assertTrue("Channel should be present in payload.", body.containsKey(ChannelRegistrationPayload.CHANNEL_KEY));
        assertTrue("Identity hints should be present in payload.", body.containsKey(ChannelRegistrationPayload.IDENTITY_HINTS_KEY));

        JsonMap identityHints = body.opt(ChannelRegistrationPayload.IDENTITY_HINTS_KEY).getMap();
        JsonMap channel = body.opt(ChannelRegistrationPayload.CHANNEL_KEY).getMap();

        // Identity items
        assertTrue("User ID should be present in payload.", identityHints.containsKey(ChannelRegistrationPayload.USER_ID_KEY));
        assertEquals("User ID should be fakeUserId.", identityHints.get(ChannelRegistrationPayload.USER_ID_KEY).getString(), testUserId);

        assertTrue("APID should be present in payload.", identityHints.containsKey(ChannelRegistrationPayload.APID_KEY));
        assertEquals("APID should match.", identityHints.get(ChannelRegistrationPayload.APID_KEY).getString(), testApid);

        // Channel specific items
        assertTrue("Device type should be present in payload.", channel.containsKey(ChannelRegistrationPayload.DEVICE_TYPE_KEY));
        assertEquals("Device type should be android.", channel.get(ChannelRegistrationPayload.DEVICE_TYPE_KEY).getString(), testDeviceType);
        assertTrue("Opt in should be present in payload.", channel.containsKey(ChannelRegistrationPayload.OPT_IN_KEY));
        assertEquals("Opt in should be true.", channel.get(ChannelRegistrationPayload.OPT_IN_KEY).getBoolean(!testOptIn), testOptIn);
        assertTrue("Background flag should be present in payload.", channel.containsKey(ChannelRegistrationPayload.BACKGROUND_ENABLED_KEY));
        assertEquals("Background flag should be true.", channel.get(ChannelRegistrationPayload.BACKGROUND_ENABLED_KEY).getBoolean(!testBackgroundEnabled), testBackgroundEnabled);
        assertTrue("Push address should be present in payload.", channel.containsKey(ChannelRegistrationPayload.PUSH_ADDRESS_KEY));
        assertEquals("Push address should be gcmRegistrationId.", channel.get(ChannelRegistrationPayload.PUSH_ADDRESS_KEY).getString(), testPushAddress);
        assertTrue("Alias should be present in payload", channel.containsKey(ChannelRegistrationPayload.ALIAS_KEY));
        assertEquals("Alias should be fakeAlias.", channel.get(ChannelRegistrationPayload.ALIAS_KEY).getString(), testAlias);
        assertTrue("Set tags should be present in payload", channel.containsKey(ChannelRegistrationPayload.SET_TAGS_KEY));
        assertEquals("Set tags should be true.", channel.get(ChannelRegistrationPayload.SET_TAGS_KEY).getBoolean(!testSetTags), testSetTags);
        assertTrue("Tags should be present in payload", channel.containsKey(ChannelRegistrationPayload.TAGS_KEY));

        assertTrue("Timezone should be in payload", channel.containsKey(ChannelRegistrationPayload.TIMEZONE_KEY));
        assertTrue("Language should be in payload", channel.containsKey(ChannelRegistrationPayload.LANGUAGE_KEY));
        assertTrue("Country should be in payload", channel.containsKey(ChannelRegistrationPayload.COUNTRY_KEY));

        // Check the tags within channel item
        JsonList tags = channel.get(ChannelRegistrationPayload.TAGS_KEY).getList();
        assertEquals("Tags size should be 2.", tags.size(), testTags.size());
        assertTrue("Tags should contain tagOne.", testTags.contains(tags.get(0).getString()));
        assertTrue("Tags should contain tagTwo.", testTags.contains(tags.get(1).getString()));
    }
/**
     * Test that the json has the full expected payload when analytics is enabled.
     */
Test that the json has the full expected payload when analytics is enabled.
Test that the json has the full expected payload when analytics is enabled .
@Test
    public void testAsJsonFullPayloadAnalyticsEnabled() throws JSONException {
        payload = new ChannelRegistrationPayload.Builder()
                .setOptIn(testOptIn)
                .setBackgroundEnabled(testBackgroundEnabled)
                .setAlias(testAlias)
                .setDeviceType(testDeviceType)
                .setPushAddress(testPushAddress)
                .setTags(testSetTags, testTags)
                .setUserId(testUserId)
                .setApid(testApid)
                .setLanguage(testLanguage)
                .setTimezone(testTimezone)
                .setCountry(testCountry)
                .build();
        JsonMap body = payload.toJsonValue().getMap();
        assertTrue("Channel should be present in payload.", body.containsKey(ChannelRegistrationPayload.CHANNEL_KEY));
        assertTrue("Identity hints should be present in payload.", body.containsKey(ChannelRegistrationPayload.IDENTITY_HINTS_KEY));
        JsonMap identityHints = body.opt(ChannelRegistrationPayload.IDENTITY_HINTS_KEY).getMap();
        JsonMap channel = body.opt(ChannelRegistrationPayload.CHANNEL_KEY).getMap();
        assertTrue("User ID should be present in payload.", identityHints.containsKey(ChannelRegistrationPayload.USER_ID_KEY));
        assertEquals("User ID should be fakeUserId.", identityHints.get(ChannelRegistrationPayload.USER_ID_KEY).getString(), testUserId);
        assertTrue("APID should be present in payload.", identityHints.containsKey(ChannelRegistrationPayload.APID_KEY));
        assertEquals("APID should match.", identityHints.get(ChannelRegistrationPayload.APID_KEY).getString(), testApid);
        assertTrue("Device type should be present in payload.", channel.containsKey(ChannelRegistrationPayload.DEVICE_TYPE_KEY));
        assertEquals("Device type should be android.", channel.get(ChannelRegistrationPayload.DEVICE_TYPE_KEY).getString(), testDeviceType);
        assertTrue("Opt in should be present in payload.", channel.containsKey(ChannelRegistrationPayload.OPT_IN_KEY));
        assertEquals("Opt in should be true.", channel.get(ChannelRegistrationPayload.OPT_IN_KEY).getBoolean(!testOptIn), testOptIn);
        assertTrue("Background flag should be present in payload.", channel.containsKey(ChannelRegistrationPayload.BACKGROUND_ENABLED_KEY));
        assertEquals("Background flag should be true.", channel.get(ChannelRegistrationPayload.BACKGROUND_ENABLED_KEY).getBoolean(!testBackgroundEnabled), testBackgroundEnabled);
        assertTrue("Push address should be present in payload.", channel.containsKey(ChannelRegistrationPayload.PUSH_ADDRESS_KEY));
        assertEquals("Push address should be gcmRegistrationId.", channel.get(ChannelRegistrationPayload.PUSH_ADDRESS_KEY).getString(), testPushAddress);
        assertTrue("Alias should be present in payload", channel.containsKey(ChannelRegistrationPayload.ALIAS_KEY));
        assertEquals("Alias should be fakeAlias.", channel.get(ChannelRegistrationPayload.ALIAS_KEY).getString(), testAlias);
        assertTrue("Set tags should be present in payload", channel.containsKey(ChannelRegistrationPayload.SET_TAGS_KEY));
        assertEquals("Set tags should be true.", channel.get(ChannelRegistrationPayload.SET_TAGS_KEY).getBoolean(!testSetTags), testSetTags);
        assertTrue("Tags should be present in payload", channel.containsKey(ChannelRegistrationPayload.TAGS_KEY));
        assertTrue("Timezone should be in payload", channel.containsKey(ChannelRegistrationPayload.TIMEZONE_KEY));
        assertTrue("Language should be in payload", channel.containsKey(ChannelRegistrationPayload.LANGUAGE_KEY));
        assertTrue("Country should be in payload", channel.containsKey(ChannelRegistrationPayload.COUNTRY_KEY));
        JsonList tags = channel.get(ChannelRegistrationPayload.TAGS_KEY).getList();
        assertEquals("Tags size should be 2.", tags.size(), testTags.size());
        assertTrue("Tags should contain tagOne.", testTags.contains(tags.get(0).getString()));
        assertTrue("Tags should contain tagTwo.", testTags.contains(tags.get(1).getString()));
    }
@ Test public void testAsJsonFullPayloadAnalyticsEnabled ( ) throws JSONException { payload = new ChannelRegistrationPayload . Builder ( ) . setOptIn ( testOptIn ) . setBackgroundEnabled ( testBackgroundEnabled ) . setAlias ( testAlias ) . setDeviceType ( testDeviceType ) . setPushAddress ( testPushAddress ) . setTags ( testSetTags , testTags ) . setUserId ( testUserId ) . setApid ( testApid ) . setLanguage ( testLanguage ) . setTimezone ( testTimezone ) . setCountry ( testCountry ) . build ( ) ; JsonMap body = payload . toJsonValue ( ) . getMap ( ) ; assertTrue ( "Channel should be present in payload." , body . containsKey ( ChannelRegistrationPayload . CHANNEL_KEY ) ) ; assertTrue ( "Identity hints should be present in payload." , body . containsKey ( ChannelRegistrationPayload . IDENTITY_HINTS_KEY ) ) ; JsonMap identityHints = body . opt ( ChannelRegistrationPayload . IDENTITY_HINTS_KEY ) . getMap ( ) ; JsonMap channel = body . opt ( ChannelRegistrationPayload . CHANNEL_KEY ) . getMap ( ) ; assertTrue ( "User ID should be present in payload." , identityHints . containsKey ( ChannelRegistrationPayload . USER_ID_KEY ) ) ; assertEquals ( "User ID should be fakeUserId." , identityHints . get ( ChannelRegistrationPayload . USER_ID_KEY ) . getString ( ) , testUserId ) ; assertTrue ( "APID should be present in payload." , identityHints . containsKey ( ChannelRegistrationPayload . APID_KEY ) ) ; assertEquals ( "APID should match." , identityHints . get ( ChannelRegistrationPayload . APID_KEY ) . getString ( ) , testApid ) ; assertTrue ( "Device type should be present in payload." , channel . containsKey ( ChannelRegistrationPayload . DEVICE_TYPE_KEY ) ) ; assertEquals ( "Device type should be android." , channel . get ( ChannelRegistrationPayload . DEVICE_TYPE_KEY ) . getString ( ) , testDeviceType ) ; assertTrue ( "Opt in should be present in payload." , channel . containsKey ( ChannelRegistrationPayload . OPT_IN_KEY ) ) ; assertEquals ( "Opt in should be true." , channel . get ( ChannelRegistrationPayload . OPT_IN_KEY ) . getBoolean ( ! testOptIn ) , testOptIn ) ; assertTrue ( "Background flag should be present in payload." , channel . containsKey ( ChannelRegistrationPayload . BACKGROUND_ENABLED_KEY ) ) ; assertEquals ( "Background flag should be true." , channel . get ( ChannelRegistrationPayload . BACKGROUND_ENABLED_KEY ) . getBoolean ( ! testBackgroundEnabled ) , testBackgroundEnabled ) ; assertTrue ( "Push address should be present in payload." , channel . containsKey ( ChannelRegistrationPayload . PUSH_ADDRESS_KEY ) ) ; assertEquals ( "Push address should be gcmRegistrationId." , channel . get ( ChannelRegistrationPayload . PUSH_ADDRESS_KEY ) . getString ( ) , testPushAddress ) ; assertTrue ( "Alias should be present in payload" , channel . containsKey ( ChannelRegistrationPayload . ALIAS_KEY ) ) ; assertEquals ( "Alias should be fakeAlias." , channel . get ( ChannelRegistrationPayload . ALIAS_KEY ) . getString ( ) , testAlias ) ; assertTrue ( "Set tags should be present in payload" , channel . containsKey ( ChannelRegistrationPayload . SET_TAGS_KEY ) ) ; assertEquals ( "Set tags should be true." , channel . get ( ChannelRegistrationPayload . SET_TAGS_KEY ) . getBoolean ( ! testSetTags ) , testSetTags ) ; assertTrue ( "Tags should be present in payload" , channel . containsKey ( ChannelRegistrationPayload . TAGS_KEY ) ) ; assertTrue ( "Timezone should be in payload" , channel . containsKey ( ChannelRegistrationPayload . TIMEZONE_KEY ) ) ; assertTrue ( "Language should be in payload" , channel . containsKey ( ChannelRegistrationPayload . LANGUAGE_KEY ) ) ; assertTrue ( "Country should be in payload" , channel . containsKey ( ChannelRegistrationPayload . COUNTRY_KEY ) ) ; JsonList tags = channel . get ( ChannelRegistrationPayload . TAGS_KEY ) . getList ( ) ; assertEquals ( "Tags size should be 2." , tags . size ( ) , testTags . size ( ) ) ; assertTrue ( "Tags should contain tagOne." , testTags . contains ( tags . get ( 0 ) . getString ( ) ) ) ; assertTrue ( "Tags should contain tagTwo." , testTags . contains ( tags . get ( 1 ) . getString ( ) ) ) ; }
Test that the json has the full expected payload when analytics is enabled.
Test that the json has the full expected payload when analytics is enabled .
// Top level fields // Identity items // Channel specific items // Check the tags within channel item