public void Test_GroupScopeAsync() { KiiGroup group = Kii.Group("test_group"); group.Save(); group.Topic("group_topic").Save(); CountDownLatch cd = new CountDownLatch(1); IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null; Exception exception = null; KiiTopic topic = group.Topic("group_topic"); topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => { entries = result; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 20))) { Assert.Fail("Callback not fired."); } Assert.IsNull(exception); Assert.AreEqual(4, entries.Count); }
public void Test_GroupScopeTrueASync() { LogIn("test-user-00001"); client.AddResponse(204, null); string groupID = "test_group"; string topicName = "test_topic"; KiiTopic topic = KiiGroup.GroupWithID(groupID).Topic(topicName); CountDownLatch cd = new CountDownLatch(1); bool? existence = null; Exception exception = null; topic.Exists((bool?b, Exception e) => { existence = b; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsTrue(existence.Value); Assert.IsNull(exception); Assert.AreEqual(KiiHttpMethod.HEAD, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "groups", groupID, "topics", topicName), client.RequestUrl [0]); }
public void Test_UserScopeFalseASync() { LogIn("test-user-00001"); client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.TOPIC_NOT_FOUND)); string userID = "test_user"; string topicName = "test_topic"; KiiTopic topic = KiiUser.UserWithID(userID).Topic(topicName); CountDownLatch cd = new CountDownLatch(1); bool? existence = null; Exception exception = null; topic.Exists((bool?b, Exception e) => { existence = b; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsFalse(existence.Value); Assert.IsNull(exception); Assert.AreEqual(KiiHttpMethod.HEAD, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "topics", topicName), client.RequestUrl [0]); }
public void Test_AppScopeSync() { LogIn("test-user-00001"); client.AddResponse(200, RESPONSE_BODY); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); IList <KiiACLEntry <KiiTopic, TopicAction> > entries = topic.ListAclEntries(); Assert.AreEqual(6, entries.Count); Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [0].Action); Assert.AreEqual("UUUU-5555-6666-7777-8888", ((KiiUser)entries [0].Subject).ID); Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [1].Action); Assert.AreEqual("GGGG-5555-6666-7777-8888", ((KiiGroup)entries[1].Subject).ID); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [2].Action); Assert.AreEqual(KiiAnonymousUser.Get(), entries [2].Subject); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [3].Action); Assert.AreEqual(KiiAnyAuthenticatedUser.Get(), entries [3].Subject); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [4].Action); Assert.AreEqual("UUUU-1111-2222-3333-4444", ((KiiUser)entries [4].Subject).ID); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [5].Action); Assert.AreEqual("GGGG-1111-2222-3333-4444", ((KiiGroup)entries[5].Subject).ID); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics", topicName, "acl"), client.RequestUrl [0]); }
public void Test_Status403ASync() { LogIn("test-user-00001"); client.AddResponse(new ForbiddenException("", null, "")); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); CountDownLatch cd = new CountDownLatch(1); bool? existence = null; Exception exception = null; topic.Exists((bool?b, Exception e) => { existence = b; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsFalse(existence.HasValue); Assert.IsNotNull(exception); Assert.IsInstanceOfType(typeof(ForbiddenException), exception); Assert.AreEqual(KiiHttpMethod.HEAD, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics", topicName), client.RequestUrl [0]); }
public void Test_NotLoggedInSync() { string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); topic.ListAclEntries(); }
public void Test_UserScope404ASync() { LogIn("test-user-00001"); client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.ACL_NOT_FOUND)); string userID = "test_user"; string topicName = "test_topic"; KiiTopic topic = KiiUser.UserWithID(userID).Topic(topicName); CountDownLatch cd = new CountDownLatch(1); IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null; Exception exception = null; topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => { entries = result; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsNull(entries); Assert.IsInstanceOfType(typeof(NotFoundException), exception); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "topics", topicName, "acl"), client.RequestUrl [0]); }
public void Test_AnonymousSync() { KiiUser.LogOut(); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); topic.Exists(); }
public void Test_AppScope404Sync() { LogIn("test-user-00001"); client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.ACL_NOT_FOUND)); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); topic.ListAclEntries(); }
public void Test_Status403Sync() { LogIn("test-user-00001"); client.AddResponse(new ForbiddenException("", null, "")); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); topic.Exists(); }
public void Test_0007_SendMessage_Null() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); topic.SendMessage(null); }
public void Test_Delete_By_Anonymous() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); Kii.LogOut(); topic.Delete(); }
public void Test_0001_Subscribe_Topic() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); KiiUser.CurrentUser.PushSubscription.Subscribe(topic); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/subscriptions/users/user1234", client.RequestUrl [0]); }
public void Test_0003_Save() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); topic.Save(); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic", client.RequestUrl [0]); }
public void Test_AppScopeTrueSync() { LogIn("test-user-00001"); client.AddResponse(204, null); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); Assert.IsTrue(topic.Exists()); Assert.AreEqual(KiiHttpMethod.HEAD, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics", topicName), client.RequestUrl [0]); }
public void Test_AppScopeFalseSync() { LogIn("test-user-00001"); client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.TOPIC_NOT_FOUND)); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); Assert.IsFalse(topic.Exists()); Assert.AreEqual(KiiHttpMethod.HEAD, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics", topicName), client.RequestUrl [0]); }
public void Test_0002_Delete_Async() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); topic.Delete((KiiTopic target, Exception e) => { Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic", client.RequestUrl [0]); }); }
public void Test_0009_Unsubscribe_Topic_Async() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); KiiUser.CurrentUser.PushSubscription.Unsubscribe(topic, (KiiSubscribable target, Exception e) => { Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/subscriptions/users/user1234", client.RequestUrl [0]); }); }
public void Test_0014_IsSubscribed_Topic_false() { this.LogIn(); ClearClientRequest(); client.AddResponse(404, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); bool isSubscribed = KiiUser.CurrentUser.PushSubscription.IsSubscribed(topic); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/subscriptions/users/user1234", client.RequestUrl [0]); Assert.IsFalse(isSubscribed); }
public void Test_0008_SendMessage_Null_Async() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); topic.SendMessage(null, (KiiPushMessage msg, Exception e) => { Assert.IsNotNull(e); Assert.IsInstanceOfType(typeof(ArgumentNullException), e); }); }
public void Test_0017_IsSubscribed_Topic_Async_true() { this.LogIn(); ClearClientRequest(); client.AddResponse(204, null); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); KiiUser.CurrentUser.PushSubscription.IsSubscribed(topic, (KiiSubscribable target, bool isSubscribed, Exception e) => { Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/subscriptions/users/user1234", client.RequestUrl [0]); Assert.IsTrue(isSubscribed); }); }
public void Test_Save_By_Anonymous() { this.LogIn(); ClearClientRequest(); client.AddResponse(new CloudException(401, null)); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); Kii.LogOut(); try { topic.Save(); Assert.Fail("CloudException has not thrown"); } catch (CloudException e) { // pass } Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic", client.RequestUrl [0]); }
public void Test_0005_SendMessage() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiPushMessageData data = new KiiPushMessageData(); data.Put("payload", "abc"); KiiPushMessage message = KiiPushMessage.BuildWith(data).Build(); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); topic.SendMessage(message); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); Assert.AreEqual("{\"data\":{\"payload\":\"abc\"},\"gcm\":{\"enabled\":true},\"apns\":{\"enabled\":true},\"mqtt\":{\"enabled\":true}}", client.RequestBody [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/messages", client.RequestUrl [0]); }
public void KiiTopicAclTest() { this.LogIn(); KiiTopic appTopicA = Kii.Topic("A"); KiiTopic appTopicA_ = Kii.Topic("A"); KiiTopic appTopicB = Kii.Topic("B"); KiiTopic usrTopicA = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234")).Topic("A"); KiiTopicACL acl1 = null; KiiTopicACL acl2 = null; // same object acl1 = new KiiTopicACL(appTopicA); acl2 = new KiiTopicACL(appTopicA_); Assert.IsTrue(acl1.Equals(acl2)); Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode()); Assert.IsFalse(acl1 == acl2); // same object and action acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC); acl2 = new KiiTopicACL(appTopicA_, TopicAction.SEND_MESSAGE_TO_TOPIC); Assert.IsTrue(acl1.Equals(acl2)); Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode()); Assert.IsFalse(acl1 == acl2); // different action acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC); acl2 = new KiiTopicACL(appTopicA_, TopicAction.SUBSCRIBE_TO_TOPIC); Assert.IsFalse(acl1.Equals(acl2)); Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode()); Assert.IsFalse(acl1 == acl2); // different topic name acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC); acl2 = new KiiTopicACL(appTopicB, TopicAction.SEND_MESSAGE_TO_TOPIC); Assert.IsFalse(acl1.Equals(acl2)); Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode()); Assert.IsFalse(acl1 == acl2); // different scope of bucket acl1 = new KiiTopicACL(appTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC); acl2 = new KiiTopicACL(usrTopicA, TopicAction.SEND_MESSAGE_TO_TOPIC); Assert.IsFalse(acl1.Equals(acl2)); Assert.IsFalse(acl1.GetHashCode() == acl2.GetHashCode()); Assert.IsFalse(acl1 == acl2); }
public void Test_NotLoggedInASync() { string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); CountDownLatch cd = new CountDownLatch(1); IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null; Exception exception = null; topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => { entries = result; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsNull(entries); Assert.IsInstanceOfType(typeof(InvalidOperationException), exception); }
public void Test_UserScopeASync() { LogIn("test-user-00001"); client.AddResponse(200, RESPONSE_BODY); string userID = "test_user"; string topicName = "test_topic"; KiiTopic topic = KiiUser.UserWithID(userID).Topic(topicName); CountDownLatch cd = new CountDownLatch(1); IList <KiiACLEntry <KiiTopic, TopicAction> > entries = null; Exception exception = null; topic.ListAclEntries((IList <KiiACLEntry <KiiTopic, TopicAction> > result, Exception e) => { entries = result; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsNull(exception); Assert.AreEqual(6, entries.Count); Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [0].Action); Assert.AreEqual("UUUU-5555-6666-7777-8888", ((KiiUser)entries [0].Subject).ID); Assert.AreEqual(TopicAction.SEND_MESSAGE_TO_TOPIC, entries [1].Action); Assert.AreEqual("GGGG-5555-6666-7777-8888", ((KiiGroup)entries[1].Subject).ID); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [2].Action); Assert.AreEqual(KiiAnonymousUser.Get(), entries [2].Subject); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [3].Action); Assert.AreEqual(KiiAnyAuthenticatedUser.Get(), entries [3].Subject); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [4].Action); Assert.AreEqual("UUUU-1111-2222-3333-4444", ((KiiUser)entries [4].Subject).ID); Assert.AreEqual(TopicAction.SUBSCRIBE_TO_TOPIC, entries [5].Action); Assert.AreEqual("GGGG-1111-2222-3333-4444", ((KiiGroup)entries[5].Subject).ID); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]); Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "users", userID, "topics", topicName, "acl"), client.RequestUrl [0]); }
public void Test_AnonymousASync() { KiiUser.LogOut(); string topicName = "test_topic"; KiiTopic topic = Kii.Topic(topicName); CountDownLatch cd = new CountDownLatch(1); bool? existence = null; Exception exception = null; topic.Exists((bool?b, Exception e) => { existence = b; exception = e; cd.Signal(); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 3))) { Assert.Fail("Callback not fired."); } Assert.IsFalse(existence.HasValue); Assert.IsNotNull(exception); Assert.IsInstanceOfType(typeof(InvalidOperationException), exception); }
public void Test_SendMessage_Anonymous() { this.LogIn(); ClearClientRequest(); client.AddResponse(new CloudException(401, null)); KiiPushMessageData data = new KiiPushMessageData(); data.Put("payload", "abc"); KiiPushMessage message = KiiPushMessage.BuildWith(data).Build(); KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic"); Kii.LogOut(); try { topic.SendMessage(message); Assert.Fail("CloudException has not thrown"); } catch (CloudException e) { // pass } Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); Assert.AreEqual("{\"data\":{\"payload\":\"abc\"},\"gcm\":{\"enabled\":true},\"apns\":{\"enabled\":true},\"mqtt\":{\"enabled\":true}}", client.RequestBody [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/users/user1234/topics/my_topic/push/messages", client.RequestUrl [0]); }
/// <summary> /// Get instance of app scope topic. /// The topic bound to the application. /// </summary> /// <param name="name">topic name.</param> /// <returns>KiiTopic bound to the application.</returns> /// <remarks></remarks> public static KiiTopic Topic(string name) { KiiTopic topic = new KiiTopic(null, name); return(topic); }