diff --git a/tarantool-client/src/test/java/io/tarantool/client/integration/tdg/TDGClientTest.java b/tarantool-client/src/test/java/io/tarantool/client/integration/tdg/TDGClientTest.java index 99b98b74..e0e66afc 100644 --- a/tarantool-client/src/test/java/io/tarantool/client/integration/tdg/TDGClientTest.java +++ b/tarantool-client/src/test/java/io/tarantool/client/integration/tdg/TDGClientTest.java @@ -233,4 +233,50 @@ void testTDGThrowError() { Assertions.assertEquals( "Type \"NoSpace\" not found", tarantoolSlashErrorsException.getReason().getErr()); } + + @Test + void testServiceWithArgs() { + + // service name from config file! + final String serviceName = "get_by_id"; + + final TarantoolDataGridSpace space = client.space("User"); + final Map user = + new HashMap() { + { + put("age", 1); + put("name", "nick"); + } + }; + + final Map insertedUser = space.put(user).join(); + Assertions.assertEquals(user, insertedUser); + + final Map serviceArgs = new HashMap<>(); + serviceArgs.put("model_type", "User"); + serviceArgs.put("id", 1); + + final List callResult = + client.call("call_service", Arrays.asList(serviceName, serviceArgs)).join().get(); + // 0 - response, 1 - error + Assertions.assertEquals(2, callResult.size()); + Assertions.assertInstanceOf(Map.class, callResult.get(0)); + Assertions.assertEquals(user, callResult.get(0)); + } + + @Test + void testServiceWithoutArgs() { + + // service name from config file! + final String serviceName = "hello"; + + final String expectedString = "hello!"; + final List callResult = + client.call("call_service", Collections.singletonList(serviceName)).join().get(); + + // 0 - response, 1 - error + Assertions.assertEquals(2, callResult.size()); + Assertions.assertInstanceOf(String.class, callResult.get(0)); + Assertions.assertEquals(expectedString, callResult.get(0)); + } } diff --git a/tarantool-shared-resources/tdg/test-cluster-configuration/config.yml b/tarantool-shared-resources/tdg/test-cluster-configuration/config.yml index 521667b0..afa6c283 100644 --- a/tarantool-shared-resources/tdg/test-cluster-configuration/config.yml +++ b/tarantool-shared-resources/tdg/test-cluster-configuration/config.yml @@ -1,3 +1,16 @@ --- types: __file: model.avsc + +services: + get_by_id: + doc: "Return User data by id" + function: services.users.get_by_id + args: + model_type: string + id: int + return_type: User + hello: + doc: "Return 'hello!' string" + function: services.users.say_hello + return_type: string diff --git a/tarantool-shared-resources/tdg/test-cluster-configuration/src/services/users.lua b/tarantool-shared-resources/tdg/test-cluster-configuration/src/services/users.lua new file mode 100644 index 00000000..fed0d07f --- /dev/null +++ b/tarantool-shared-resources/tdg/test-cluster-configuration/src/services/users.lua @@ -0,0 +1,10 @@ +return { + -- Args must be the table! + get_by_id = function(args) + local repository = require("repository") + return repository.get(args.model_type, args.id); + end, + say_hello = function() + return 'hello!'; + end +}