@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,223 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import android.os.Build;
4
-
5
- import com.marianhello.bgloc.HttpPostService;
6
- import com.marianhello.bgloc.HttpPostService.UploadingProgressListener;
7
-
8
- import org.json.JSONArray;
9
- import org.json.JSONObject;
10
- import org.junit.After;
11
- import org.junit.Before;
12
- import org.junit.Rule;
13
- import org.junit.Test;
14
- import org.junit.rules.ExpectedException;
15
- import org.junit.runner.RunWith;
16
- import org.mockito.InOrder;
17
- import org.mockito.Mock;
18
- import org.mockito.MockitoAnnotations;
19
- import org.robolectric.RobolectricTestRunner;
20
-
21
- import java.io.ByteArrayInputStream;
22
- import java.io.ByteArrayOutputStream;
23
- import java.io.File;
24
- import java.io.IOException;
25
- import java.io.InputStream;
26
- import java.net.HttpURLConnection;
27
- import java.net.MalformedURLException;
28
- import java.net.UnknownHostException;
29
- import java.util.HashMap;
30
- import java.util.Random;
31
-
32
- import static org.hamcrest.core.Is.is;
33
- import static org.junit.Assert.assertThat;
34
- import static org.mockito.Mockito.inOrder;
35
- import static org.mockito.Mockito.mock;
36
- import static org.mockito.Mockito.verify;
37
- import static org.mockito.Mockito.when;
38
-
39
- @RunWith(RobolectricTestRunner.class)
40
- public class HttpPostServiceTest {
41
- @Mock
42
- HttpURLConnection mockHttpURLConnection;
43
-
44
- private static final int DEFAULT_SDK_INT = Build.VERSION.SDK_INT;
45
-
46
- @Rule
47
- public final ExpectedException exception = ExpectedException.none();
48
-
49
- @Before
50
- public void setUp() {
51
- MockitoAnnotations.initMocks(this);
52
- }
53
-
54
- @After
55
- public void cleanUp() {
56
- try {
57
- TestHelper.setFinalStatic(Build.VERSION.class.getField("SDK_INT"), DEFAULT_SDK_INT);
58
- } catch (Exception e) {
59
- e.printStackTrace();
60
- }
61
- }
62
-
63
- @Test
64
- public void testPostJSONThrowsMalformedURLException() throws IOException {
65
- exception.expect(MalformedURLException.class);
66
- HttpPostService.postJSON(null, (JSONObject) null, null);
67
- }
68
-
69
- @Test
70
- public void testPostJSONThrowsUnknownHostException() throws IOException {
71
- exception.expect(UnknownHostException.class);
72
- HttpPostService.postJSON("http://unknown/json", (JSONObject) null, null);
73
- }
74
-
75
- @Test
76
- public void testPostJSONResult() throws IOException {
77
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
78
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
79
- when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
80
-
81
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
82
- assertThat(service.postJSON((JSONObject) new JSONObject(), null), is(200));
83
- verify(mockHttpURLConnection).setRequestMethod("POST");
84
- }
85
-
86
-
87
- @Test
88
- public void testPostJSONShouldPostHeaders() throws IOException {
89
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
90
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
91
-
92
- HashMap headers = new HashMap();
93
- headers.put("foo", "bar");
94
-
95
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
96
- service.postJSON((JSONObject) null, headers);
97
- verify(mockHttpURLConnection).setRequestMethod("POST");
98
- verify(mockHttpURLConnection).setRequestProperty("Content-Type", "application/json");
99
- verify(mockHttpURLConnection).setRequestProperty("foo", "bar");
100
- }
101
-
102
- @Test
103
- public void testPostJSONObject() throws IOException {
104
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
105
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
106
-
107
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
108
- service.postJSON(new JSONObject(), null);
109
- verify(mockHttpURLConnection).setRequestMethod("POST");
110
- assertThat(outputStream.toString(), is("{}"));
111
- }
112
-
113
- @Test
114
- public void testPostJSONArray() throws IOException {
115
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
116
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
117
-
118
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
119
- service.postJSON(new JSONArray(), null);
120
- verify(mockHttpURLConnection).setRequestMethod("POST");
121
- assertThat(outputStream.toString(), is("[]"));
122
- }
123
-
124
- @Test
125
- public void testPostJSONObjectNull() throws IOException {
126
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
127
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
128
-
129
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
130
- service.postJSON((JSONObject) null, null);
131
- verify(mockHttpURLConnection).setRequestMethod("POST");
132
- assertThat(outputStream.toString(), is("null"));
133
- }
134
-
135
- @Test
136
- public void testPostJSONArrayNull() throws IOException {
137
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
138
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
139
-
140
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
141
- service.postJSON((JSONArray) null, null);
142
- verify(mockHttpURLConnection).setRequestMethod("POST");
143
- assertThat(outputStream.toString(), is("null"));
144
- }
145
-
146
- @Test
147
- public void testPostString() throws IOException {
148
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
149
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
150
-
151
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
152
- service.postJSONString("test", null);
153
- verify(mockHttpURLConnection).setRequestMethod("POST");
154
- verify(mockHttpURLConnection).setRequestProperty("Content-Type", "application/json");
155
- assertThat(outputStream.toString(), is("test"));
156
- }
157
-
158
- @Test
159
- public void testPostStream() throws Exception {
160
- TestHelper.setFinalStatic(Build.VERSION.class.getField("SDK_INT"), Build.VERSION_CODES.KITKAT);
161
-
162
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
163
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
164
- when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
165
-
166
- String body = "test";
167
- InputStream inputStream = new ByteArrayInputStream(body.getBytes());
168
- HashMap headers = new HashMap();
169
- headers.put("foo", "bar");
170
-
171
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
172
- assertThat(service.postJSONFile(inputStream, headers, null), is(200));
173
- verify(mockHttpURLConnection).setRequestMethod("POST");
174
- verify(mockHttpURLConnection).setRequestProperty("foo", "bar");
175
- verify(mockHttpURLConnection).setFixedLengthStreamingMode((long) body.length());
176
- //verify(mockHttpURLConnection).setChunkedStreamingMode(0);
177
- assertThat(outputStream.toString(), is("test"));
178
- }
179
-
180
- @Test
181
- public void testJSONPostFile() throws Exception {
182
- TestHelper.setFinalStatic(Build.VERSION.class.getField("SDK_INT"), Build.VERSION_CODES.KITKAT);
183
-
184
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
185
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
186
- when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
187
-
188
- File file = new File("./README.md");
189
-
190
- HashMap headers = new HashMap();
191
- headers.put("foo", "bar");
192
-
193
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
194
- assertThat(service.postJSONFile(file, headers, null), is(200));
195
- verify(mockHttpURLConnection).setRequestMethod("POST");
196
- verify(mockHttpURLConnection).setRequestProperty("Content-Type", "application/json");
197
- verify(mockHttpURLConnection).setRequestProperty("foo", "bar");
198
- verify(mockHttpURLConnection).setFixedLengthStreamingMode((long) file.length());
199
- //verify(mockHttpURLConnection).setChunkedStreamingMode(0);
200
- }
201
-
202
- @Test
203
- public void testJSONPostFileProgressListener() throws IOException {
204
- HttpPostService service = new HttpPostService(mockHttpURLConnection);
205
- UploadingProgressListener mockListener = mock(UploadingProgressListener.class);
206
-
207
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
208
- when(mockHttpURLConnection.getOutputStream()).thenReturn(outputStream);
209
-
210
- int bodySize = HttpPostService.BUFFER_SIZE * 5;
211
- byte[] body = new byte[bodySize];
212
- new Random().nextBytes(body);
213
- InputStream inputStream = new ByteArrayInputStream(body);
214
-
215
- service.postJSONFile(inputStream, null, mockListener);
216
- InOrder inOrder = inOrder(mockListener);
217
- inOrder.verify(mockListener).onProgress(20);
218
- inOrder.verify(mockListener).onProgress(40);
219
- inOrder.verify(mockListener).onProgress(60);
220
- inOrder.verify(mockListener).onProgress(80);
221
- inOrder.verify(mockListener).onProgress(100);
222
- }
223
- }
@@ -1,50 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import com.marianhello.bgloc.data.LocationTemplate;
4
- import com.marianhello.bgloc.data.LocationTemplateFactory;
5
-
6
- import junit.framework.Assert;
7
-
8
- import org.json.JSONArray;
9
- import org.json.JSONException;
10
- import org.json.JSONObject;
11
- import org.json.JSONTokener;
12
- import org.junit.Test;
13
-
14
- /**
15
- * Created by finch on 9.12.2017.
16
- */
17
-
18
- public class LocationTemplateFactoryTest {
19
- @Test
20
- public void testTemplateFromJsonArray() {
21
- String jsonString = "[\"foo\",\"bar\",123]";
22
-
23
- try {
24
- LocationTemplate tpl = LocationTemplateFactory.fromJSONString(jsonString);
25
- JSONArray expected = new JSONArray();
26
- expected.put("foo");
27
- expected.put("bar");
28
- expected.put(123);
29
- Assert.assertEquals(expected.toString(), tpl.toString());
30
- } catch (JSONException e) {
31
- org.junit.Assert.fail(e.getMessage());
32
- }
33
- }
34
-
35
- @Test
36
- public void testTemplateFromJsonObject() {
37
- String jsonString = "{\"foo\":\"bar\",\"pretzels\":123}";
38
-
39
- try {
40
- LocationTemplate tpl = LocationTemplateFactory.fromJSONString(jsonString);
41
- JSONObject expected = new JSONObject();
42
- expected.put("foo", "bar");
43
- expected.put("pretzels", 123);
44
- Assert.assertEquals(expected.toString(), tpl.toString());
45
- } catch (JSONException e) {
46
- org.junit.Assert.fail(e.getMessage());
47
- }
48
- }
49
-
50
- }
@@ -1,180 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import com.marianhello.bgloc.Config;
4
- import com.marianhello.bgloc.ConnectivityListener;
5
- import com.marianhello.bgloc.PostLocationTask;
6
- import com.marianhello.bgloc.PostLocationTask.PostLocationTaskListener;
7
- import com.marianhello.bgloc.data.BackgroundLocation;
8
- import com.marianhello.bgloc.data.LocationDAO;
9
-
10
- import org.junit.After;
11
- import org.junit.Before;
12
- import org.junit.BeforeClass;
13
- import org.junit.Ignore;
14
- import org.junit.Rule;
15
- import org.junit.Test;
16
- import org.junit.rules.ExpectedException;
17
- import org.junit.runner.RunWith;
18
- import org.mockito.MockitoAnnotations;
19
- import org.robolectric.RobolectricTestRunner;
20
-
21
- import java.io.IOException;
22
- import java.net.HttpURLConnection;
23
- import java.net.ProtocolException;
24
- import java.net.URL;
25
- import java.net.URLConnection;
26
- import java.net.URLStreamHandler;
27
- import java.net.URLStreamHandlerFactory;
28
- import java.util.concurrent.RejectedExecutionException;
29
-
30
- import static org.mockito.Mockito.mock;
31
- import static org.mockito.Mockito.reset;
32
- import static org.mockito.Mockito.times;
33
- import static org.mockito.Mockito.verify;
34
-
35
- /**
36
- * Test inspired by
37
- * https://github.com/google/agera/blob/master/extensions/net/src/test/java/com/google/android/agera/net/HttpFunctionsTest.java
38
- */
39
- @RunWith(RobolectricTestRunner.class)
40
- public class PostLocationTaskTest {
41
- private static final String TEST_PROTOCOL = "httptest";
42
- private static final String SLOW_PROTOCOL = "httpslow";
43
-
44
- private static HttpURLConnection mockHttpURLConnection;
45
-
46
- private ConnectivityListener connectivityListener = new ConnectivityListener() {
47
- @Override
48
- public boolean hasConnectivity() {
49
- return true;
50
- }
51
- };
52
-
53
- @Rule
54
- public final ExpectedException exception = ExpectedException.none();
55
-
56
- @BeforeClass
57
- public static void onlyOnce() throws Throwable {
58
- mockHttpURLConnection = mock(HttpURLConnection.class);
59
- URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
60
- @Override
61
- public URLStreamHandler createURLStreamHandler(final String s) {
62
- if (TEST_PROTOCOL.equals(s)) {
63
- return new URLStreamHandler() {
64
- @Override
65
- protected URLConnection openConnection(final URL url) throws IOException {
66
- return mockHttpURLConnection;
67
- }
68
- };
69
- }
70
- if (SLOW_PROTOCOL.equals(s)) {
71
- return new URLStreamHandler() {
72
- @Override
73
- protected URLConnection openConnection(final URL url) throws IOException {
74
- try {
75
- Thread.sleep(100);
76
- } catch (InterruptedException e) { /* noop */ }
77
- return mockHttpURLConnection;
78
- }
79
- };
80
- }
81
-
82
- return null;
83
- }
84
- });
85
- }
86
-
87
- @Before
88
- public void setUp() {
89
- MockitoAnnotations.initMocks(this);
90
- }
91
-
92
- @After
93
- public void tearDown() {
94
- reset(mockHttpURLConnection);
95
- }
96
-
97
- @Test
98
- public void persistTask() throws ProtocolException, InterruptedException {
99
- LocationDAO mockDAO = mock(LocationDAO.class);
100
-
101
- PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
102
- PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
103
-
104
- Config config = Config.getDefault();
105
- config.setUrl(TEST_PROTOCOL + "://localhost:3000/locations");
106
- config.setSyncUrl(TEST_PROTOCOL + "://localhost:3000/sync");
107
- task.setConfig(config);
108
-
109
- for (int i = 0; i < 10; i++) {
110
- task.add(new BackgroundLocation());
111
- }
112
-
113
- Thread.sleep(3000);
114
- verify(mockHttpURLConnection, times(10)).setRequestMethod("POST");
115
- }
116
-
117
- @Test
118
- public void persistTaskShouldRejectAfterShutdown() {
119
- LocationDAO mockDAO = mock(LocationDAO.class);
120
-
121
- PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
122
- PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
123
-
124
- Config config = Config.getDefault();
125
- config.setUrl(TEST_PROTOCOL + "://localhost:3000/locations");
126
- config.setSyncUrl(TEST_PROTOCOL + "://localhost:3000/sync");
127
- task.setConfig(config);
128
-
129
- for (int i = 0; i < 10; i++) {
130
- task.add(new BackgroundLocation());
131
- }
132
-
133
- task.shutdown();
134
- task.add(new BackgroundLocation());
135
- }
136
-
137
- @Test
138
- public void persistTaskOnShutdown() throws ProtocolException, InterruptedException {
139
- LocationDAO mockDAO = mock(LocationDAO.class);
140
-
141
- PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
142
- PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
143
-
144
- Config config = Config.getDefault();
145
- config.setUrl(SLOW_PROTOCOL + "://localhost:3000/locations");
146
- config.setSyncUrl(SLOW_PROTOCOL + "://localhost:3000/sync");
147
- task.setConfig(config);
148
-
149
- for (int i = 0; i < 10; i++) {
150
- task.add(new BackgroundLocation());
151
- }
152
-
153
- task.shutdown(600);
154
-
155
- Thread.sleep(3000);
156
- verify(mockHttpURLConnection, times(10)).setRequestMethod("POST");
157
- }
158
-
159
- @Test
160
- public void persistTaskSetUnsyncedOnShutdown() throws InterruptedException {
161
- LocationDAO mockDAO = mock(LocationDAO.class);
162
-
163
- PostLocationTaskListener mockListener = mock(PostLocationTaskListener.class);
164
- PostLocationTask task = new PostLocationTask(mockDAO,mockListener, connectivityListener);
165
-
166
- Config config = Config.getDefault();
167
- config.setUrl(SLOW_PROTOCOL + "://localhost:3000/locations");
168
- config.setSyncUrl(SLOW_PROTOCOL + "://localhost:3000/sync");
169
- task.setConfig(config);
170
-
171
- for (int i = 0; i < 10; i++) {
172
- task.add(new BackgroundLocation());
173
- }
174
-
175
- task.shutdown(1);
176
-
177
- Thread.sleep(3000);
178
- verify(mockDAO).deleteUnpostedLocations();
179
- }
180
- }
@@ -1,16 +0,0 @@
1
- package com.marianhello.backgroundgeolocation;
2
-
3
- import java.lang.reflect.Field;
4
- import java.lang.reflect.Modifier;
5
-
6
- public class TestHelper {
7
- static void setFinalStatic(Field field, Object newValue) throws Exception {
8
- field.setAccessible(true);
9
-
10
- Field modifiersField = Field.class.getDeclaredField("modifiers");
11
- modifiersField.setAccessible(true);
12
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
13
-
14
- field.set(null, newValue);
15
- }
16
- }
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>CFBundleDevelopmentRegion</key>
6
- <string>en</string>
7
- <key>CFBundleExecutable</key>
8
- <string>$(EXECUTABLE_NAME)</string>
9
- <key>CFBundleIdentifier</key>
10
- <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
- <key>CFBundleInfoDictionaryVersion</key>
12
- <string>6.0</string>
13
- <key>CFBundleName</key>
14
- <string>$(PRODUCT_NAME)</string>
15
- <key>CFBundlePackageType</key>
16
- <string>BNDL</string>
17
- <key>CFBundleShortVersionString</key>
18
- <string>1.0</string>
19
- <key>CFBundleSignature</key>
20
- <string>????</string>
21
- <key>CFBundleVersion</key>
22
- <string>1</string>
23
- </dict>
24
- </plist>
@@ -1,185 +0,0 @@
1
- //
2
- // MAURBackgroundLocationTest.m
3
- // BackgroundGeolocationTests
4
- //
5
- // Created by Marian Hello on 12/06/16.
6
- // Copyright © 2016 mauron85. All rights reserved.
7
- //
8
-
9
- #import <XCTest/XCTest.h>
10
- #import "MAURLocation.h"
11
-
12
- @interface MAURBackgroundLocationTest : XCTestCase
13
-
14
- @end
15
-
16
- @implementation MAURBackgroundLocationTest
17
-
18
- - (void)setUp {
19
- [super setUp];
20
- // Put setup code here. This method is called before the invocation of each test method in the class.
21
- }
22
-
23
- - (void)tearDown {
24
- // Put teardown code here. This method is called after the invocation of each test method in the class.
25
- [super tearDown];
26
- }
27
-
28
- - (void)testTimeToDictionary {
29
- NSDateFormatter *RFC3339DateFormatter = [[NSDateFormatter alloc] init];
30
- RFC3339DateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
31
- RFC3339DateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZZ";
32
- RFC3339DateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
33
- NSString *string = @"2016-01-01T00:00:00+01:00";
34
-
35
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
36
- bgloc1.time = [RFC3339DateFormatter dateFromString:string];
37
-
38
- NSDictionary *data = [bgloc1 toDictionary];
39
-
40
- XCTAssertEqual([[data objectForKey:@"time"] doubleValue], 1451602800000);
41
- XCTAssertEqual([bgloc1.time timeIntervalSince1970] * 1000, 1451602800000);
42
- }
43
-
44
- - (void)testObjectCopying {
45
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
46
- bgloc1.latitude = [NSNumber numberWithDouble:12];
47
- bgloc1.longitude = [NSNumber numberWithDouble:11];
48
- bgloc1.radius = [NSNumber numberWithDouble:50];
49
-
50
- MAURLocation *stationaryLocation = [bgloc1 copy];
51
- // stationaryLocation.type = @"stationary";
52
-
53
- XCTAssertTrue([bgloc1.radius isEqualToNumber:[NSNumber numberWithDouble:50]]);
54
- // XCTAssertTrue([stationaryLocation.type isEqualToString:@"stationary"]);
55
- }
56
-
57
- - (void)testDistanceFromLocation {
58
- // This is an example of a functional test case.
59
- // Use XCTAssert and related functions to verify your tests produce the correct results.
60
- const double latitude1 = 49.1634594;
61
- const double longitude1 = 20.273454;
62
- const double latitude2 = 49.1260825;
63
- const double longitude2 = 20.4350187;
64
-
65
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
66
- MAURLocation *bgloc2 = [[MAURLocation alloc] init];
67
- bgloc1.latitude = [NSNumber numberWithDouble:latitude1];
68
- bgloc1.longitude = [NSNumber numberWithDouble:longitude1];
69
- bgloc2.latitude = [NSNumber numberWithDouble:latitude2];
70
- bgloc2.longitude = [NSNumber numberWithDouble:longitude2];
71
-
72
- CLLocation *location1 = [[CLLocation alloc]initWithLatitude:latitude1 longitude:longitude1];
73
- CLLocation *location2 = [[CLLocation alloc]initWithLatitude:latitude2 longitude:longitude2];
74
-
75
- double apple_dist = [location1 distanceFromLocation:location2];
76
- double bgloc_dist = [bgloc1 distanceFromLocation:bgloc2];
77
- XCTAssertEqualWithAccuracy(bgloc_dist, apple_dist, 20, "Our implementation of distance %f should equal Apple %f", bgloc_dist, apple_dist);
78
- }
79
-
80
- - (void)testLocationIsBeyond {
81
- // Use XCTAssert and related functions to verify your tests produce the correct results.
82
- const double latitude1 = 49.134873;
83
- const double longitude1 = 20.209260;
84
- const double latitude2 = 49.14088;
85
- const double longitude2 = 20.225382;
86
-
87
- MAURLocation *bgloc1 = [[MAURLocation alloc] init];
88
- MAURLocation *bgloc2 = [[MAURLocation alloc] init];
89
- bgloc1.latitude = [NSNumber numberWithDouble:latitude1];
90
- bgloc1.longitude = [NSNumber numberWithDouble:longitude1];
91
- bgloc2.latitude = [NSNumber numberWithDouble:latitude2];
92
- bgloc2.longitude = [NSNumber numberWithDouble:longitude2];
93
-
94
- XCTAssertTrue([bgloc1 isBeyond:bgloc2 radius:100], "Expecting bgloc1 to not be beyond bgloc2 and radius 100m");
95
- XCTAssertTrue([bgloc1 isBeyond:bgloc2 radius:1000], "Expecting bgloc1 to not be beyond bgloc2 and radius 1000m");
96
- XCTAssertTrue(![bgloc1 isBeyond:bgloc2 radius:10000], "Expecting bgloc1 to be beyond bgloc2 and radius 10000m");
97
- }
98
-
99
- - (void)testIfSignificantlyNewerLocationIsBetter {
100
- const double latitude1 = 49.134873;
101
- const double longitude1 = 20.209260;
102
- const double latitude2 = 49.14088;
103
- const double longitude2 = 20.225382;
104
- const int oldtime = 1451602800; //Fri Jan 01 2016 00:00:00 GMT+0100 (CET)
105
- const int newtime = 1451610000; //Fri Jan 01 2016 00:02:00 GMT+0100 (CET)
106
-
107
- MAURLocation *older = [[MAURLocation alloc] init];
108
- MAURLocation *newer = [[MAURLocation alloc] init];
109
- older.latitude = [NSNumber numberWithDouble:latitude1];
110
- older.longitude = [NSNumber numberWithDouble:longitude1];
111
- older.time = [[NSDate alloc]initWithTimeIntervalSince1970:oldtime];
112
- newer.latitude = [NSNumber numberWithDouble:latitude2];
113
- newer.longitude = [NSNumber numberWithDouble:longitude2];
114
- newer.time = [[NSDate alloc]initWithTimeIntervalSince1970:newtime];
115
-
116
- XCTAssertTrue([newer isBetterLocation:older]);
117
- }
118
-
119
- - (void)testIfLocationWithBetterAccuracyAndSameTimeIsBetter {
120
- const double latitude1 = 49.134873;
121
- const double longitude1 = 20.209260;
122
- const double latitude2 = 49.14088;
123
- const double longitude2 = 20.225382;
124
- const double accuracy = 400;
125
- const double betterAccuracy = 100;
126
- const int time = 1451602800;
127
-
128
- MAURLocation *lessAccurate = [[MAURLocation alloc] init];
129
- MAURLocation *moreAccurate = [[MAURLocation alloc] init];
130
- lessAccurate.latitude = [NSNumber numberWithDouble:latitude1];
131
- lessAccurate.longitude = [NSNumber numberWithDouble:longitude1];
132
- lessAccurate.time = [[NSDate alloc]initWithTimeIntervalSince1970:time];
133
- lessAccurate.accuracy = [NSNumber numberWithDouble:accuracy];
134
- moreAccurate.latitude = [NSNumber numberWithDouble:latitude2];
135
- moreAccurate.longitude = [NSNumber numberWithDouble:longitude2];
136
- moreAccurate.time = [[NSDate alloc]initWithTimeIntervalSince1970:time];
137
- moreAccurate.accuracy = [NSNumber numberWithDouble:betterAccuracy];
138
-
139
- XCTAssertTrue([moreAccurate isBetterLocation:lessAccurate]);
140
- }
141
-
142
- - (void)testIflLocationWithNilAccuracyIsInvalid
143
- {
144
- MAURLocation *loc = [[MAURLocation alloc] init];
145
- XCTAssertFalse([loc hasAccuracy]);
146
- }
147
-
148
- - (void) testIfLocationWithZeroAccuracyIsInvalid
149
- {
150
- MAURLocation *loc = [[MAURLocation alloc] init];
151
- loc.accuracy = [NSNumber numberWithInt:0];
152
- XCTAssertTrue([loc hasAccuracy]);
153
- }
154
-
155
- - (void) testIfLocationWithAccuracyAboveZeroIsValid
156
- {
157
- MAURLocation *loc = [[MAURLocation alloc] init];
158
- loc.accuracy = [NSNumber numberWithInt:10];
159
- XCTAssertTrue([loc isValid]);
160
- }
161
-
162
- - (void)testIflLocationWithTimeMoreThenOneDayFromNowIsInvalid
163
- {
164
- MAURLocation *loc = [[MAURLocation alloc] init];
165
- loc.accuracy = [[NSNumber alloc] initWithInt:1];
166
- loc.time = [[[NSDate alloc] init] dateByAddingTimeInterval:186400];
167
- XCTAssertTrue(![loc hasTime]);
168
- }
169
-
170
- - (void)testIflLocationWithTimeNowIsValid
171
- {
172
- MAURLocation *loc = [[MAURLocation alloc] init];
173
- loc.accuracy = [[NSNumber alloc] initWithInt:1];
174
- loc.time = [[NSDate alloc] init];
175
- XCTAssertTrue([loc isValid]);
176
- }
177
-
178
- - (void)testPerformanceExample {
179
- // This is an example of a performance test case.
180
- [self measureBlock:^{
181
- // Put the code you want to measure the time of here.
182
- }];
183
- }
184
-
185
- @end