From a35944bfe2fabda4816e4396f92280ee9fcf789d Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Fri, 15 Jul 2011 20:16:43 +0000 Subject: [PATCH] THRIFT-1238 Thrift JS client cannot read map of structures(TestCase) Patch: Henrique Mendonca git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1147301 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/thrift/server/ServerTestBase.java | 19 +++++--- lib/js/test/build.xml | 5 ++- lib/js/test/test.html | 44 +++++++++++++++++-- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/java/test/org/apache/thrift/server/ServerTestBase.java b/lib/java/test/org/apache/thrift/server/ServerTestBase.java index 13a8be69..b9974c4a 100644 --- a/lib/java/test/org/apache/thrift/server/ServerTestBase.java +++ b/lib/java/test/org/apache/thrift/server/ServerTestBase.java @@ -185,13 +185,10 @@ public abstract class ServerTestBase extends TestCase { Insanity crazy = new Insanity(); crazy.userMap = new HashMap(); - crazy.xtructs = new ArrayList(); - crazy.userMap.put(Numberz.EIGHT, (long)8); - crazy.xtructs.add(goodbye); - - Insanity looney = new Insanity(); crazy.userMap.put(Numberz.FIVE, (long)5); + crazy.xtructs = new ArrayList(); + crazy.xtructs.add(goodbye); crazy.xtructs.add(hello); HashMap first_map = new HashMap(); @@ -200,6 +197,7 @@ public abstract class ServerTestBase extends TestCase { first_map.put(Numberz.TWO, crazy); first_map.put(Numberz.THREE, crazy); + Insanity looney = new Insanity(); second_map.put(Numberz.SIX, looney); Map> insane = @@ -389,6 +387,7 @@ public abstract class ServerTestBase extends TestCase { testStruct(testClient); testNestedStruct(testClient); testMap(testClient); + testStringMap(testClient); testSet(testClient); testList(testClient); testEnum(testClient); @@ -429,6 +428,16 @@ public abstract class ServerTestBase extends TestCase { assertEquals(mapout, mapin); } + private void testStringMap(ThriftTest.Client testClient) throws TException { + Map mapout = new HashMap(); + mapout.put("a", "123"); + mapout.put(" x y ", " with spaces "); + mapout.put("same", "same"); + mapout.put("0", "numeric key"); + Map mapin = testClient.testStringMap(mapout); + assertEquals(mapout, mapin); + } + private void testNestedMap(ThriftTest.Client testClient) throws TException { Map> mm = testClient.testMapMap(1); diff --git a/lib/js/test/build.xml b/lib/js/test/build.xml index bd2faf25..32316a16 100644 --- a/lib/js/test/build.xml +++ b/lib/js/test/build.xml @@ -59,7 +59,10 @@ - + + + + diff --git a/lib/js/test/test.html b/lib/js/test/test.html index bd124afa..5039edb4 100644 --- a/lib/js/test/test.html +++ b/lib/js/test/test.html @@ -215,9 +215,47 @@ module("Insanity"); test("testInsanity", function() { - var insanity; - var res = client.testInsanity(insanity); - ok(res); + var insanity = { + "1":{ + "3":{ + "userMap":{ "8":8, "5":5 }, + "xtructs":[{ + "string_thing":"Goodbye4", + "byte_thing":4, + "i32_thing":4, + "i64_thing":4 + }, + { + "string_thing":"Hello2", + "byte_thing":2, + "i32_thing":2, + "i64_thing":2 + } + ] + }, + "2":{ + "userMap":{ "8":8, "5":5 }, + "xtructs":[{ + "string_thing":"Goodbye4", + "byte_thing":4, + "i32_thing":4, + "i64_thing":4 + }, + { + "string_thing":"Hello2", + "byte_thing":2, + "i32_thing":2, + "i64_thing":2 + } + ] + } + }, + "2":{ "6":{ "userMap":null, "xtructs":null } } + }; + var res = client.testInsanity(""); + ok(res, JSON.stringify(res)); + ok(insanity, JSON.stringify(insanity)); + equals(JSON.stringify(res), JSON.stringify(insanity)) //TODO: read and compare maps recursively }); -- 2.17.1