From f1e278c4c018c72efeabbde122bdd4c645d12070 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Thu, 11 Nov 2010 08:17:40 +0000 Subject: [PATCH] Revised CallPath to handle null or empty paths correctly. Updated ResourceQuery callspec to accept a list in the response body. --- .../query/client/ResourceQueryClient.java | 5 +++- .../gson/webservice/definition/CallPath.java | 7 +++-- .../webservice/definition/CallPathTest.java | 29 +++++++++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/wsclient/src/main/java/com/google/gson/rest/query/client/ResourceQueryClient.java b/wsclient/src/main/java/com/google/gson/rest/query/client/ResourceQueryClient.java index ff107f55..13dbfd90 100644 --- a/wsclient/src/main/java/com/google/gson/rest/query/client/ResourceQueryClient.java +++ b/wsclient/src/main/java/com/google/gson/rest/query/client/ResourceQueryClient.java @@ -63,7 +63,10 @@ public class ResourceQueryClient, Q> } private static 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"}) diff --git a/wsdef/src/main/java/com/google/gson/webservice/definition/CallPath.java b/wsdef/src/main/java/com/google/gson/webservice/definition/CallPath.java index dc0c9380..dfbe8271 100644 --- a/wsdef/src/main/java/com/google/gson/webservice/definition/CallPath.java +++ b/wsdef/src/main/java/com/google/gson/webservice/definition/CallPath.java @@ -25,14 +25,15 @@ import com.google.gson.webservice.definition.internal.utils.Pair; */ 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 double version; private final long resourceId; public CallPath(String path) { - if (path == null) { - this.path = null; + if (path == null || path.trim().equals("")) { + this.path = path; version = IGNORE_VERSION; resourceId = ID.INVALID_ID; } else { diff --git a/wsdef/src/test/java/com/google/gson/webservice/definition/CallPathTest.java b/wsdef/src/test/java/com/google/gson/webservice/definition/CallPathTest.java index c9181496..eae6d6db 100644 --- a/wsdef/src/test/java/com/google/gson/webservice/definition/CallPathTest.java +++ b/wsdef/src/test/java/com/google/gson/webservice/definition/CallPathTest.java @@ -15,6 +15,8 @@ */ package com.google.gson.webservice.definition; +import com.google.gson.rest.definition.ID; + import junit.framework.TestCase; /** @@ -28,14 +30,14 @@ public class CallPathTest extends TestCase { CallPath path = new CallPath("/1.0/rest/service1"); assertEquals("/rest/service1", path.get()); assertEquals(1D, path.getVersion()); - assertEquals(-1L, path.getResourceId()); + assertEquals(ID.INVALID_ID, path.getResourceId()); } public void testVersionNotPresent() { CallPath path = new CallPath("/rest/service1"); assertEquals("/rest/service1", path.get()); - assertEquals(-1D, path.getVersion()); - assertEquals(-1L, path.getResourceId()); + assertEquals(CallPath.IGNORE_VERSION, path.getVersion()); + assertEquals(ID.INVALID_ID, path.getResourceId()); } public void testResourceIdPresent() { @@ -56,4 +58,25 @@ public class CallPathTest extends TestCase { assertEquals("/rest/service53", path.get()); 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()); + } }