Android Open Source - mobile-connector-sdk-android Engage Local Event Store Test






From Project

Back to project page mobile-connector-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project mobile-connector-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.silverpop.engage.store;
//from   w w w  .ja va  2s .com
import android.test.AndroidTestCase;

import com.silverpop.engage.domain.EngageEvent;
import com.silverpop.engage.domain.UBF;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by jeremydyer on 5/19/14.
 */
public class EngageLocalEventStoreTest
        extends AndroidTestCase {

    private EngageLocalEventStore engageLocalEventStore;

    @Override
    protected void setUp() throws Exception{
        engageLocalEventStore = EngageLocalEventStore.get(getContext());
        engageLocalEventStore.open();

        //Delete all of the existing events.
        engageLocalEventStore.deleteAllUBFEvents();
    }

    public void testCountForEventType() {
        EngageEvent event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);
        engageLocalEventStore.saveUBFEvent(event);

        assertTrue(engageLocalEventStore.countForEventType(UBF.INSTALLED) == 1);
        assertTrue(engageLocalEventStore.countForEventType(UBF.SESSION_ENDED) == 0);
    }

    public void testDeleteAllUBFEvents() {
        EngageEvent event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);
        engageLocalEventStore.saveUBFEvent(event);

        assertEquals(1l, engageLocalEventStore.countForEventType(-1));
        engageLocalEventStore.deleteAllUBFEvents();
        assertEquals(0l, engageLocalEventStore.countForEventType(-1));
    }

    public void testFindEventByIdentifier() {
        EngageEvent event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);
        event = engageLocalEventStore.saveUBFEvent(event);

        EngageEvent foundEvent = engageLocalEventStore.findEventByIdentifier(event.getId());
        assertTrue(event.getEventJson().equals(foundEvent.getEventJson()));
        assertTrue(event.getEventStatus() == foundEvent.getEventStatus());
        assertEquals(event.getEventType(), foundEvent.getEventType());
    }

    public void testFindEngageEventWithStatus() {
        EngageEvent event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);
        event = engageLocalEventStore.saveUBFEvent(event);

        EngageEvent[] events = engageLocalEventStore.findEngageEventsWithStatus(event.getEventStatus());
        assertTrue(events != null && events.length == 1);

    }

    public void testFindUnpostedEvents() {
        EngageEvent event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);
        event = engageLocalEventStore.saveUBFEvent(event);

        event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.FAILED_POST);
        event.setEventType(UBF.INSTALLED);
        event = engageLocalEventStore.saveUBFEvent(event);

        EngageEvent[] foundEvents = engageLocalEventStore.findEngageEventsWithStatus(EngageEvent.FAILED_POST);
        assertTrue(foundEvents != null && foundEvents.length == 1);

        event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.FAILED_POST);
        event.setEventType(UBF.INSTALLED);
        event = engageLocalEventStore.saveUBFEvent(event);

        foundEvents = engageLocalEventStore.findEngageEventsWithStatus(EngageEvent.FAILED_POST);
        assertTrue(foundEvents != null && foundEvents.length == 2);
    }

    public void testDeleteExpiredLocalEvents() {
        EngageEvent event = new EngageEvent();

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DATE, -31);

        event.setEventDate(calendar.getTime());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);
        event = engageLocalEventStore.saveUBFEvent(event);

        assertTrue(engageLocalEventStore.findEventByIdentifier(event.getId()) != null);
        engageLocalEventStore.deleteExpiredLocalEvents();
        assertTrue(engageLocalEventStore.findEventByIdentifier(event.getId()) == null);
        assertTrue(engageLocalEventStore.countForEventType(EngageEvent.SUCCESSFULLY_POSTED) == 0);
    }

    public void testSaveUBFEvent() {
        EngageEvent event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);

        event = engageLocalEventStore.saveUBFEvent(event);
        assertTrue(event.getId() > -1);

        event = new EngageEvent();
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);

        event = engageLocalEventStore.saveUBFEvent(event);
        assertTrue(event.getId() > -1);

        event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);
        event.setEventType(UBF.INSTALLED);

        event = engageLocalEventStore.saveUBFEvent(event);
        assertTrue(event.getId() == -1);

        event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventType(UBF.INSTALLED);

        event = engageLocalEventStore.saveUBFEvent(event);
        assertTrue(event.getId() > -1);

        event = new EngageEvent();
        event.setEventDate(new Date());
        event.setEventJson(UBF.installed(getContext(), null).toJSONString());
        event.setEventStatus(EngageEvent.SUCCESSFULLY_POSTED);

        event = engageLocalEventStore.saveUBFEvent(event);
        assertTrue(event.getId() > -1);

        event = new EngageEvent();
        event = engageLocalEventStore.saveUBFEvent(event);
        assertTrue(event.getId() == -1);

        assertTrue(engageLocalEventStore.countForEventType(-1) == 4);
        engageLocalEventStore.deleteAllUBFEvents();
        assertTrue(engageLocalEventStore.countForEventType(-1) == 0);
    }

    @Override
    public void tearDown() throws Exception {
        engageLocalEventStore.close();
    }
}




Java Source Code List

com.silverpop.engage.EngageApplication.java
com.silverpop.engage.UBFManager.java
com.silverpop.engage.XMLAPIManager.java
com.silverpop.engage.augmentation.UBFAugmentationServiceImpl.java
com.silverpop.engage.augmentation.UBFAugmentationService.java
com.silverpop.engage.augmentation.plugin.UBFAddressAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFCoordinatesAugmentationPlugin.java
com.silverpop.engage.augmentation.plugin.UBFLocationNameAugmentationPlugin.java
com.silverpop.engage.config.EngageConfigManagerTests.java
com.silverpop.engage.config.EngageConfigManager.java
com.silverpop.engage.config.EngageConfigTest.java
com.silverpop.engage.config.EngageConfig.java
com.silverpop.engage.deeplinking.EngageDeepLinkManager.java
com.silverpop.engage.demo.engagetest.Application.java
com.silverpop.engage.demo.engagetest.EngageNotificationReceiver.java
com.silverpop.engage.demo.engagetest.MainActivity.java
com.silverpop.engage.demo.engagetest.PushReceiver.java
com.silverpop.engage.demo.engagetest.fragment.EngageConfigFragment.java
com.silverpop.engage.demo.engagetest.fragment.UBFAPIFragment.java
com.silverpop.engage.demo.engagetest.fragment.XMLAPIFragment.java
com.silverpop.engage.domain.EngageEvent.java
com.silverpop.engage.domain.JSONable.java
com.silverpop.engage.domain.UBFTests.java
com.silverpop.engage.domain.UBF.java
com.silverpop.engage.domain.XMLAPIEnum.java
com.silverpop.engage.domain.XMLAPITest.java
com.silverpop.engage.domain.XMLAPI.java
com.silverpop.engage.exception.XMLResponseParseException.java
com.silverpop.engage.location.manager.EngageLocationManager.java
com.silverpop.engage.location.manager.plugin.EngageLocationManagerDefault.java
com.silverpop.engage.location.receiver.EngageLocationReceiver.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverBase.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverGeocode.java
com.silverpop.engage.location.receiver.plugin.EngageLocationReceiverHardcodeTest.java
com.silverpop.engage.network.Credential.java
com.silverpop.engage.network.EngageClient.java
com.silverpop.engage.network.RequestCacheWrapper.java
com.silverpop.engage.network.UBFClient.java
com.silverpop.engage.network.XMLAPIClient.java
com.silverpop.engage.response.EngageResponseXMLTests.java
com.silverpop.engage.response.EngageResponseXML.java
com.silverpop.engage.response.XMLAPIResponseNode.java
com.silverpop.engage.store.EngageLocalEventStoreTest.java
com.silverpop.engage.store.EngageLocalEventStore.java
com.silverpop.engage.store.EngageSQLiteHelper.java
com.silverpop.engage.util.EngageExpirationParserTests.java
com.silverpop.engage.util.EngageExpirationParser.java
com.silverpop.engage.util.TimedAsyncTask.java