Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> user =
new HashMap<String, Object>() {
{
put("age", 1);
put("name", "nick");
}
};

final Map<?, ?> insertedUser = space.put(user).join();
Assertions.assertEquals(user, insertedUser);

final Map<String, Object> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
Loading