use of com.mysql.cj.xdevapi.UpdateSpec in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testDocUpdate.
@Test
public void testDocUpdate() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
try {
String collName = createTempTestCollection(this.protocol);
String json = "{'_id': '85983efc2a9a11e5b345feff819cdc9f', 'testVal': '1', 'insertedBy': 'Jess'}".replaceAll("'", "\"");
this.protocol.send(this.messageBuilder.buildDocInsert(getTestDatabase(), collName, Arrays.asList(new String[] { json }), false), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
List<UpdateSpec> updates = new ArrayList<>();
updates.add(new UpdateSpec(UpdateType.ITEM_SET, "$.a").setValue("lemon"));
updates.add(new UpdateSpec(UpdateType.ITEM_REMOVE, "$.insertedBy"));
this.protocol.send(this.messageBuilder.buildDocUpdate(new DocFilterParams(getTestDatabase(), collName), updates), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
// verify
this.protocol.send(this.messageBuilder.buildFind(new DocFilterParams(getTestDatabase(), collName)), 0);
ColumnDefinition metadata = this.protocol.readMetadata();
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
Row r = ris.next();
assertEquals("{\"a\": \"lemon\", \"_id\": \"85983efc2a9a11e5b345feff819cdc9f\", \"testVal\": \"1\"}", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
} finally {
dropTempTestCollection(this.protocol);
}
}
Aggregations