Skip to content

Commit

Permalink
Merged geo reinit and master and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislavin committed Mar 14, 2017
1 parent 1d4c72a commit 971554d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import com.google.android.gms.location.Geofence;

import org.infobip.mobile.messaging.Message;
import org.infobip.mobile.messaging.MobileMessagingCore;
import org.infobip.mobile.messaging.MobileMessagingProperty;
import org.infobip.mobile.messaging.api.support.Tuple;
import org.infobip.mobile.messaging.storage.MessageStore;
import org.infobip.mobile.messaging.storage.SQLiteMessageStore;
import org.infobip.mobile.messaging.tools.InfobipAndroidTestCase;
import org.infobip.mobile.messaging.util.DateTimeUtil;
import org.infobip.mobile.messaging.util.PreferenceHelper;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -23,7 +19,6 @@

public class GeoMonitoringTest extends InfobipAndroidTestCase {

private MessageStore messageStore;
private Long now;

@Override
Expand All @@ -32,12 +27,8 @@ protected void setUp() throws Exception {

now = System.currentTimeMillis();

PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
PreferenceHelper.saveString(context, MobileMessagingProperty.MESSAGE_STORE_CLASS, SQLiteMessageStore.class.getName());

Geofencing.getInstance(context);
geoStore = MobileMessagingCore.getInstance(context).getMessageStoreForGeo();
geoStore.deleteAll(context);
}

public void test_shouldCalculateRefreshDatesForGeoStartAndExpired() throws Exception {
Expand Down Expand Up @@ -137,30 +128,9 @@ public void test_shouldCalculateRefreshDateForGeoExpiredIfGeoIsMonitoredNow() th
assertEquals(millis15MinAfterNow, geofencesAndNextRefreshDate.getRight().getRight().getTime(), 3000);
}

private void saveGeoMessageToDb(String startTimeMillis, String expiryTimeMillis) throws JSONException {
Geo geo = new Geo(0.0, 0.0, new ArrayList<Area>() {{
add(new Area("SomeAreaId", "SomeAreaTitle", 0.0, 0.0, 10));
}}, null, new ArrayList<GeoEvent>(), expiryTimeMillis, startTimeMillis, "SomeCampaignId");

Message message = new Message(
"SomeMessageId",
"SomeTitle",
"SomeBody",
"SomeSound",
true,
"SomeIcon",
true,
"SomeCategory",
"SomeFrom",
now,
0,
null,
geo,
"SomeDestination",
Message.Status.UNKNOWN,
"SomeStatusMessage"
);
geoStore.save(context, message);
private void saveGeoMessageToDb(String startTimeMillis, String expiryTimeMillis) {
Geo geo = createGeo(0.0, 0.0, expiryTimeMillis, startTimeMillis, "SomeCampaignId",
createArea("SomeAreaId", "SomeAreaTitle", 0.0, 0.0, 10));
createMessage(context, "SomeMessageId", true, geo);
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.infobip.mobile.messaging.geo;

import org.infobip.mobile.messaging.Message;
import org.infobip.mobile.messaging.MobileMessaging;
import org.infobip.mobile.messaging.MobileMessagingCore;
import org.infobip.mobile.messaging.MobileMessagingProperty;
import org.infobip.mobile.messaging.gcm.MobileMessageHandler;
import org.infobip.mobile.messaging.platform.AndroidBroadcaster;
import org.infobip.mobile.messaging.storage.MessageStore;
import org.infobip.mobile.messaging.storage.SQLiteMessageStore;
import org.infobip.mobile.messaging.tools.InfobipAndroidTestCase;
import org.infobip.mobile.messaging.util.DateTimeUtil;
import org.infobip.mobile.messaging.util.PreferenceHelper;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -23,29 +21,21 @@

public class GeoStorageTest extends InfobipAndroidTestCase {

private MessageStore geoStore;
private MessageStore commonStore;
private MobileMessageHandler handler;
private long now;
private MessageStore commonStore;

@Override
protected void setUp() throws Exception {
super.setUp();

context = getInstrumentation().getContext();

handler = new MobileMessageHandler(new AndroidBroadcaster(context));
PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
PreferenceHelper.saveString(context, MobileMessagingProperty.MESSAGE_STORE_CLASS, SQLiteMessageStore.class.getName());
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.PUSH_REGISTRATION_ENABLED, true);
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.GEOFENCING_ACTIVATED, true);

handler = new MobileMessageHandler();
geoStore = MobileMessagingCore.getInstance(context).getMessageStoreForGeo();
geoStore.deleteAll(context);
commonStore = MobileMessagingCore.getInstance(context).getMessageStore();
commonStore.deleteAll(context);
now = System.currentTimeMillis();
handler = new MobileMessageHandler(broadcaster);
commonStore = MobileMessaging.getInstance(context).getMessageStore();
}

public void test_shouldSaveGeoMessagesToGeoStore() throws Exception {
Expand Down Expand Up @@ -126,31 +116,9 @@ public void test_shouldDeleteExpiredAreas() throws Exception {
assertEquals(nonExpiredMessageId, geoStore.findAll(context).get(0).getMessageId());
}

private void saveGeoMessageToDb(String messageId, String startTimeMillis, String expiryTimeMillis) throws JSONException {
Geo geo = new Geo(0.0, 0.0, new ArrayList<Area>() {{
add(new Area("SomeAreaId", "SomeAreaTitle", 0.0, 0.0, 10));
}}, null, new ArrayList<GeoEvent>(), expiryTimeMillis, startTimeMillis, "SomeCampaignId");

JSONObject internalData = new JSONObject(new JsonSerializer().serialize(geo));
Message message = new Message(
messageId,
"SomeTitle",
"SomeBody",
"SomeSound",
true,
"SomeIcon",
true,
"SomeCategory",
"SomeFrom",
now,
0,
internalData,
null,
geo,
"SomeDestination",
Message.Status.UNKNOWN,
"SomeStatusMessage"
);
geoStore.save(context, message);
private void saveGeoMessageToDb(String messageId, String startTimeMillis, String expiryTimeMillis) {
Geo geo = createGeo(0.0, 0.0, expiryTimeMillis, startTimeMillis, "SomeCampaignId",
createArea("SomeAreaId", "SomeAreaTitle", 0.0, 0.0, 10));
createMessage(context, messageId, true, geo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.infobip.mobile.messaging.geo.GeoReport;
import org.infobip.mobile.messaging.mobile.MobileApiResourceProvider;
import org.infobip.mobile.messaging.platform.Broadcaster;
import org.infobip.mobile.messaging.storage.MessageStore;
import org.infobip.mobile.messaging.util.PreferenceHelper;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
Expand All @@ -45,6 +46,7 @@ public class InfobipAndroidTestCase extends InstrumentationTestCase {
protected DebugServer debugServer;
protected MobileMessaging mobileMessaging;
protected MobileMessagingTestable mobileMessagingCore;
protected MessageStore geoStore;
protected DatabaseHelper databaseHelper;
protected SqliteDatabaseProvider databaseProvider;
protected Broadcaster broadcaster;
Expand Down Expand Up @@ -81,6 +83,7 @@ protected void setUp() throws Exception {

databaseHelper = MobileMessagingCore.getDatabaseHelper(context);
databaseProvider = MobileMessagingCore.getDatabaseProvider(context);
geoStore = MobileMessagingCore.getInstance(context).getMessageStoreForGeo();
}

private static Context mockContext(final Context realContext) {
Expand Down Expand Up @@ -225,6 +228,20 @@ protected static Geo createGeo(Double triggeringLatitude, Double triggeringLongi
return new Geo(triggeringLatitude, triggeringLongitude, null, null, null, campaignId, Arrays.asList(areas), new ArrayList<GeoEventSettings>());
}

/**
* Generates new Geo object
* @param triggeringLatitude latitude that event was triggered with
* @param triggeringLongitude longitude that event was triggered with
* @param expiryTime geo campaign expiration time
* @param startTime geo campaign start time
* @param campaignId campaign id
* @param areas array of areas to include
* @return new Geo object
*/
protected static Geo createGeo(Double triggeringLatitude, Double triggeringLongitude, String expiryTime, String startTime, String campaignId, Area... areas) {
return new Geo(triggeringLatitude, triggeringLongitude, null, expiryTime, startTime, campaignId, Arrays.asList(areas), new ArrayList<GeoEventSettings>());
}

/**
* Asserts that two objects are strictly the same using JSONAssert and JSON serialization
* @param expected expected object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void addUnreportedMessageIds(String... messageIDs) {
PreferenceHelper.appendToStringArray(context, MobileMessagingProperty.INFOBIP_UNREPORTED_MESSAGE_IDS, messageIDs);
}

void addSyncMessagesIds(String... messageIDs) {
public void addSyncMessagesIds(String... messageIDs) {
String[] timestampMessageIdPair = concatTimestampToMessageId(messageIDs);
PreferenceHelper.appendToStringArray(context, MobileMessagingProperty.INFOBIP_SYNC_MESSAGES_IDS, timestampMessageIdPair);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public enum MobileMessagingProperty {
UNREPORTED_GEO_EVENTS("org.ninfobip.mobile.messaging.infobip.UNREPORTED_GEO_EVENTS", new String[0]),
FINISHED_CAMPAIGN_IDS("org.infobip.mobile.messaging.infobip.FINISHED_CAMPAIGN_IDS", new HashSet<String>()),
SUSPENDED_CAMPAIGN_IDS("org.infobip.mobile.messaging.infobip.SUSPENDED_CAMPAIGN_IDS", new HashSet<String>()),
FINISHED_CAMPAIGN_IDS("org.infobip.mobile.messaging.infobip.FINISHED_CAMPAIGN_IDS", new String[0]),
SUSPENDED_CAMPAIGN_IDS("org.infobip.mobile.messaging.infobip.SUSPENDED_CAMPAIGN_IDS", new String[0]),
ALL_ACTIVE_GEO_AREAS_MONITORED("org.infobip.mobile.messaging.infobip.ALL_ACTIVE_GEO_AREAS_MONITORED", false),

GEOFENCING_ACTIVATED("org.infobip.mobile.messaging.infobip.GEOFENCING_ACTIVATED", false),
Expand Down

0 comments on commit 971554d

Please sign in to comment.