@josuelmm/cordova-background-geolocation 4.2.2 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/.npmignore +11 -0
  2. package/CHANGELOG.md +213 -0
  3. package/HISTORY.md +73 -0
  4. package/README.md +45 -74
  5. package/android/CDVBackgroundGeolocation/src/main/java/com/marianhello/bgloc/cordova/ConfigMapper.java +24 -0
  6. package/android/CDVBackgroundGeolocation/src/main/java/com/tenforwardconsulting/bgloc/cordova/BackgroundGeolocationPlugin.java +61 -1
  7. package/android/common/src/main/AndroidManifest.xml +1 -1
  8. package/android/common/src/main/java/com/marianhello/bgloc/BootCompletedReceiver.java +6 -3
  9. package/android/common/src/main/java/com/marianhello/bgloc/Config.java +65 -1
  10. package/android/common/src/main/java/com/marianhello/bgloc/PostLocationTask.java +1 -1
  11. package/android/common/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java +94 -0
  12. package/android/common/src/main/java/com/marianhello/bgloc/data/ConfigJsonMapper.java +205 -0
  13. package/android/common/src/main/java/com/marianhello/bgloc/data/LocationTemplateFactory.java +6 -0
  14. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationContract.java +5 -1
  15. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteConfigurationDAO.java +32 -1
  16. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationContract.java +12 -2
  17. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java +33 -2
  18. package/android/common/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java +15 -1
  19. package/android/common/src/main/java/com/marianhello/bgloc/provider/DistanceFilterLocationProvider.java +23 -8
  20. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceImpl.java +246 -21
  21. package/android/common/src/main/java/com/marianhello/bgloc/service/LocationServiceProxy.java +5 -2
  22. package/android/common/src/main/java/com/marianhello/bgloc/sync/BatchManager.java +46 -13
  23. package/ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m +23 -1
  24. package/ios/common/BackgroundGeolocation/MAURBackgroundGeolocationFacade.m +111 -5
  25. package/ios/common/BackgroundGeolocation/MAURBackgroundSync.m +20 -0
  26. package/ios/common/BackgroundGeolocation/MAURConfig.h +2 -0
  27. package/ios/common/BackgroundGeolocation/MAURConfig.m +16 -2
  28. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.h +3 -0
  29. package/ios/common/BackgroundGeolocation/MAURConfigurationContract.m +3 -1
  30. package/ios/common/BackgroundGeolocation/MAURGeolocationOpenHelper.m +15 -1
  31. package/ios/common/BackgroundGeolocation/MAURLocation.h +12 -0
  32. package/ios/common/BackgroundGeolocation/MAURLocation.m +33 -4
  33. package/ios/common/BackgroundGeolocation/MAURLocationContract.h +4 -0
  34. package/ios/common/BackgroundGeolocation/MAURLocationContract.m +5 -1
  35. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.h +9 -0
  36. package/ios/common/BackgroundGeolocation/MAURPostLocationTask.m +59 -1
  37. package/ios/common/BackgroundGeolocation/MAURSQLiteConfigurationDAO.m +54 -4
  38. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.h +12 -0
  39. package/ios/common/BackgroundGeolocation/MAURSQLiteLocationDAO.m +125 -5
  40. package/package.json +36 -1
  41. package/plugin.xml +3 -2
  42. package/www/BackgroundGeolocation.d.ts +114 -3
  43. package/www/BackgroundGeolocation.js +11 -4
  44. package/CLAUDE.md +0 -56
  45. package/android/CDVBackgroundGeolocation/src/test/java/com/marianhello/ConfigMapperTest.java +0 -220
  46. package/android/common/src/androidTest/java/com/marianhello/bgloc/BackgroundGeolocationFacadeTest.java +0 -45
  47. package/android/common/src/androidTest/java/com/marianhello/bgloc/BatchManagerTest.java +0 -570
  48. package/android/common/src/androidTest/java/com/marianhello/bgloc/ConfigTest.java +0 -76
  49. package/android/common/src/androidTest/java/com/marianhello/bgloc/ContentProviderLocationDAOTest.java +0 -437
  50. package/android/common/src/androidTest/java/com/marianhello/bgloc/DBLogReaderTest.java +0 -95
  51. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationContentProviderTest.java +0 -159
  52. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceProxyTest.java +0 -161
  53. package/android/common/src/androidTest/java/com/marianhello/bgloc/LocationServiceTest.java +0 -247
  54. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteConfigurationDAOTest.java +0 -200
  55. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOTest.java +0 -457
  56. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteLocationDAOThreadTest.java +0 -96
  57. package/android/common/src/androidTest/java/com/marianhello/bgloc/SQLiteOpenHelperTest.java +0 -225
  58. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestPluginDelegate.java +0 -46
  59. package/android/common/src/androidTest/java/com/marianhello/bgloc/TestResourceResolver.java +0 -14
  60. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/MockLocationProvider.java +0 -50
  61. package/android/common/src/androidTest/java/com/marianhello/bgloc/provider/TestLocationProviderFactory.java +0 -17
  62. package/android/common/src/androidTest/java/com/marianhello/bgloc/sqlite/SQLiteOpenHelper10.java +0 -92
  63. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/LocationProviderTestCase.java +0 -107
  64. package/android/common/src/androidTest/java/com/marianhello/bgloc/test/TestConstants.java +0 -5
  65. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ArrayListLocationTemplateTest.java +0 -82
  66. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/BackgroundLocationTest.java +0 -128
  67. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/ConfigTest.java +0 -191
  68. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/DBLogReaderTest.java +0 -37
  69. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HashMapLocationTemplateTest.java +0 -216
  70. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/HttpPostServiceTest.java +0 -223
  71. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/LocationTemplateFactoryTest.java +0 -50
  72. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/PostLocationTaskTest.java +0 -180
  73. package/android/common/src/test/java/com/marianhello/backgroundgeolocation/TestHelper.java +0 -16
  74. package/ios/common/BackgroundGeolocationTests/Info.plist +0 -24
  75. package/ios/common/BackgroundGeolocationTests/MAURBackgroundLocationTest.m +0 -185
  76. package/ios/common/BackgroundGeolocationTests/MAURConfigTest.m +0 -161
  77. package/ios/common/BackgroundGeolocationTests/MAURGeolocationOpenHelperTest.m +0 -102
  78. package/ios/common/BackgroundGeolocationTests/MAURLocationTest.m +0 -216
  79. package/ios/common/BackgroundGeolocationTests/MAURLocationUploaderTest.m +0 -55
  80. package/ios/common/BackgroundGeolocationTests/MAURLogReaderTest.m +0 -43
  81. package/ios/common/BackgroundGeolocationTests/MAURSQLiteConfigurationDAOTest.m +0 -102
  82. package/ios/common/BackgroundGeolocationTests/MAURSQLiteHelperTest.m +0 -41
  83. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOTests.m +0 -240
  84. package/ios/common/BackgroundGeolocationTests/MAURSQLiteLocationDAOThreadTest.m +0 -84
  85. package/ios/common/BackgroundGeolocationTests/MAURSQLiteOpenHelperTest.m +0 -144
  86. package/ios/common/scripts/xcode-refactor.js +0 -184
@@ -1,128 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import android.os.Build;
4
- import androidx.test.filters.SmallTest;
5
-
6
- import com.marianhello.bgloc.data.BackgroundLocation;
7
-
8
- import junit.framework.Assert;
9
-
10
- import org.junit.Test;
11
-
12
- import java.lang.reflect.Field;
13
- import java.lang.reflect.Modifier;
14
-
15
- /**
16
- * Created by finch on 10/08/16.
17
- */
18
- @SmallTest
19
- public class BackgroundLocationTest {
20
-
21
- static void setSDKVersion(Object newValue) {
22
-
23
- Field modifiersField = null;
24
- try {
25
- Field field = Build.VERSION.class.getField("SDK_INT");
26
-
27
- field.setAccessible(true);
28
-
29
- modifiersField = Field.class.getDeclaredField("modifiers");
30
- modifiersField.setAccessible(true);
31
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
32
-
33
- field.set(null, newValue);
34
- } catch (Exception e) {
35
- e.printStackTrace();
36
- }
37
- }
38
-
39
- @Test public void testHasMockShouldBeFalse() {
40
- BackgroundLocation l = new BackgroundLocation();
41
- Assert.assertFalse(l.hasIsFromMockProvider());
42
- Assert.assertFalse(l.hasMockLocationsEnabled());
43
- Assert.assertEquals(0x0, l.getMockFlags());
44
- }
45
-
46
- @Test public void testHasMockShouldBeTrue() {
47
- BackgroundLocation l = new BackgroundLocation();
48
- l.setMockLocationsEnabled(true);
49
- l.setIsFromMockProvider(true);
50
- Assert.assertTrue(l.hasMockLocationsEnabled());
51
- Assert.assertTrue(l.areMockLocationsEnabled());
52
- Assert.assertEquals(0xF, l.getMockFlags());
53
- }
54
-
55
- @Test public void testIsFromMockProviderShouldBeTrue() {
56
- BackgroundLocation l = new BackgroundLocation();
57
- l.setIsFromMockProvider(true);
58
- Assert.assertTrue(l.hasIsFromMockProvider());
59
- Assert.assertTrue(l.isFromMockProvider());
60
- Assert.assertEquals(0x3, l.getMockFlags());
61
- }
62
-
63
- @Test public void testIsFromMockProviderShouldBeFalse() {
64
- BackgroundLocation l = new BackgroundLocation();
65
- l.setIsFromMockProvider(false);
66
- Assert.assertTrue(l.hasIsFromMockProvider());
67
- Assert.assertFalse(l.isFromMockProvider());
68
- Assert.assertEquals(0x2, l.getMockFlags());
69
- }
70
-
71
- @Test public void testAreMockLocationsEnabledShouldBeTrue() {
72
- BackgroundLocation l = new BackgroundLocation();
73
- l.setMockLocationsEnabled(true);
74
- Assert.assertTrue(l.hasMockLocationsEnabled());
75
- Assert.assertTrue(l.areMockLocationsEnabled());
76
- Assert.assertEquals(0xC, l.getMockFlags());
77
- }
78
-
79
- @Test public void testAreMockLocationsEnabledShouldBeFalse() {
80
- BackgroundLocation l = new BackgroundLocation();
81
- l.setMockLocationsEnabled(false);
82
- Assert.assertTrue(l.hasMockLocationsEnabled());
83
- Assert.assertFalse(l.areMockLocationsEnabled());
84
- Assert.assertEquals(0x8, l.getMockFlags());
85
- }
86
-
87
- @Test
88
- public void olderLocationShouldBeWorse() {
89
- setSDKVersion(17);
90
-
91
- BackgroundLocation netLocation = new BackgroundLocation();
92
- netLocation.setProvider("network");
93
- netLocation.setLatitude(49);
94
- netLocation.setLongitude(5);
95
- netLocation.setAccuracy(38);
96
- netLocation.setElapsedRealtimeNanos(1470776557324L * 1000000L);
97
-
98
- BackgroundLocation gpsLocation = new BackgroundLocation();
99
- gpsLocation.setProvider("gps");
100
- gpsLocation.setLatitude(49);
101
- gpsLocation.setLongitude(5);
102
- gpsLocation.setAccuracy(5);
103
- gpsLocation.setElapsedRealtimeNanos(1470773246000L * 1000000L);
104
-
105
- Assert.assertFalse(gpsLocation.isBetterLocationThan(netLocation));
106
- }
107
-
108
- @Test
109
- public void newerLocationShouldBeBetter() {
110
- setSDKVersion(17);
111
-
112
- BackgroundLocation netLocation = new BackgroundLocation();
113
- netLocation.setProvider("network");
114
- netLocation.setLatitude(49);
115
- netLocation.setLongitude(5);
116
- netLocation.setAccuracy(38);
117
- netLocation.setElapsedRealtimeNanos(0);
118
-
119
- BackgroundLocation gpsLocation = new BackgroundLocation();
120
- gpsLocation.setProvider("gps");
121
- gpsLocation.setLatitude(49);
122
- gpsLocation.setLongitude(5);
123
- gpsLocation.setAccuracy(105);
124
- gpsLocation.setElapsedRealtimeNanos(2000000000L * 60 * 2);
125
-
126
- Assert.assertFalse(netLocation.isBetterLocationThan(gpsLocation));
127
- }
128
- }
@@ -1,191 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import androidx.test.filters.SmallTest;
4
-
5
- import com.marianhello.bgloc.Config;
6
- import com.marianhello.bgloc.data.ArrayListLocationTemplate;
7
- import com.marianhello.bgloc.data.HashMapLocationTemplate;
8
- import com.marianhello.bgloc.data.LocationTemplate;
9
- import com.marianhello.bgloc.data.LocationTemplateFactory;
10
-
11
- import junit.framework.Assert;
12
-
13
- import org.junit.Test;
14
-
15
- import java.util.ArrayList;
16
- import java.util.HashMap;
17
-
18
- /**
19
- * Created by finch on 29.11.2017.
20
- */
21
-
22
- @SmallTest
23
- public class ConfigTest {
24
- @Test
25
- public void testEmptyConfig() {
26
- Config config = new Config();
27
-
28
- Assert.assertFalse(config.hasStationaryRadius());
29
- Assert.assertFalse(config.hasDistanceFilter());
30
- Assert.assertFalse(config.hasDesiredAccuracy());
31
- Assert.assertFalse(config.hasDebug());
32
- Assert.assertFalse(config.hasNotificationTitle());
33
- Assert.assertFalse(config.hasNotificationText());
34
- Assert.assertFalse(config.hasStopOnTerminate());
35
- Assert.assertFalse(config.hasStartOnBoot());
36
- Assert.assertFalse(config.hasLocationProvider());
37
- Assert.assertFalse(config.hasInterval());
38
- Assert.assertFalse(config.hasFastestInterval());
39
- Assert.assertFalse(config.hasActivitiesInterval());
40
- Assert.assertFalse(config.hasNotificationIconColor());
41
- Assert.assertFalse(config.hasLargeNotificationIcon());
42
- Assert.assertFalse(config.hasSmallNotificationIcon());
43
- Assert.assertFalse(config.hasStartForeground());
44
- Assert.assertFalse(config.hasStopOnStillActivity());
45
- Assert.assertFalse(config.hasUrl());
46
- Assert.assertFalse(config.hasSyncUrl());
47
- Assert.assertFalse(config.hasSyncThreshold());
48
- Assert.assertFalse(config.hasHttpHeaders());
49
- Assert.assertFalse(config.hasMaxLocations());
50
- Assert.assertFalse(config.hasTemplate());
51
- }
52
-
53
- @Test
54
- public void testDefaultConfig() {
55
- Config config = Config.getDefault();
56
-
57
- Assert.assertEquals(config.getStationaryRadius(), 50f);
58
- Assert.assertEquals(config.getDistanceFilter().intValue(), 500);
59
- Assert.assertEquals(config.getDesiredAccuracy().intValue(), 100);
60
- Assert.assertFalse(config.isDebugging());
61
- Assert.assertEquals(config.getNotificationTitle(), "Background tracking");
62
- Assert.assertEquals(config.getNotificationText(), "ENABLED");
63
- Assert.assertTrue(config.getStopOnTerminate());
64
- Assert.assertFalse(config.getStartOnBoot());
65
- Assert.assertEquals(config.getLocationProvider().intValue(), 0);
66
- Assert.assertEquals(config.getInterval().intValue(), 600000);
67
- Assert.assertEquals(config.getFastestInterval().intValue(), 120000);
68
- Assert.assertEquals(config.getActivitiesInterval().intValue(), 10000);
69
- Assert.assertEquals(config.getNotificationIconColor(), "");
70
- Assert.assertEquals(config.getLargeNotificationIcon(), "");
71
- Assert.assertEquals(config.getSmallNotificationIcon(), "");
72
- Assert.assertTrue(config.getStartForeground());
73
- Assert.assertTrue(config.getStopOnStillActivity());
74
- Assert.assertEquals(config.getUrl(), "");
75
- Assert.assertEquals(config.getSyncUrl(), "");
76
- Assert.assertEquals(config.getSyncThreshold().intValue(), 100);
77
- Assert.assertTrue(config.getHttpHeaders().isEmpty());
78
- Assert.assertEquals(config.getTemplate(), LocationTemplateFactory.getDefault());
79
- Assert.assertEquals(config.getMaxLocations().intValue(), 10000);
80
- }
81
-
82
- @Test
83
- public void testMergeConfig() {
84
- Config config = new Config();
85
-
86
- config.setSyncThreshold(10);
87
- config.setMaxLocations(1000);
88
- config.setDesiredAccuracy(5);
89
-
90
- Config newConfig = new Config();
91
- newConfig.setSyncThreshold(100);
92
- newConfig.setDesiredAccuracy(500);
93
-
94
- Config merged = Config.merge(config, newConfig);
95
-
96
- Assert.assertEquals(merged.getSyncThreshold().intValue(), 100);
97
- Assert.assertEquals(merged.getMaxLocations().intValue(), 1000);
98
- Assert.assertEquals(merged.getDesiredAccuracy().intValue(), 500);
99
-
100
- Assert.assertEquals(config.getSyncThreshold().intValue(), 10);
101
- Assert.assertEquals(config.getMaxLocations().intValue(), 1000);
102
- Assert.assertEquals(config.getDesiredAccuracy().intValue(), 5);
103
-
104
- Assert.assertNotSame(config, merged);
105
- Assert.assertNotSame(config.getSyncThreshold(), merged.getSyncThreshold());
106
- Assert.assertNotSame(config.getDesiredAccuracy(), merged.getDesiredAccuracy());
107
- }
108
-
109
- @Test
110
- public void testMergeHttpHeaders() {
111
- HashMap httpHeaders = new HashMap<String, String>();
112
- httpHeaders.put("key", "value");
113
-
114
- Config config = new Config();
115
- config.setHttpHeaders(httpHeaders);
116
-
117
- Config merged = Config.merge(config, new Config());
118
- httpHeaders.put("key", "othervalue");
119
-
120
- Assert.assertNotSame(config, merged);
121
- Assert.assertNotSame(config.getHttpHeaders(), merged.getHttpHeaders());
122
- Assert.assertEquals("value", merged.getHttpHeaders().get("key"));
123
- Assert.assertEquals("othervalue", config.getHttpHeaders().get("key"));
124
- }
125
-
126
- @Test
127
- public void testMergeHashTemplate() {
128
- HashMap map = new HashMap();
129
- map.put("key", "value");
130
- LocationTemplate tpl = new HashMapLocationTemplate(map);
131
-
132
- Config config = new Config();
133
- config.setTemplate(tpl);
134
-
135
- Config merged = Config.merge(config, new Config());
136
- map.put("key", "othervalue");
137
-
138
- Assert.assertNotSame(config, merged);
139
- Assert.assertNotSame(config.getTemplate(), merged.getTemplate());
140
- Assert.assertEquals("value", ((HashMapLocationTemplate)merged.getTemplate()).get("key"));
141
- Assert.assertEquals("othervalue", ((HashMapLocationTemplate)config.getTemplate()).get("key"));
142
- }
143
-
144
-
145
- @Test
146
- public void testMergeArrayTemplate() {
147
- ArrayList props = new ArrayList();
148
- props.add("foo");
149
- ArrayListLocationTemplate tpl = new ArrayListLocationTemplate(props);
150
-
151
- Config config = new Config();
152
- config.setTemplate(tpl);
153
-
154
- Config merged = Config.merge(config, new Config());
155
-
156
- props.add(0, "foobar");
157
-
158
- Assert.assertNotSame(config, merged);
159
- Assert.assertNotSame(config.getTemplate(), merged.getTemplate());
160
- Assert.assertEquals("foo", ((ArrayListLocationTemplate)merged.getTemplate()).toArray()[0]);
161
- Assert.assertEquals("foobar", ((ArrayListLocationTemplate)config.getTemplate()).toArray()[0]);
162
- }
163
-
164
- @Test
165
- public void testMergeEmptyUrls() {
166
- Config config1 = new Config();
167
- config1.setUrl("url");
168
- config1.setSyncUrl("syncUrl");
169
-
170
- Config config2 = new Config();
171
- config2.setUrl("");
172
- config2.setSyncUrl("");
173
-
174
- Assert.assertEquals("", Config.merge(config1, config2).getUrl());
175
- Assert.assertEquals("", Config.merge(config1, config2).getSyncUrl());
176
- }
177
-
178
- @Test
179
- public void testResetToDefaultProps() {
180
- Config config1 = new Config();
181
- config1.setUrl("url");
182
- config1.setSyncUrl("syncUrl");
183
-
184
- Config config2 = new Config();
185
- config2.setUrl("");
186
- config2.setSyncUrl("");
187
-
188
- Assert.assertEquals(Config.getDefault().getUrl(), Config.merge(config1, config2).getUrl());
189
- Assert.assertEquals(Config.getDefault().getSyncUrl(), Config.merge(config1, config2).getSyncUrl());
190
- }
191
- }
@@ -1,37 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import androidx.test.filters.SmallTest;
4
-
5
- import com.marianhello.logging.DBLogReader;
6
-
7
- import junit.framework.Assert;
8
-
9
- import org.junit.Test;
10
- import org.slf4j.event.Level;
11
-
12
- @SmallTest
13
- public class DBLogReaderTest {
14
- @Test
15
- public void testBuildQuery() {
16
- DBLogReader.QueryBuilder qb = new DBLogReader.QueryBuilder();
17
- String sql = qb.buildQuery(100, 0, Level.DEBUG);
18
-
19
- Assert.assertEquals("SELECT [event_id], [timestmp], [formatted_message], [logger_name], [level_string] FROM [logging_event] WHERE [level_string] IN ('ERROR', 'WARN', 'INFO', 'DEBUG') ORDER BY [timestmp] DESC, [event_id] DESC LIMIT 100;", sql);
20
- }
21
-
22
- @Test
23
- public void testBuildQueryWithOffset() {
24
- DBLogReader.QueryBuilder qb = new DBLogReader.QueryBuilder();
25
- String sql = qb.buildQuery(100, 10, Level.ERROR);
26
-
27
- Assert.assertEquals("SELECT [event_id], [timestmp], [formatted_message], [logger_name], [level_string] FROM [logging_event] WHERE [level_string] IN ('ERROR') AND [event_id] < 10 ORDER BY [timestmp] DESC, [event_id] DESC LIMIT 100;", sql);
28
- }
29
-
30
- @Test
31
- public void testBuildStackTraceQuery() {
32
- DBLogReader.QueryBuilder qb = new DBLogReader.QueryBuilder();
33
- String sql = qb.buildStackTraceQuery(100);
34
-
35
- Assert.assertEquals("SELECT [trace_line] FROM [logging_event_exception] WHERE [i] = 100 ORDER BY [i] ASC;", sql);
36
- }
37
- }
@@ -1,216 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import com.marianhello.bgloc.Config;
4
- import com.marianhello.bgloc.data.BackgroundLocation;
5
- import com.marianhello.bgloc.data.HashMapLocationTemplate;
6
- import com.marianhello.bgloc.data.LocationTemplate;
7
- import com.marianhello.bgloc.data.LocationTemplateFactory;
8
-
9
- import junit.framework.Assert;
10
-
11
- import org.json.JSONArray;
12
- import org.json.JSONException;
13
- import org.json.JSONObject;
14
- import org.junit.Test;
15
-
16
- import java.util.HashMap;
17
-
18
- /**
19
- * Created by finch on 9.12.2017.
20
- */
21
-
22
- public class HashMapLocationTemplateTest {
23
- @Test
24
- public void testObjectTemplateToString() {
25
- HashMap props = new HashMap();
26
- props.put("foo", "bar");
27
- props.put("pretzels", 123);
28
- HashMapLocationTemplate tpl = new HashMapLocationTemplate(props);
29
-
30
- Assert.assertEquals("{\"foo\":\"bar\",\"pretzels\":123}" , tpl.toString());
31
- }
32
-
33
- @Test
34
- public void testLocationToJSONObject() throws JSONException {
35
- BackgroundLocation location = new BackgroundLocation();
36
- location.setLocationId(11L);
37
- location.setProvider("test");
38
- location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
39
- location.setAltitude(100);
40
- location.setLatitude(49);
41
- location.setLongitude(5);
42
- location.setLocationProvider(1);
43
- location.setAccuracy(105);
44
- location.setSpeed(50);
45
- location.setBearing(1);
46
-
47
- HashMap map = new HashMap<String, String>();
48
- map.put("Id", "@id");
49
- map.put("Provider", "@provider");
50
- map.put("Time", "@time");
51
- map.put("Altitude", "@altitude");
52
- map.put("Latitude", "@latitude");
53
- map.put("Longitude", "@longitude");
54
- map.put("Foo", "bar");
55
- map.put("LocationProvider", "@locationProvider");
56
- map.put("Accuracy", "@accuracy");
57
- map.put("Speed", "@speed");
58
- map.put("Bearing", "@bearing");
59
- map.put("Pretzels", 123);
60
-
61
- LocationTemplate tpl = new HashMapLocationTemplate(map);
62
- JSONObject expected = (JSONObject) tpl.locationToJson(location);
63
-
64
- Assert.assertEquals(expected.get("Id"), location.getLocationId());
65
- Assert.assertEquals(expected.get("Provider"), location.getProvider());
66
- Assert.assertEquals(expected.get("Time"), location.getTime());
67
- Assert.assertEquals(expected.get("Altitude"), location.getAltitude());
68
- Assert.assertEquals(expected.get("Latitude"), location.getLatitude());
69
- Assert.assertEquals(expected.get("Longitude"), location.getLongitude());
70
- Assert.assertEquals(expected.get("Foo"), "bar");
71
- Assert.assertEquals(expected.get("LocationProvider"), location.getLocationProvider());
72
- Assert.assertEquals(expected.get("Accuracy"), location.getAccuracy());
73
- Assert.assertEquals(expected.get("Speed"), location.getSpeed());
74
- Assert.assertEquals(expected.get("Bearing"), location.getBearing());
75
- Assert.assertEquals(expected.get("Pretzels"), 123);
76
- }
77
-
78
- @Test
79
- public void testLocationToJSONObjectFactory() throws JSONException {
80
- BackgroundLocation location = new BackgroundLocation();
81
- location.setLocationId(11L);
82
- location.setProvider("test");
83
- location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
84
- location.setAltitude(100);
85
- location.setLatitude(49);
86
- location.setLongitude(5);
87
- location.setLocationProvider(1);
88
- location.setAccuracy(105);
89
- location.setSpeed(50);
90
- location.setBearing(1);
91
-
92
- HashMap map = new HashMap();
93
- map.put("Id", "@id");
94
- map.put("Provider", "@provider");
95
- map.put("Time", "@time");
96
- map.put("Altitude", "@altitude");
97
- map.put("Latitude", "@latitude");
98
- map.put("Longitude", "@longitude");
99
- map.put("Foo", "bar");
100
- map.put("LocationProvider", "@locationProvider");
101
- map.put("Accuracy", "@accuracy");
102
- map.put("Speed", "@speed");
103
- map.put("Bearing", "@bearing");
104
- map.put("Pretzels", 123);
105
-
106
- JSONObject json = new JSONObject(map);
107
- LocationTemplate tpl = LocationTemplateFactory.fromJSON(json);
108
-
109
- JSONObject expected = (JSONObject) tpl.locationToJson(location);
110
-
111
- Assert.assertEquals(expected.get("Id"), location.getLocationId());
112
- Assert.assertEquals(expected.get("Provider"), location.getProvider());
113
- Assert.assertEquals(expected.get("Time"), location.getTime());
114
- Assert.assertEquals(expected.get("Altitude"), location.getAltitude());
115
- Assert.assertEquals(expected.get("Latitude"), location.getLatitude());
116
- Assert.assertEquals(expected.get("Longitude"), location.getLongitude());
117
- Assert.assertEquals(expected.get("Foo"), "bar");
118
- Assert.assertEquals(expected.get("LocationProvider"), location.getLocationProvider());
119
- Assert.assertEquals(expected.get("Accuracy"), location.getAccuracy());
120
- Assert.assertEquals(expected.get("Speed"), location.getSpeed());
121
- Assert.assertEquals(expected.get("Bearing"), location.getBearing());
122
- }
123
-
124
- @Test
125
- public void testNullToString() {
126
- HashMapLocationTemplate tpl = new HashMapLocationTemplate((HashMap)null);
127
- Assert.assertEquals("null", tpl.toString());
128
- }
129
-
130
- @Test
131
- public void testNestedObjectTemplate() throws JSONException {
132
- BackgroundLocation location = new BackgroundLocation();
133
- location.setLocationId(11L);
134
- location.setProvider("test");
135
- location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
136
- location.setAltitude(100);
137
- location.setLatitude(49);
138
- location.setLongitude(5);
139
- location.setLocationProvider(1);
140
- location.setAccuracy(105);
141
- location.setSpeed(50);
142
- location.setBearing(1);
143
-
144
- JSONObject template = new JSONObject(
145
- "{\"data\":{\"Id\":\"@id\"," +
146
- "\"Provider\":\"@provider\"," +
147
- "\"Time\":\"@time\"," +
148
- "\"Altitude\":\"@altitude\"," +
149
- "\"Latitude\":\"@latitude\"," +
150
- "\"Longitude\":\"@longitude\"," +
151
- "\"Foo\":\"bar\"," +
152
- "\"LocationProvider\":\"@locationProvider\"," +
153
- "\"Accuracy\":\"@accuracy\"," +
154
- "\"Speed\":\"@speed\"," +
155
- "\"Bearing\":\"@bearing\"}" +
156
- "}"
157
- );
158
- LocationTemplate tpl = LocationTemplateFactory.fromJSON(template);
159
-
160
- JSONObject json = ((JSONObject) tpl.locationToJson(location));
161
- JSONObject expected = json.getJSONObject("data");
162
-
163
- Assert.assertEquals(expected.get("Id"), location.getLocationId());
164
- Assert.assertEquals(expected.get("Provider"), location.getProvider());
165
- Assert.assertEquals(expected.get("Time"), location.getTime());
166
- Assert.assertEquals(expected.get("Altitude"), location.getAltitude());
167
- Assert.assertEquals(expected.get("Latitude"), location.getLatitude());
168
- Assert.assertEquals(expected.get("Longitude"), location.getLongitude());
169
- Assert.assertEquals(expected.get("Foo"), "bar");
170
- Assert.assertEquals(expected.get("LocationProvider"), location.getLocationProvider());
171
- Assert.assertEquals(expected.get("Accuracy"), location.getAccuracy());
172
- Assert.assertEquals(expected.get("Speed"), location.getSpeed());
173
- Assert.assertEquals(expected.get("Bearing"), location.getBearing());
174
- }
175
-
176
-
177
- @Test
178
- public void testNestedArrayTemplate() throws JSONException {
179
- BackgroundLocation location = new BackgroundLocation();
180
- location.setLocationId(11L);
181
- location.setProvider("test");
182
- location.setElapsedRealtimeNanos(2000000000L * 60 * 2);
183
- location.setAltitude(100);
184
- location.setLatitude(49);
185
- location.setLongitude(5);
186
- location.setLocationProvider(1);
187
- location.setAccuracy(105);
188
- location.setSpeed(50);
189
- location.setBearing(1);
190
-
191
- JSONObject template = new JSONObject(
192
- "{\"data\":[\"@id\",\"@provider\",\"@time\",\"@altitude\",\"@latitude\"," +
193
- "\"@longitude\",\"foo\",\"@locationProvider\",\"@accuracy\",\"@speed\"," +
194
- "\"@bearing\",123]}"
195
- );
196
- LocationTemplate tpl = LocationTemplateFactory.fromJSON(template);
197
-
198
- JSONObject json = ((JSONObject) tpl.locationToJson(location));
199
- JSONArray expected = json.getJSONArray("data");
200
-
201
- Assert.assertEquals(expected.get(0), location.getLocationId());
202
- Assert.assertEquals(expected.get(1), location.getProvider());
203
- Assert.assertEquals(expected.get(2), location.getTime());
204
- Assert.assertEquals(expected.get(3), location.getAltitude());
205
- Assert.assertEquals(expected.get(4), location.getLatitude());
206
- Assert.assertEquals(expected.get(5), location.getLongitude());
207
- Assert.assertEquals(expected.get(6), "foo");
208
- Assert.assertEquals(expected.get(7), location.getLocationProvider());
209
- Assert.assertEquals(expected.get(8), location.getAccuracy());
210
- Assert.assertEquals(expected.get(9), location.getSpeed());
211
- Assert.assertEquals(expected.get(10), location.getBearing());
212
- Assert.assertEquals(expected.get(11), 123);
213
-
214
- }
215
-
216
- }