Search in sources :

Example 66 with JsonValue

use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.

the class DocIdTypeIT method testComplexId.

/**
 * @throws Exception
 */
@Test
public void testComplexId() throws Exception {
    String body = "{'_id':{'a':1,'b':2}}";
    resp = Unirest.post(url(DB, COLL)).basicAuth(ADMIN_ID, ADMIN_PWD).header("content-type", "application/json").body(body).asString();
    Assert.assertEquals("create doc with complex id ", org.apache.http.HttpStatus.SC_CREATED, resp.getStatus());
    resp = Unirest.get(url(DB, COLL)).basicAuth(ADMIN_ID, ADMIN_PWD).header("content-type", "application/json").queryString("filter", "{'_id':{'a':1,'b':2}}").queryString("count", "1").queryString("rep", "pj").asString();
    JsonValue rbody = Json.parse(resp.getBody());
    Assert.assertTrue("check doc", rbody != null && rbody.isObject() && rbody.asObject().get("_size") != null && rbody.asObject().get("_size").isNumber() && rbody.asObject().get("_size").asInt() == 1);
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) Test(org.junit.Test)

Example 67 with JsonValue

use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.

the class JsonSchemaCheckerIT method testGetSchema.

/**
 * @throws Exception
 */
@Test
public void testGetSchema() throws Exception {
    resp = Unirest.get(url(DB, SCHEMA_STORE, "basic")).basicAuth(ADMIN_ID, ADMIN_PWD).asString();
    Assert.assertEquals("test get schema", HttpStatus.SC_OK, resp.getStatus());
    JsonValue rbody = Json.parse(resp.getBody().toString());
    Assert.assertTrue("response body is a document", rbody != null && rbody.isObject());
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) Test(org.junit.Test)

Example 68 with JsonValue

use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.

the class PostCollectionIT method testPostDocumentOperators.

/**
 * @throws Exception
 */
@Test
public void testPostDocumentOperators() throws Exception {
    resp = Unirest.post(url(DB, COLL)).basicAuth(ADMIN_ID, ADMIN_PWD).header("content-type", "application/json").body("{ '_id': 'docid2', '$push': {'array': 'a'}, '$inc': { 'count': 100 }}").asString();
    Assert.assertEquals("check response status of create test data", org.apache.http.HttpStatus.SC_BAD_REQUEST, resp.getStatus());
    resp = Unirest.post(url(DB, COLL)).basicAuth(ADMIN_ID, ADMIN_PWD).queryString("wm", "upsert").header("content-type", "application/json").body("{ '_id': 'docid2', '$currentDate': {'timestamp': true } }").asString();
    Assert.assertEquals("check response status of create test data with $currentDate operator", org.apache.http.HttpStatus.SC_CREATED, resp.getStatus());
    resp = Unirest.get(url(DB, COLL, "docid2")).basicAuth(ADMIN_ID, ADMIN_PWD).asString();
    Assert.assertEquals("check response status of get test data", org.apache.http.HttpStatus.SC_OK, resp.getStatus());
    JsonValue rbody = Json.parse(resp.getBody().toString());
    Assert.assertTrue("check data to be a json object", rbody != null && rbody.isObject());
    JsonValue timestamp = rbody.asObject().get("timestamp");
    Assert.assertTrue("check timestamp to be an object", timestamp != null && timestamp.isObject());
    JsonValue $date = timestamp.asObject().get("$date");
    Assert.assertTrue("check $date to be numeric", $date != null && $date.isNumber());
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) Test(org.junit.Test)

Example 69 with JsonValue

use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.

the class PutDocumentIT method testPutDocumentDotNotation.

/**
 * @throws Exception
 */
@Test
public void testPutDocumentDotNotation() throws Exception {
    resp = Unirest.put(url(DB, COLL, "docid1")).basicAuth(ADMIN_ID, ADMIN_PWD).queryString("wm", "upsert").header("content-type", "application/json").body("{ 'doc.number': 1 }").asString();
    Assert.assertEquals("check response status of create test data", org.apache.http.HttpStatus.SC_CREATED, resp.getStatus());
    resp = Unirest.get(url(DB, COLL, "docid1")).basicAuth(ADMIN_ID, ADMIN_PWD).asString();
    Assert.assertEquals("check response status of get test data", org.apache.http.HttpStatus.SC_OK, resp.getStatus());
    JsonValue rbody = Json.parse(resp.getBody().toString());
    Assert.assertTrue("check data to be a json object", rbody != null && rbody.isObject());
    JsonValue doc = rbody.asObject().get("doc");
    Assert.assertTrue("check data to have the 'doc' json object", doc != null && doc.isObject());
    JsonValue number = doc.asObject().get("number");
    Assert.assertTrue("check doc to have the 'number' property", number != null && number.isNumber() && number.asInt() == 1);
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) Test(org.junit.Test)

Example 70 with JsonValue

use of com.eclipsesource.json.JsonValue in project restheart by SoftInstigate.

the class PutDocumentIT method testPutDocumentOperators.

/**
 * @throws Exception
 */
@Test
public void testPutDocumentOperators() throws Exception {
    resp = Unirest.put(url(DB, COLL, "docid2")).basicAuth(ADMIN_ID, ADMIN_PWD).queryString("wm", "upsert").header("content-type", "application/json").body("{ '$push': {'array': 'a'}, '$inc': { 'count': 100 } }").asString();
    Assert.assertEquals("check response status of create test data", org.apache.http.HttpStatus.SC_BAD_REQUEST, resp.getStatus());
    resp = Unirest.put(url(DB, COLL, "docid2")).basicAuth(ADMIN_ID, ADMIN_PWD).queryString("wm", "upsert").header("content-type", "application/json").body("{ '$currentDate': {'timestamp': { '$type': 'date' }}}").asString();
    Assert.assertEquals("check response status of create test data with $currentDate operator", org.apache.http.HttpStatus.SC_CREATED, resp.getStatus());
    resp = Unirest.get(url(DB, COLL, "docid2")).basicAuth(ADMIN_ID, ADMIN_PWD).asString();
    Assert.assertEquals("check response status of get test data", org.apache.http.HttpStatus.SC_OK, resp.getStatus());
    JsonValue rbody = Json.parse(resp.getBody().toString());
    Assert.assertTrue("check data to be a json object", rbody != null && rbody.isObject());
    JsonValue timestamp = rbody.asObject().get("timestamp");
    Assert.assertTrue("check timestamp to be an object", timestamp != null && timestamp.isObject());
    JsonValue $date = timestamp.asObject().get("$date");
    Assert.assertTrue("check $date to be numeric", $date != null && $date.isNumber());
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) Test(org.junit.Test)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)147 JsonObject (com.eclipsesource.json.JsonObject)74 JsonArray (com.eclipsesource.json.JsonArray)43 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)26 URL (java.net.URL)21 HashMap (java.util.HashMap)10 IOException (java.io.IOException)9 Member (com.eclipsesource.json.JsonObject.Member)6 ParseException (com.eclipsesource.json.ParseException)4 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)4 InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 Map (java.util.Map)3 WebTarget (javax.ws.rs.client.WebTarget)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 FileInputStream (java.io.FileInputStream)2