mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-14 08:11:00 +00:00
made a resource fetching test that succeeds locally
This commit is contained in:
1 parent
bdf1412954
commit
b8e48c33ac
6 files changed
+24
-15
No files matched your search
+3
-1
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -80,7 +81,8 @@ public class SignInTest {
|
||||
final IgtimiConnectionFactory connectionFactory = Activator.getInstance().getConnectionFactory();
|
||||
Account account = connectionFactory.registerAccountForWhichClientIsAuthorized("3b6cbd0522423bb1ac274ddb9e7e579c4b3be6667622271086c4fdbf30634ba9");
|
||||
IgtimiConnection connection = connectionFactory.connect(account);
|
||||
Iterable<Resource> resources = connection.getResources(Permission.read, /* start time */ null, /* end time */ null, /* serial numbers */ null, /* stream IDs */ null);
|
||||
Iterable<Resource> resources = connection.getResources(Permission.read, /* start time */ null, /* end time */ null,
|
||||
/* serial numbers */ Collections.singleton("GA-EN-AAEJ"), /* stream IDs */ null);
|
||||
assertTrue(resources.iterator().hasNext());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ public interface Resource {
|
||||
|
||||
public abstract boolean isBlob();
|
||||
|
||||
public abstract Permission[] getPermissions();
|
||||
public abstract Iterable<Permission> getPermissions();
|
||||
|
||||
public abstract int[] getDataTypes();
|
||||
|
||||
|
||||
+2
@@ -150,6 +150,8 @@ public class IgtimiConnectionFactoryImpl implements IgtimiConnectionFactory {
|
||||
url.append(streamId);
|
||||
}
|
||||
}
|
||||
url.append("&");
|
||||
url.append(getAccessTokenUrlParameter(account));
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -52,9 +52,9 @@ public class IgtimiConnectionImpl implements IgtimiConnection {
|
||||
Iterable<String> serialNumbers, Iterable<String> streamIds) throws IllegalStateException, ClientProtocolException, IOException, ParseException {
|
||||
HttpClient client = getHttpClient();
|
||||
HttpGet getResources = new HttpGet(connectionFactory.getResourcesUrl(permission, startTime, endTime, serialNumbers, streamIds, account));
|
||||
JSONObject usersJson = ConnectivityUtils.getJsonFromResponse(client.execute(getResources));
|
||||
JSONObject resourcesJson = ConnectivityUtils.getJsonFromResponse(client.execute(getResources));
|
||||
final List<Resource> result = new ArrayList<>();
|
||||
for (Object userJson : (JSONArray) usersJson.get("resources")) {
|
||||
for (Object userJson : (JSONArray) resourcesJson.get("resources")) {
|
||||
Resource user = new ResourceDeserializer().createResourceFromJson((JSONObject) ((JSONObject) userJson).get("resource"));
|
||||
result.add(user);
|
||||
}
|
||||
|
||||
+13
-8
@@ -1,5 +1,9 @@
|
||||
package com.sap.sailing.domain.igtimiadapter.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -14,16 +18,17 @@ public class ResourceDeserializer {
|
||||
new MillisecondsTimePoint(((Double) resourceJson.get("start_time")).longValue()),
|
||||
new MillisecondsTimePoint(((Double) resourceJson.get("end_time")).longValue()),
|
||||
(String) resourceJson.get("device_serial_number"),
|
||||
getDataTypes((JSONArray) resourceJson.get("dadta_types")),
|
||||
getPermissions((JSONArray) resourceJson.get("permissions")),
|
||||
getDataTypes((JSONArray) resourceJson.get("data_types")),
|
||||
getPermissions((JSONObject) resourceJson.get("permissions")),
|
||||
blob == null ? false : blob);
|
||||
}
|
||||
|
||||
private Permission[] getPermissions(JSONArray jsonArray) {
|
||||
final Permission[] result = new Permission[jsonArray.size()];
|
||||
int i=0;
|
||||
for (Object o : jsonArray) {
|
||||
result[i++] = Permission.valueOf((String) o);
|
||||
private Iterable<Permission> getPermissions(JSONObject permissions) {
|
||||
final List<Permission> result = new ArrayList<>();
|
||||
for (Entry<Object, Object> e : permissions.entrySet()) {
|
||||
if ((Boolean) e.getValue()) {
|
||||
result.add(Permission.valueOf((String) e.getKey()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -32,7 +37,7 @@ public class ResourceDeserializer {
|
||||
final int[] result = new int[jsonArray.size()];
|
||||
int i=0;
|
||||
for (Object o : jsonArray) {
|
||||
result[i++] = (Integer) o;
|
||||
result[i++] = ((Long) o).intValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,11 +10,11 @@ public class ResourceImpl implements Resource {
|
||||
private final TimePoint endTime;
|
||||
private final String deviceSerialNumber;
|
||||
private final int[] dataTypes;
|
||||
private final Permission[] permissions;
|
||||
private final Iterable<Permission> permissions;
|
||||
private final boolean blob;
|
||||
|
||||
public ResourceImpl(long id, TimePoint startTime, TimePoint endTime, String deviceSerialNumber, int[] dataTypes,
|
||||
Permission[] permissions, boolean blob) {
|
||||
Iterable<Permission> permissions, boolean blob) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.startTime = startTime;
|
||||
@@ -51,7 +51,7 @@ public class ResourceImpl implements Resource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission[] getPermissions() {
|
||||
public Iterable<Permission> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user