model.setBatch(1);
model.addColumn(Bytes.toBytes(COLUMN_1));
// test put operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 403);
String scannerURI = response.getLocation();
assertNull(scannerURI);
// recall previous put operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
assertEquals(response.getCode(), 201);
scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell
response = client.get(scannerURI, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
// verify that data was returned
assertTrue(response.getBody().length > 0);
// verify that the expected X-headers are present
boolean foundRowHeader = false, foundColumnHeader = false,
foundTimestampHeader = false;
for (Header header: response.getHeaders()) {
if (header.getName().equals("X-Row")) {
foundRowHeader = true;
} else if (header.getName().equals("X-Column")) {
foundColumnHeader = true;
} else if (header.getName().equals("X-Timestamp")) {
foundTimestampHeader = true;
}
}
assertTrue(foundRowHeader);
assertTrue(foundColumnHeader);
assertTrue(foundTimestampHeader);
// test delete scanner operation is forbidden in read-only mode
conf.set("hbase.rest.readonly", "true");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 403);
// recall previous delete scanner operation with read-only off
conf.set("hbase.rest.readonly", "false");
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
}