Revised CallPath to handle null or empty paths correctly.
Updated ResourceQuery callspec to accept a list in the response body.
This commit is contained in:
parent
eac1505670
commit
f1e278c4c0
|
@ -63,7 +63,10 @@ public class ResourceQueryClient<I extends ID, R extends RestResource<I, R>, Q>
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> WebServiceCallSpec generateCallSpec(CallPath callPath) {
|
private static <T> WebServiceCallSpec generateCallSpec(CallPath callPath) {
|
||||||
return new WebServiceCallSpec.Builder(callPath).supportsHttpMethod(HttpMethod.GET).build();
|
return new WebServiceCallSpec.Builder(callPath)
|
||||||
|
.supportsHttpMethod(HttpMethod.GET)
|
||||||
|
.addResponseBodyParam(TypedKeysQuery.RESOURCE_LIST)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
|
|
@ -25,14 +25,15 @@ import com.google.gson.webservice.definition.internal.utils.Pair;
|
||||||
*/
|
*/
|
||||||
public final class CallPath {
|
public final class CallPath {
|
||||||
|
|
||||||
private static final double IGNORE_VERSION = -1D;
|
/** Visible for testing only */
|
||||||
|
static final double IGNORE_VERSION = -1D;
|
||||||
private final String path;
|
private final String path;
|
||||||
private final double version;
|
private final double version;
|
||||||
private final long resourceId;
|
private final long resourceId;
|
||||||
|
|
||||||
public CallPath(String path) {
|
public CallPath(String path) {
|
||||||
if (path == null) {
|
if (path == null || path.trim().equals("")) {
|
||||||
this.path = null;
|
this.path = path;
|
||||||
version = IGNORE_VERSION;
|
version = IGNORE_VERSION;
|
||||||
resourceId = ID.INVALID_ID;
|
resourceId = ID.INVALID_ID;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.gson.webservice.definition;
|
package com.google.gson.webservice.definition;
|
||||||
|
|
||||||
|
import com.google.gson.rest.definition.ID;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,14 +30,14 @@ public class CallPathTest extends TestCase {
|
||||||
CallPath path = new CallPath("/1.0/rest/service1");
|
CallPath path = new CallPath("/1.0/rest/service1");
|
||||||
assertEquals("/rest/service1", path.get());
|
assertEquals("/rest/service1", path.get());
|
||||||
assertEquals(1D, path.getVersion());
|
assertEquals(1D, path.getVersion());
|
||||||
assertEquals(-1L, path.getResourceId());
|
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testVersionNotPresent() {
|
public void testVersionNotPresent() {
|
||||||
CallPath path = new CallPath("/rest/service1");
|
CallPath path = new CallPath("/rest/service1");
|
||||||
assertEquals("/rest/service1", path.get());
|
assertEquals("/rest/service1", path.get());
|
||||||
assertEquals(-1D, path.getVersion());
|
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||||
assertEquals(-1L, path.getResourceId());
|
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResourceIdPresent() {
|
public void testResourceIdPresent() {
|
||||||
|
@ -56,4 +58,25 @@ public class CallPathTest extends TestCase {
|
||||||
assertEquals("/rest/service53", path.get());
|
assertEquals("/rest/service53", path.get());
|
||||||
assertEquals(323222L, path.getResourceId());
|
assertEquals(323222L, path.getResourceId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNullPath() {
|
||||||
|
CallPath path = new CallPath(null);
|
||||||
|
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||||
|
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||||
|
assertNull(path.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEmptyPath() {
|
||||||
|
CallPath path = new CallPath("");
|
||||||
|
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||||
|
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||||
|
assertEquals("", path.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWhiteSpacePath() {
|
||||||
|
CallPath path = new CallPath("\r\n");
|
||||||
|
assertEquals(CallPath.IGNORE_VERSION, path.getVersion());
|
||||||
|
assertEquals(ID.INVALID_ID, path.getResourceId());
|
||||||
|
assertEquals("\r\n", path.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user