Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
#200 - fixed assertion that was ignoring that the returned save() dat…
Browse files Browse the repository at this point in the history
…a could represent an expanded object graph
  • Loading branch information
lhazlewood committed Jun 3, 2015
1 parent 2310d21 commit ea90183
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class ApiKeyIT extends ClientIT {

def client = buildClient(false)
def retrievedApiKey = client.getResource(apiKey.href, ApiKey)
assertEquals apiKey, retrievedApiKey
assertEquals apiKey.href, retrievedApiKey.href
assertEquals apiKey.id, retrievedApiKey.id

//TODO test expansion for this scenario when it gets fixed in the DefaultDataStore
}
Expand Down
32 changes: 25 additions & 7 deletions impl/src/main/java/com/stormpath/sdk/impl/ds/DefaultDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1031,16 +1031,34 @@ private boolean isApiKeyCollectionQuery(Class clazz, QueryString qs) {
* @since 1.0.RC3
*/
@SuppressWarnings({ "SuspiciousMethodCalls", "unchecked" })
private Enlistment toEnlistment(Map data) {
private Enlistment toEnlistment(final Map data) {

Assert.notEmpty(data, "data cannot be null or empty.");
String href = (String)data.get("href");
Assert.hasText(href, "href cannot be null or empty.");

Map modified = new LinkedHashMap<String, Object>(data.size());

//since 1.0.RC4.3 - need to recursively add enlistments if the data is expanded:
for(Object o : data.entrySet()) {
Map.Entry entry = (Map.Entry)o;
Object key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map && isMaterialized((Map<String,?>)value)) {
value = toEnlistment((Map)value);
}
modified.put(key, value);
}

Enlistment enlistment;
Object responseHref = data.get("href");
if (this.hrefMapStore.containsKey(responseHref)) {
enlistment = this.hrefMapStore.get(responseHref);
enlistment.setProperties((Map<String, Object>) data);
if (this.hrefMapStore.containsKey(href)) {
enlistment = this.hrefMapStore.get(href);
enlistment.setProperties((Map<String, Object>) modified);
} else {
enlistment = new Enlistment((Map<String, Object>) data);
this.hrefMapStore.put((String) responseHref, enlistment);
enlistment = new Enlistment((Map<String, Object>) modified);
this.hrefMapStore.put(href, enlistment);
}

return enlistment;
}
}

0 comments on commit ea90183

Please sign in to comment.