public void Test_0001_GeoDistanceQuery() { KiiBucket bucket = testUser.Bucket("aBucket"); KiiObject obj = bucket.NewKiiObject(); KiiGeoPoint point = new KiiGeoPoint(35.667983, 139.739356); obj.SetGeoPoint("myLoc", point); obj.Save(); KiiGeoPoint center = new KiiGeoPoint(35.677379, 139.702148); KiiClause clause = KiiClause.GeoDistance("myloc", center, 4000, "distanceToMyLoc"); KiiQuery query = new KiiQuery(clause); KiiQueryResult <KiiObject> result = bucket.Query(query); KiiObject retObj = result [0]; KiiGeoPoint retPoint; retPoint = retObj.GetGeoPoint("myLoc"); Assert.AreEqual(point.Latitude, retPoint.Latitude); Assert.AreEqual(point.Longitude, retPoint.Longitude); JsonObject jObj = retObj.GetJsonObject("_calculated"); double retDistance = jObj.GetDouble("distanceToMyLoc"); double expectedDistance = distanceInMeter(point, center); Assert.IsTrue(approximateEqual(expectedDistance, retDistance, 0.00001)); }
public void TestReadObjectInBucket() { CountDownLatch cd = new CountDownLatch(1); KiiUser user = KiiUser.CurrentUser; KiiBucket bucket = user.Bucket("aclTest"); KiiBucketAcl acl = bucket.Acl(BucketAction.READ_OBJECTS_IN_BUCKET); KiiACLEntry <KiiBucket, BucketAction> entry = acl.Subject(KiiAnyAuthenticatedUser.Get()); entry.Save(ACLOperation.GRANT, (KiiACLEntry <KiiBucket, BucketAction> savedEntry, Exception e) => { Assert.IsNull(e); Assert.AreEqual(BucketAction.READ_OBJECTS_IN_BUCKET, savedEntry.Action); bucket.ListAclEntries((IList <KiiACLEntry <KiiBucket, BucketAction> > list, Exception e2) => { Assert.IsNull(e2); CheckEntriesAfterAdd(user, list); // Remove ACL Entry entry.Save(ACLOperation.REVOKE, (KiiACLEntry <KiiBucket, BucketAction> savedEntry2, Exception e3) => { Assert.IsNull(e3); Assert.AreEqual(BucketAction.READ_OBJECTS_IN_BUCKET, savedEntry2.Action); bucket.ListAclEntries((IList <KiiACLEntry <KiiBucket, BucketAction> > list2, Exception e4) => { Assert.IsNull(e4); CheckEntriesAfterRemove(user, list2); cd.Signal(); }); }); }); }); if (!cd.Wait(new TimeSpan(0, 0, 0, 10))) { Assert.Fail("Callback not fired."); } }
void SaveScore(int score) { KiiUser user = KiiUser.CurrentUser; if (user == null) { return; } KiiBucket bucket = user.Bucket("scores"); KiiObject kiiObj = bucket.NewKiiObject(); kiiObj ["score"] = score; kiiObj ["time"] = Time.time; kiiObj ["level"] = 1; Debug.Log("Saving score..."); kiiObj.Save((KiiObject obj, Exception e) => { if (e != null) { Debug.LogError(e.ToString()); } else { Debug.Log("Score sent: " + score.ToString()); } }); }
public static void LoadHighScore() { if (KiiUser.CurrentUser == null) { return; } KiiUser user = KiiUser.CurrentUser; KiiBucket bucket = user.Bucket("scores"); KiiQuery query = new KiiQuery(); query.SortByDesc("score"); query.Limit = 1; bucket.Query(query, (KiiQueryResult <KiiObject> list, Exception e) => { if (e != null) { Debug.LogError("Failed to load high score " + e.ToString()); } else { foreach (KiiObject obj in list) { highscore = obj.GetInt("score", 0); Debug.Log("High score loaded: " + highscore.ToString()); return; } } }); }
public void Test_1100_Bucket_OK() { KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd")); KiiBucket bucket = user.Bucket("myBucket"); Assert.IsNotNull(bucket); Assert.AreEqual("myBucket", bucket.Name); }
public void Test_0302_Uri_UserScope_endWith_slash() { Kii.Initialize("abbId", "appKey", Kii.Site.JP); KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234/")); KiiBucket bucket = user.Bucket("name1234"); Assert.AreEqual("kiicloud://users/user1234/buckets/name1234", bucket.Uri.ToString()); }
public void Test_1_4_CountWhenBucketParentNotExists() { MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; string mockResponseBody = "{\"errorCode\" : \"USER_NOT_FOUND\"}"; client.AddResponse(new CloudException(404, mockResponseBody)); string bucketName = "TestBucket"; KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/dummyUserId")); KiiBucket bucket = user.Bucket(bucketName); CloudException exp = null; try { bucket.Count(); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // check request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyUserId", "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\" : \"all\"" + "}," + "\"aggregations\" : [ {" + "\"type\" : \"COUNT\"," + "\"putAggregationInto\" : \"count_field\"" + "}]" + "}" + "}"; JsonObject expectedBodyJson = new JsonObject(queryStr); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
private IEnumerator TestStep() { string username = StringUtils.RandomAlphabetic(20); string password = StringUtils.RandomAlphabetic(20); KiiUser user = KiiUser.BuilderWithName(username).Build(); var task = RegisterUser(user, password, (KiiUser u, Exception e) => { if (e != null) { throw new TestFailException(); } Debug.Log("Register user."); }); yield return(StartCoroutine(task)); // Create object string bucketName = StringUtils.RandomAlphabetic(10); string objectId = StringUtils.RandomAlphabetic(10); KiiBucket bucket = user.Bucket(bucketName); KiiObject obj = bucket.NewKiiObject(objectId); string objKey = "KeyA"; string objValue = "ValueA"; obj [objKey] = objValue; Exception exp = null; bool endFlag = false; KiiObjectCallback callback = (KiiObject obj1, Exception e) => { exp = e; endFlag = true; }; obj.SaveAllFields(true, callback); while (!endFlag) { yield return(new WaitForSeconds(1)); } if (exp != null) { throw new TestFailException(); } Debug.Log("object created"); // refresh endFlag = false; exp = null; obj.Refresh(callback); while (!endFlag) { yield return(new WaitForSeconds(1)); } if (exp != null) { throw new TestFailException(); } Debug.Log("object refreshed"); // Update with patch obj ["KeyB"] = "ValueB"; obj ["KeyA"] = "UpdateB"; endFlag = false; exp = null; obj.Save(true, callback); while (!endFlag) { yield return(new WaitForSeconds(1)); } if (exp != null) { throw new TestFailException(); } Debug.Log("object updated."); // verify update string uri = SDKUtils.GetObjectUFEUri(obj); Debug.Log("object ufe uri :" + uri); string body = ApiHelper.get(uri, Kii.AppId, Kii.AppKey, KiiUser.AccessToken); JsonObject json = new JsonObject(body); if (!"UpdateA".Equals(json.GetString("KeyA"))) { throw new TestFailException(); } if (!"ValueB".Equals(json.GetString("KeyB"))) { throw new TestFailException(); } resultFlag = true; }
private IEnumerator TestStep() { string username = StringUtils.RandomAlphabetic(20); string password = StringUtils.RandomAlphabetic(20); KiiUser user = KiiUser.BuilderWithName(username).Build(); var task = RegisterUser(user, password, (KiiUser u, Exception e) => { if (e != null) { throw new TestFailException(); } Debug.Log("Register user."); }); yield return(StartCoroutine(task)); // Create object string bucketName = StringUtils.RandomAlphabetic(10); string objectId = StringUtils.RandomAlphabetic(10); KiiBucket bucket = user.Bucket(bucketName); KiiObject obj = bucket.NewKiiObject(objectId); string objKey = "KeyA"; string objValue = "ValueA"; obj [objKey] = objValue; Exception exp = null; bool endFlag = false; KiiObjectCallback callback = (KiiObject obj1, Exception e) => { exp = e; endFlag = true; }; obj.SaveAllFields(true, callback); while (!endFlag) { yield return(new WaitForSeconds(1)); } if (exp != null) { throw new TestFailException(); } Debug.Log("object created"); // Update with no-patch KiiObject obj2 = bucket.NewKiiObject(objectId); obj2 [objKey] = "UpdateA"; endFlag = false; exp = null; obj2.SaveAllFields(false, callback); while (!endFlag) { yield return(new WaitForSeconds(1)); } Debug.Log("Exception:" + exp); if (exp == null) { throw new TestFailException(); } if (409 != ((CloudException)exp).Status) { throw new TestFailException(); } Debug.Log("object updated has expected conflict response ."); resultFlag = true; }
private IEnumerator TestStep() { string username = StringUtils.RandomAlphabetic(20); string password = StringUtils.RandomAlphabetic(20); KiiUser user = KiiUser.BuilderWithName(username).Build(); var task = RegisterUser(user, password, (KiiUser u, Exception e) => { if (e != null) { throw new TestFailException(); } Debug.Log("Register user."); }); yield return(StartCoroutine(task)); IDictionary dict = KiiUser.CurrentUser.GetAccessTokenDictionary(); if (dict == null) { throw new TestFailException(); } string token = dict["access_token"].ToString(); if (token == null) { throw new TestFailException(); } long expiresAt = Convert.ToInt64(dict["expires_at"].ToString()); if (expiresAt != long.MaxValue) { throw new TestFailException(); } Exception exp = null; bool endFlag = false; KiiObjectCallback callback = (KiiObject obj, Exception e) => { exp = e; endFlag = true; }; KiiObject ob = user.Bucket(StringUtils.RandomAlphabetic(10)).NewKiiObject(); ob["key"] = "value"; ob.Save(callback); while (!endFlag) { yield return(new WaitForSeconds(1)); } if (exp != null) { throw new TestFailException(); } resultFlag = true; }
void UserCreatedCallback(KiiUser callbackUser, System.Exception exc) { Debug.LogWarning(exc.Message); if (exc != null && exc as System.NullReferenceException == null) { // Error handling setErrText = "CREATE USER FAILURE: " + exc.Message; return; } setErrText = "CREATE USER SUCCESS " + callbackUser.Username; User = callbackUser; KiiObject origObj = callbackUser.Bucket("worlds").NewKiiObject(); origObj["test"] = "true"; origObj.Save(true, BucketCreatedCallback); }
void OnGUI() { ScalableGUI gui = new ScalableGUI(); gui.Label(5, 5, 310, 20, "Push2App scene"); if (gui.Button(200, 5, 120, 35, "-> Push2User")) { this.kiiPushPlugin.OnPushMessageReceived -= this.receivedCallback; Application.LoadLevel("push2user"); } this.payload = gui.TextField(0, 45, 320, 50, this.payload); if (gui.Button(0, 100, 160, 50, "Create Object")) { KiiBucket bucket = KiiUser.CurrentUser.Bucket(BUCKET_NAME); KiiObject obj = bucket.NewKiiObject(); obj ["payload"] = this.payload; obj.Save((KiiObject o, Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("Failed to save object", e); return; } this.message = "#####creating object is successful!!"; }); } if (gui.Button(160, 100, 160, 50, "Clear Log")) { this.message = "--- Logs will show here ---"; } if (gui.Button(0, 150, 160, 50, "Register Push")) { Invoke("registerPush", 0); } if (gui.Button(160, 150, 160, 50, "Unregister Push")) { this.kiiPushPlugin.UnregisterPush((Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("#####Unregister push is failed!!", e); return; } this.message = "#####Unregister push is successful!!"; }); } if (gui.Button(0, 200, 160, 50, "Subscribe bucket")) { KiiUser user = KiiUser.CurrentUser; KiiBucket bucket = user.Bucket(BUCKET_NAME); KiiPushSubscription subscription = user.PushSubscription; subscription.Subscribe(bucket, (KiiSubscribable target, Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("#####Subscribe is failed!!", e); return; } this.message = "#####Subscribe is successful!!"; }); } if (gui.Button(160, 200, 160, 50, "Unsubscribe bucket")) { KiiUser user = KiiUser.CurrentUser; KiiBucket bucket = user.Bucket(BUCKET_NAME); KiiPushSubscription subscription = user.PushSubscription; subscription.Unsubscribe(bucket, (KiiSubscribable target, Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("#####Unsubscribe is failed!!", e); return; } this.message = "#####Unsubscribe is successful!!"; }); } if (gui.Button(0, 250, 160, 50, "Check subscription")) { KiiUser user = KiiUser.CurrentUser; KiiBucket bucket = user.Bucket(BUCKET_NAME); KiiPushSubscription subscription = user.PushSubscription; subscription.IsSubscribed(bucket, (KiiSubscribable target, bool isSubscribed, Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("#####Check subscription is failed!!", e); return; } this.message = "#####Subscription status : " + isSubscribed; }); } gui.TextArea(5, 310, 310, 170, this.message, 10); }
public void Test_1101_Bucket_null() { KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/abcd")); user.Bucket(null); }