public void NotOrTest()
        {
            KiiBucket bucket = KiiUser.CurrentUser.Bucket("my_bucket");
            KiiObject obj1   = bucket.NewKiiObject();

            obj1["name"] = "foo";
            obj1.Save();
            KiiObject obj2 = bucket.NewKiiObject();

            obj2["name"] = "bar";
            obj2.Save();
            KiiObject obj3 = bucket.NewKiiObject();

            obj3["name"] = "hoge";
            obj3.Save();

            KiiQuery query = new KiiQuery(KiiClause.Not(KiiClause.Or(KiiClause.Equals("name", "foo"), KiiClause.Equals("name", "bar"))));

            query.SortByAsc("name");

            KiiQueryResult <KiiObject> results = bucket.Query(query);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("hoge", results[0].GetString("name"));
        }
Example #2
0
        public void Test_0001_And_1()
        {
            KiiClause c = KiiClause.And(
                KiiClause.Equals("name", "kii")
                );

            Assert.AreEqual("{\"type\":\"eq\",\"field\":\"name\",\"value\":\"kii\"}", c.ToJson().ToString());
        }
        public void Test_2_6_CountWithUnsupportedQuery()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client           = factory.Client;
            string         mockResponseBody = "{\"errorCode\" : \"QUERY_NOT_SUPPORTED\"}";

            client.AddResponse(new CloudException(400, mockResponseBody));

            string    bucketName = "TestBucket";
            KiiBucket bucket     = Kii.Bucket(bucketName);
            KiiClause clause     = KiiClause.Equals("key", "value");
            KiiQuery  query      = new KiiQuery(clause);

            query.NextPaginationKey = "pkey";
            CloudException exp = null;

            try {
                bucket.Count(query);
                Assert.Fail("Exception not thrown");
            } catch (CloudException e) {
                exp = e;
            }
            Assert.IsNotNull(exp);
            Assert.AreEqual(400, exp.Status);
            Assert.AreEqual(mockResponseBody, exp.Body);

            // check request.
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "TestBucket", "query");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            String queryStr = "{ " +
                              "\"bucketQuery\" : {" +
                              "\"clause\" : {" +
                              "\"type\" : \"eq\"," +
                              "\"field\" : \"key\"," +
                              "\"value\" : \"value\"" +
                              "}," +
                              "\"aggregations\" : [ {" +
                              "\"type\" : \"COUNT\"," +
                              "\"putAggregationInto\" : \"count_field\"" +
                              "}]" +
                              "}, " +
                              "\"paginationKey\" : \"pkey\"" +
                              "}";
            JsonObject expectedBodyJson = new JsonObject(queryStr);
            JsonObject actualBodyJson   = new JsonObject(client.RequestBody[0]);

            KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson);
        }
        public void Test_2_5_CountWithOrQuery()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(200, "{\"aggregations\" : { \"count_field\" : 5 } }");

            string    bucketName = "TestBucket";
            KiiBucket bucket     = Kii.Bucket(bucketName);
            KiiClause clause1    = KiiClause.Equals("key1", "value1");
            KiiClause clause2    = KiiClause.Equals("key2", "value2");
            KiiClause clause     = KiiClause.Or(clause1, clause2);
            KiiQuery  query      = new KiiQuery(clause);
            int       count      = bucket.Count(query);

            Assert.AreEqual(5, count);

            // check request.
            Console.WriteLine(client.RequestBody[0]);
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "TestBucket", "query");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            String queryStr = "{ " +
                              "\"bucketQuery\" : {" +
                              "\"clause\" : {" +
                              "\"type\" : \"or\"," +
                              "\"clauses\" :[ {" +
                              "\"type\" : \"eq\"," +
                              "\"field\" : \"key1\"," +
                              "\"value\" : \"value1\"" +
                              "}," +
                              "{" +
                              "\"type\" : \"eq\"," +
                              "\"field\" : \"key2\"," +
                              "\"value\" : \"value2\"" +
                              "}]" +
                              "}," +
                              "\"aggregations\" : [ {" +
                              "\"type\" : \"COUNT\"," +
                              "\"putAggregationInto\" : \"count_field\"" +
                              "}]" +
                              "}" +
                              "}";
            JsonObject expectedBodyJson = new JsonObject(queryStr);
            JsonObject actualBodyJson   = new JsonObject(client.RequestBody[0]);

            KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson);
        }
Example #5
0
 public void Test_0011_And_null()
 {
     KiiClause.And(
         KiiClause.Equals("name", "kii"),
         null,
         KiiClause.GreaterThan("score", 100),
         null
         );
 }
Example #6
0
        public void Test_0100_Or()
        {
            KiiClause c = KiiClause.Or(
                KiiClause.Equals("name", "kii"),
                KiiClause.GreaterThan("score", 100)
                );

            Assert.AreEqual("{\"type\":\"or\",\"clauses\":[" +
                            "{\"type\":\"eq\",\"field\":\"name\",\"value\":\"kii\"}," +
                            "{\"type\":\"range\",\"field\":\"score\",\"lowerLimit\":100,\"lowerIncluded\":false}]}", c.ToJson().ToString());
        }
Example #7
0
        public void Test_0010_And_array()
        {
            KiiClause[] arr = new KiiClause[] {
                KiiClause.Equals("name", "kii"),
                KiiClause.GreaterThan("score", 100)
            };

            KiiClause c = KiiClause.And(arr);

            Assert.AreEqual("{\"type\":\"and\",\"clauses\":[" +
                            "{\"type\":\"eq\",\"field\":\"name\",\"value\":\"kii\"}," +
                            "{\"type\":\"range\",\"field\":\"score\",\"lowerLimit\":100,\"lowerIncluded\":false}]}", c.ToJson().ToString());
        }
Example #8
0
        public void Test_2_2_CountWithQueryWhenObjectExistsInBucket()
        {
            string    bucketName = "TestBucket" + CurrentTimeMillis();
            KiiBucket bucket     = Kii.Bucket(bucketName);

            for (int i = 0; i < 10; i++)
            {
                KiiObject obj = bucket.NewKiiObject();
                obj ["key"] = "value";
                obj.Save();
            }

            KiiBucket      callbackBucket = null;
            KiiQuery       callbackQuery  = null;
            int            count          = -1;
            Exception      exp            = null;
            CountDownLatch cd             = new CountDownLatch(1);

            KiiClause clause = KiiClause.Equals("key", "value");
            KiiQuery  query  = new KiiQuery(clause);

            bucket.Count(query, (KiiBucket b, KiiQuery q, int c, Exception e) => {
                callbackBucket = b;
                callbackQuery  = q;
                count          = c;
                exp            = e;
                cd.Signal();
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(callbackBucket);
            Assert.AreEqual(bucket.Uri, callbackBucket.Uri);
            Assert.IsNotNull(callbackQuery);
            Assert.AreEqual(query.ToString(), callbackQuery.ToString());
            Assert.IsNull(exp);
            Assert.AreEqual(10, count);
        }
        public void NotAndTest()
        {
            KiiBucket bucket = KiiUser.CurrentUser.Bucket("my_bucket");
            KiiObject obj1   = bucket.NewKiiObject();

            obj1["name"] = "foo";
            obj1["age"]  = 20;
            obj1.Save();
            KiiObject obj2 = bucket.NewKiiObject();

            obj2["name"] = "foo";
            obj2["age"]  = 33;
            obj2.Save();

            KiiQuery query = new KiiQuery(KiiClause.Not(KiiClause.And(KiiClause.Equals("name", "foo"), KiiClause.LessThan("age", 30))));

            query.SortByAsc("name");

            KiiQueryResult <KiiObject> results = bucket.Query(query);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(33, results[0].GetInt("age"));
        }
Example #10
0
        public void Test_0051_Equal_value_null()
        {
            KiiClause c = KiiClause.Equals("name", null);

            Assert.AreEqual("{\"type\":\"eq\",\"field\":\"name\"}", c.ToJson().ToString());
        }
Example #11
0
 public void Test_0050_Equal_key_empty()
 {
     KiiClause.Equals("", "kii");
 }
Example #12
0
 public void Test_0050_Equal_key_null()
 {
     KiiClause.Equals(null, "kii");
 }
Example #13
0
        public void Test_0031_Equal_bool_false()
        {
            KiiClause c = KiiClause.Equals("enable", false);

            Assert.AreEqual("{\"type\":\"eq\",\"field\":\"enable\",\"value\":false}", c.ToJson().ToString());
        }
Example #14
0
        public void Test_0020_Equal_double()
        {
            KiiClause c = KiiClause.Equals("score", 1.234);

            Assert.AreEqual("{\"type\":\"eq\",\"field\":\"score\",\"value\":1.234}", c.ToJson().ToString());
        }
Example #15
0
        public void Test_0010_Equal_long()
        {
            KiiClause c = KiiClause.Equals("score", (long)1234567890123);

            Assert.AreEqual("{\"type\":\"eq\",\"field\":\"score\",\"value\":1234567890123}", c.ToJson().ToString());
        }
Example #16
0
        public void Test_0000_Equal_int()
        {
            KiiClause c = KiiClause.Equals("score", 10);

            Assert.AreEqual("{\"type\":\"eq\",\"field\":\"score\",\"value\":10}", c.ToJson().ToString());
        }
        public void Test_0002_KiiQuery_clause()
        {
            KiiQuery query = new KiiQuery(KiiClause.Equals("name", "kii"));

            Assert.AreEqual("{\"bucketQuery\":{\"clause\":{\"type\":\"eq\",\"field\":\"name\",\"value\":\"kii\"}}}", query.ToString());
        }