From 113d21a1e1c84ed58df026c84b7dddb044b10409 Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Tue, 21 Nov 2017 18:58:00 +0000 Subject: [PATCH] Nakama Java 0.5.0 release. --- CHANGELOG.md | 2 + build.gradle | 2 +- server | 2 +- .../nakama/GroupsFetchMessageTest.java | 4 - .../nakama/StorageListMessageTest.java | 139 ++++++++++++------ 5 files changed, 102 insertions(+), 47 deletions(-) delete mode 100644 src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c589fd9..ef4fb3c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project are documented below. The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/). ## [Unreleased] + +## [0.5.0] - 2017-11-21 ### Added - Support for In-App Notifications feature. - Support for Friends feature. diff --git a/build.gradle b/build.gradle index 52428ed9..9adb2241 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ plugins { } group = 'com.heroiclabs.nakama' -version = '0.5.0-SNAPSHOT' +version = '0.5.0' def description = 'Android optimized Java client for Nakama server.' sourceCompatibility = 1.7 diff --git a/server b/server index b6f073bb..ca88ea9c 160000 --- a/server +++ b/server @@ -1 +1 @@ -Subproject commit b6f073bb4ef601cee99c8daf61fb8308f05fd817 +Subproject commit ca88ea9ce6d6d002c72cdc03f665d0936b35e054 diff --git a/src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java b/src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java deleted file mode 100644 index cbe08cc6..00000000 --- a/src/test/java/com/heroiclabs/nakama/GroupsFetchMessageTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.heroiclabs.nakama; - -public class GroupsFetchMessageTest { -} diff --git a/src/test/java/com/heroiclabs/nakama/StorageListMessageTest.java b/src/test/java/com/heroiclabs/nakama/StorageListMessageTest.java index e9d2b536..e0c04c91 100644 --- a/src/test/java/com/heroiclabs/nakama/StorageListMessageTest.java +++ b/src/test/java/com/heroiclabs/nakama/StorageListMessageTest.java @@ -24,41 +24,66 @@ public class StorageListMessageTest { - private Client client; - private String userId; + private Client client1; + private Client client2; + + private Session session1; + private Session session2; @Before - public void init() { - client = DefaultClient.builder("defaultkey").build(); - Assert.assertNotNull(client); + public void init() throws Exception { + client1 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client1); + + client2 = DefaultClient.defaults("defaultkey"); + Assert.assertNotNull(client2); + + AuthenticateMessage auth1 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred1 = client1.register(auth1); + deferred1.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client1.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session1 = session; + return session; + } + }).join(2000); + + AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString()); + final Deferred deferred2 = client2.register(auth2); + deferred2.addCallbackDeferring(new Callback, Session>() { + @Override + public Deferred call(Session session) throws Exception { + return client2.connect(session); + } + }).addCallback(new Callback() { + @Override + public Session call(Session session) throws Exception { + session2 = session; + return session; + } + }).join(2000); } @After public void teardown() throws Exception { - client.disconnect().join(2000); + client1.disconnect().join(2000); + client2.disconnect().join(2000); } @Test public void testListNoRecords() throws Exception { - final String deviceId = UUID.randomUUID().toString(); - final AuthenticateMessage auth = AuthenticateMessage.Builder.device(deviceId); final String bucket = UUID.randomUUID().toString(); - final Deferred deferred = client.register(auth); - deferred.addCallbackDeferring(new Callback, Session>() { - @Override - public Deferred call(Session session) throws Exception { - return client.connect(session); - } - }).addCallbackDeferring(new Callback>, Session>() { - @Override - public Deferred> call(Session session) throws Exception { - final CollatedMessage> list = StorageListMessage.Builder.newBuilderBucket(bucket) + final CollatedMessage> list = StorageListMessage.Builder.newBuilderBucket(bucket) .collection("collection") .build(); - return client.send(list); - } - }).addCallback(new Callback, ResultSet>() { + final Deferred> deferred = client1.send(list); + deferred.addCallback(new Callback, ResultSet>() { @Override public ResultSet call(ResultSet results) throws Exception { Assert.assertEquals(0, results.getResults().size()); @@ -71,23 +96,10 @@ public ResultSet call(ResultSet results) throws Ex @Test public void testList() throws Exception { - final String deviceId = UUID.randomUUID().toString(); - final AuthenticateMessage auth = AuthenticateMessage.Builder.device(deviceId); - final String bucket = UUID.randomUUID().toString(); final String value = "{\"foo\":\"bar\"}"; - final Deferred deferred = client.register(auth); - deferred.addCallbackDeferring(new Callback, Session>() { - @Override - public Deferred call(Session session) throws Exception { - userId = session.getId(); - return client.connect(session); - } - }).addCallbackDeferring(new Callback>, Session>() { - @Override - public Deferred> call(Session session) throws Exception { - final CollatedMessage> write = StorageWriteMessage.Builder.newBuilder() + final CollatedMessage> write = StorageWriteMessage.Builder.newBuilder() .record(bucket, "collection", "record2", value, StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE) .record(bucket, "collection", "record1", value, @@ -95,9 +107,8 @@ public Deferred> call(Session session) throws Exception { .record(bucket, "collection", "record3", value, StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE) .build(); - return client.send(write); - } - }).addCallback(new Callback, ResultSet>() { + final Deferred> deferred = client1.send(write); + deferred.addCallback(new Callback, ResultSet>() { @Override public ResultSet call(ResultSet records) throws Exception { Assert.assertEquals(3, records.getResults().size()); @@ -106,11 +117,11 @@ public ResultSet call(ResultSet records) throws Exception { }).addCallbackDeferring(new Callback>, ResultSet>() { @Override public Deferred> call(ResultSet records) throws Exception { - final CollatedMessage> list = StorageListMessage.Builder.newBuilderUserId(userId) + final CollatedMessage> list = StorageListMessage.Builder.newBuilderUserId(session1.getId()) .bucket(bucket) .collection("collection") .build(); - return client.send(list); + return client1.send(list); } }).addCallback(new Callback, ResultSet>() { @Override @@ -122,7 +133,53 @@ public ResultSet call(ResultSet results) throws Ex for (StorageRecord record : results.getResults()) { Assert.assertEquals(bucket, record.getBucket()); Assert.assertEquals("collection", record.getCollection()); - Assert.assertEquals(userId, record.getUserId()); + Assert.assertEquals(session1.getId(), record.getUserId()); + Assert.assertEquals(value, record.getValue()); + } + Assert.assertNull(results.getCursor()); + return results; + } + }); + deferred.join(2000); + } + + @Test + public void testListOtherUser() throws Exception { + final String bucket = UUID.randomUUID().toString(); + final String value = "{\"foo\":\"bar\"}"; + + final CollatedMessage> write = StorageWriteMessage.Builder.newBuilder() + .record(bucket, "collection", "record2", value, + StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE) + .record(bucket, "collection", "record1", value, + StorageRecord.PermissionRead.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE) + .record(bucket, "collection", "record3", value, + StorageRecord.PermissionRead.PUBLIC_READ, StorageRecord.PermissionWrite.OWNER_WRITE) + .build(); + final Deferred> deferred = client1.send(write); + deferred.addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet records) throws Exception { + Assert.assertEquals(3, records.getResults().size()); + return records; + } + }).addCallbackDeferring(new Callback>, ResultSet>() { + @Override + public Deferred> call(ResultSet records) throws Exception { + final CollatedMessage> list = StorageListMessage.Builder.newBuilderBucket(bucket) + .collection("collection") + .build(); + return client2.send(list); + } + }).addCallback(new Callback, ResultSet>() { + @Override + public ResultSet call(ResultSet results) throws Exception { + Assert.assertEquals(1, results.getResults().size()); + Assert.assertEquals("record3", results.getResults().get(0).getKey()); + for (StorageRecord record : results.getResults()) { + Assert.assertEquals(bucket, record.getBucket()); + Assert.assertEquals("collection", record.getCollection()); + Assert.assertEquals(session1.getId(), record.getUserId()); Assert.assertEquals(value, record.getValue()); } Assert.assertNull(results.getCursor());