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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations