public void Test_AppScopeASync()
        {
            LogIn("test-user-00001");
            client.AddResponse(200, RESPONSE_BODY);
            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(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, "topics", topicName, "acl"), client.RequestUrl [0]);
        }
        public void KiiBucketAclTest()
        {
            KiiBucketAcl acl1 = new KiiBucketAcl(Kii.Bucket("AA"), BucketAction.CREATE_OBJECTS_IN_BUCKET);
            KiiBucketAcl acl2 = new KiiBucketAcl(Kii.Bucket("AA"), BucketAction.CREATE_OBJECTS_IN_BUCKET);

            KiiUser userA  = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userA_ = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userB  = KiiUser.CreateByUri(new Uri("kiicloud://users/userB"));
            KiiUser userC  = KiiUser.CreateByUri(new Uri("kiicloud://users/C"));

            KiiGroup groupA  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupA_ = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupB  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupB"));
            KiiGroup groupC  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/C"));

            KiiACLEntry <KiiBucket, BucketAction> aclEntry1 = null;
            KiiACLEntry <KiiBucket, BucketAction> aclEntry2 = null;

            // same user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, userA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, KiiAnonymousUser.Get());
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, userB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, KiiAnyAuthenticatedUser.Get());
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same group
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, groupA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different group
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, groupB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different subject kind
            aclEntry1 = new KiiACLEntry <KiiBucket, BucketAction>(acl1, userC);
            aclEntry2 = new KiiACLEntry <KiiBucket, BucketAction>(acl2, groupC);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
        }
        public void KiiObjectAclTest()
        {
            KiiObject    objectA = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/a"));
            KiiObjectAcl acl1    = new KiiObjectAcl(objectA, ObjectAction.READ_EXISTING_OBJECT);
            KiiObjectAcl acl2    = new KiiObjectAcl(objectA, ObjectAction.READ_EXISTING_OBJECT);

            KiiUser userA  = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userA_ = KiiUser.CreateByUri(new Uri("kiicloud://users/userA"));
            KiiUser userB  = KiiUser.CreateByUri(new Uri("kiicloud://users/userB"));
            KiiUser userC  = KiiUser.CreateByUri(new Uri("kiicloud://users/C"));

            KiiGroup groupA  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupA_ = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupA"));
            KiiGroup groupB  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/groupB"));
            KiiGroup groupC  = KiiGroup.CreateByUri(new Uri("kiicloud://groups/C"));

            KiiACLEntry <KiiObject, ObjectAction> aclEntry1 = null;
            KiiACLEntry <KiiObject, ObjectAction> aclEntry2 = null;

            // same user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, userA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, KiiAnonymousUser.Get());
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, userA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, userB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different user
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, KiiAnonymousUser.Get());
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, KiiAnyAuthenticatedUser.Get());
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // same group
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, groupA_);
            Assert.IsTrue(aclEntry1.Equals(aclEntry2));
            Assert.IsTrue(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different group
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, groupA);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, groupB);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
            // different subject kind
            aclEntry1 = new KiiACLEntry <KiiObject, ObjectAction>(acl1, userC);
            aclEntry2 = new KiiACLEntry <KiiObject, ObjectAction>(acl2, groupC);
            Assert.IsFalse(aclEntry1.Equals(aclEntry2));
            Assert.IsFalse(aclEntry1.GetHashCode() == aclEntry2.GetHashCode());
            Assert.IsFalse(aclEntry1 == aclEntry2);
        }