Skip to content

Commit

Permalink
Nakama Java 0.5.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Nov 21, 2017
1 parent 95a8571 commit 113d21a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

139 changes: 98 additions & 41 deletions src/test/java/com/heroiclabs/nakama/StorageListMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Session> deferred1 = client1.register(auth1);
deferred1.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
@Override
public Deferred<Session> call(Session session) throws Exception {
return client1.connect(session);
}
}).addCallback(new Callback<Session, Session>() {
@Override
public Session call(Session session) throws Exception {
session1 = session;
return session;
}
}).join(2000);

AuthenticateMessage auth2 = AuthenticateMessage.Builder.custom(UUID.randomUUID().toString());
final Deferred<Session> deferred2 = client2.register(auth2);
deferred2.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
@Override
public Deferred<Session> call(Session session) throws Exception {
return client2.connect(session);
}
}).addCallback(new Callback<Session, Session>() {
@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<Session> deferred = client.register(auth);
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
@Override
public Deferred<Session> call(Session session) throws Exception {
return client.connect(session);
}
}).addCallbackDeferring(new Callback<Deferred<ResultSet<StorageRecord>>, Session>() {
@Override
public Deferred<ResultSet<StorageRecord>> call(Session session) throws Exception {
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderBucket(bucket)
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderBucket(bucket)
.collection("collection")
.build();
return client.send(list);
}
}).addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
final Deferred<ResultSet<StorageRecord>> deferred = client1.send(list);
deferred.addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
@Override
public ResultSet<StorageRecord> call(ResultSet<StorageRecord> results) throws Exception {
Assert.assertEquals(0, results.getResults().size());
Expand All @@ -71,33 +96,19 @@ public ResultSet<StorageRecord> call(ResultSet<StorageRecord> 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<Session> deferred = client.register(auth);
deferred.addCallbackDeferring(new Callback<Deferred<Session>, Session>() {
@Override
public Deferred<Session> call(Session session) throws Exception {
userId = session.getId();
return client.connect(session);
}
}).addCallbackDeferring(new Callback<Deferred<ResultSet<RecordId>>, Session>() {
@Override
public Deferred<ResultSet<RecordId>> call(Session session) throws Exception {
final CollatedMessage<ResultSet<RecordId>> write = StorageWriteMessage.Builder.newBuilder()
final CollatedMessage<ResultSet<RecordId>> 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.OWNER_READ, StorageRecord.PermissionWrite.OWNER_WRITE)
.build();
return client.send(write);
}
}).addCallback(new Callback<ResultSet<RecordId>, ResultSet<RecordId>>() {
final Deferred<ResultSet<RecordId>> deferred = client1.send(write);
deferred.addCallback(new Callback<ResultSet<RecordId>, ResultSet<RecordId>>() {
@Override
public ResultSet<RecordId> call(ResultSet<RecordId> records) throws Exception {
Assert.assertEquals(3, records.getResults().size());
Expand All @@ -106,11 +117,11 @@ public ResultSet<RecordId> call(ResultSet<RecordId> records) throws Exception {
}).addCallbackDeferring(new Callback<Deferred<ResultSet<StorageRecord>>, ResultSet<RecordId>>() {
@Override
public Deferred<ResultSet<StorageRecord>> call(ResultSet<RecordId> records) throws Exception {
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderUserId(userId)
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderUserId(session1.getId())
.bucket(bucket)
.collection("collection")
.build();
return client.send(list);
return client1.send(list);
}
}).addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
@Override
Expand All @@ -122,7 +133,53 @@ public ResultSet<StorageRecord> call(ResultSet<StorageRecord> 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<ResultSet<RecordId>> 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<ResultSet<RecordId>> deferred = client1.send(write);
deferred.addCallback(new Callback<ResultSet<RecordId>, ResultSet<RecordId>>() {
@Override
public ResultSet<RecordId> call(ResultSet<RecordId> records) throws Exception {
Assert.assertEquals(3, records.getResults().size());
return records;
}
}).addCallbackDeferring(new Callback<Deferred<ResultSet<StorageRecord>>, ResultSet<RecordId>>() {
@Override
public Deferred<ResultSet<StorageRecord>> call(ResultSet<RecordId> records) throws Exception {
final CollatedMessage<ResultSet<StorageRecord>> list = StorageListMessage.Builder.newBuilderBucket(bucket)
.collection("collection")
.build();
return client2.send(list);
}
}).addCallback(new Callback<ResultSet<StorageRecord>, ResultSet<StorageRecord>>() {
@Override
public ResultSet<StorageRecord> call(ResultSet<StorageRecord> 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());
Expand Down

0 comments on commit 113d21a

Please sign in to comment.