HBASE-7472. [REST] Support MIME type application/protobuf

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1427843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2013-01-02 16:18:30 +00:00
parent 1a7e1a2090
commit 7beca53644
21 changed files with 112 additions and 34 deletions

View File

@ -39,6 +39,7 @@ public interface Constants {
public static final String MIMETYPE_XML = "text/xml";
public static final String MIMETYPE_BINARY = "application/octet-stream";
public static final String MIMETYPE_PROTOBUF = "application/x-protobuf";
public static final String MIMETYPE_PROTOBUF_IETF = "application/protobuf";
public static final String MIMETYPE_JSON = "application/json";
public static final String CRLF = "\r\n";

View File

@ -55,7 +55,7 @@ public class ExistsResource extends ResourceBase {
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_BINARY})
MIMETYPE_PROTOBUF_IETF, MIMETYPE_BINARY})
public Response get(final @Context UriInfo uriInfo) {
try {
if (!tableResource.exists()) {

View File

@ -60,7 +60,8 @@ public class MultiRowResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();

View File

@ -66,7 +66,8 @@ public class RegionsResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());

View File

@ -69,7 +69,8 @@ public class RootResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());

View File

@ -80,7 +80,8 @@ public class RowResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
@ -306,7 +307,8 @@ public class RowResource extends ResourceBase {
}
@PUT
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response put(final CellSetModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
@ -327,7 +329,8 @@ public class RowResource extends ResourceBase {
}
@POST
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response post(final CellSetModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {

View File

@ -68,7 +68,8 @@ public class ScannerInstanceResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo,
@QueryParam("n") int maxRows, final @QueryParam("c") int maxValues) {
if (LOG.isDebugEnabled()) {

View File

@ -120,7 +120,8 @@ public class ScannerResource extends ResourceBase {
}
@PUT
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response put(final ScannerModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
@ -130,7 +131,8 @@ public class ScannerResource extends ResourceBase {
}
@POST
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response post(final ScannerModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {

View File

@ -86,7 +86,8 @@ public class SchemaResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());
@ -209,7 +210,8 @@ public class SchemaResource extends ResourceBase {
}
@PUT
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response put(final TableSchemaModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
@ -220,7 +222,8 @@ public class SchemaResource extends ResourceBase {
}
@POST
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response post(final TableSchemaModel model,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {

View File

@ -60,7 +60,8 @@ public class StorageClusterStatusResource extends ResourceBase {
}
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("GET " + uriInfo.getAbsolutePath());

View File

@ -71,7 +71,8 @@ public class VersionResource extends ResourceBase {
* @return a response for a version request
*/
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context ServletContext context,
final @Context UriInfo uriInfo) {
if (LOG.isDebugEnabled()) {

View File

@ -43,7 +43,7 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
* ProtobufMessageHandler interface capable handlers for decoding protobuf input.
*/
@Provider
@Consumes(Constants.MIMETYPE_PROTOBUF)
@Consumes({Constants.MIMETYPE_PROTOBUF, Constants.MIMETYPE_PROTOBUF_IETF})
@InterfaceAudience.Private
public class ProtobufMessageBodyConsumer
implements MessageBodyReader<ProtobufMessageHandler> {

View File

@ -43,7 +43,7 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
* sent, then writeTo to perform the actual I/O.
*/
@Provider
@Produces(Constants.MIMETYPE_PROTOBUF)
@Produces({Constants.MIMETYPE_PROTOBUF, Constants.MIMETYPE_PROTOBUF_IETF})
@InterfaceAudience.Private
public class ProtobufMessageBodyProducer
implements MessageBodyWriter<ProtobufMessageHandler> {

View File

@ -116,6 +116,7 @@ public class TestMultiRowResource {
Response response = client.get(path.toString(), Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
client.delete(row_5_url);
client.delete(row_6_url);
@ -142,6 +143,7 @@ public class TestMultiRowResource {
Response response = client.get(path.toString(), Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
client.delete(row_5_url);
client.delete(row_6_url);

View File

@ -210,6 +210,7 @@ public class TestRowResource {
String value) throws IOException, JAXBException {
Response response = getValueXML(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
RowModel rowModel = cellSet.getRows().get(0);
@ -222,6 +223,7 @@ public class TestRowResource {
String column, String value) throws IOException, JAXBException {
Response response = getValueXML(url);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
RowModel rowModel = cellSet.getRows().get(0);
@ -259,6 +261,7 @@ public class TestRowResource {
String value) throws IOException {
Response response = getValuePB(table, row, column);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
RowModel rowModel = cellSet.getRows().get(0);
@ -501,6 +504,7 @@ public class TestRowResource {
response = client.get(path, Constants.MIMETYPE_BINARY);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_BINARY, response.getHeader("content-type"));
assertTrue(Bytes.equals(response.getBody(), body));
boolean foundTimestampHeader = false;
for (Header header: response.getHeaders()) {
@ -524,6 +528,7 @@ public class TestRowResource {
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);
}
@ -537,6 +542,7 @@ public class TestRowResource {
Thread.yield();
response = client.get(path, Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
response = deleteRow(TABLE, ROW_4);
assertEquals(response.getCode(), 200);

View File

@ -46,6 +46,7 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -124,6 +125,7 @@ public class TestScannerResource {
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertTrue(response.getCode() == 200 || response.getCode() == 204);
if (response.getCode() == 200) {
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
Iterator<RowModel> rows = cellSet.getRows().iterator();
@ -207,6 +209,7 @@ public class TestScannerResource {
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// confirm batch size conformance
@ -250,6 +253,7 @@ public class TestScannerResource {
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
CellSetModel cellSet = new CellSetModel();
cellSet.getObjectFromMessage(response.getBody());
// confirm batch size conformance
@ -292,6 +296,7 @@ public class TestScannerResource {
// 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

View File

@ -63,6 +63,7 @@ import org.apache.hadoop.hbase.rest.model.ScannerModel;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -216,7 +217,7 @@ public class TestScannersWithFilters {
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
@ -225,6 +226,7 @@ public class TestScannersWithFilters {
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cells = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -250,7 +252,7 @@ public class TestScannersWithFilters {
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
@ -259,6 +261,7 @@ public class TestScannersWithFilters {
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -312,6 +315,7 @@ public class TestScannersWithFilters {
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));

View File

@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.rest.model.TestTableSchemaModel;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -109,6 +110,7 @@ public class TestSchemaResource {
// retrieve the schema and validate it
response = client.get(schemaPath, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
model = fromXML(response.getBody());
TestTableSchemaModel.checkModel(model, TABLE1);
@ -147,6 +149,15 @@ public class TestSchemaResource {
// retrieve the schema and validate it
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
model = new TableSchemaModel();
model.getObjectFromMessage(response.getBody());
TestTableSchemaModel.checkModel(model, TABLE2);
// retrieve the schema and validate it with alternate pbuf type
response = client.get(schemaPath, Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new TableSchemaModel();
model.getObjectFromMessage(response.getBody());
TestTableSchemaModel.checkModel(model, TABLE2);

View File

@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.rest.model.StorageClusterStatusModel;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -94,6 +95,7 @@ public class TestStatusResource {
public void testGetClusterStatusXML() throws IOException, JAXBException {
Response response = client.get("/status/cluster", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
StorageClusterStatusModel model = (StorageClusterStatusModel)
context.createUnmarshaller().unmarshal(
new ByteArrayInputStream(response.getBody()));
@ -102,13 +104,17 @@ public class TestStatusResource {
@Test
public void testGetClusterStatusPB() throws IOException {
Response response = client.get("/status/cluster",
Constants.MIMETYPE_PROTOBUF);
Response response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
StorageClusterStatusModel model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());
validate(model);
response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new StorageClusterStatusModel();
model.getObjectFromMessage(response.getBody());
validate(model);
}
}

View File

@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.StringUtils;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -178,12 +179,14 @@ public class TestTableResource {
public void testTableListText() throws IOException {
Response response = client.get("/", Constants.MIMETYPE_TEXT);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
}
@Test
public void testTableListXML() throws IOException, JAXBException {
Response response = client.get("/", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
TableListModel model = (TableListModel)
context.createUnmarshaller()
.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -194,29 +197,37 @@ public class TestTableResource {
public void testTableListJSON() throws IOException {
Response response = client.get("/", Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
@Test
public void testTableListPB() throws IOException, JAXBException {
Response response = client.get("/", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
TableListModel model = new TableListModel();
model.getObjectFromMessage(response.getBody());
checkTableList(model);
response = client.get("/", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new TableListModel();
model.getObjectFromMessage(response.getBody());
checkTableList(model);
}
@Test
public void testTableInfoText() throws IOException {
Response response = client.get("/" + TABLE + "/regions",
Constants.MIMETYPE_TEXT);
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_TEXT);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
}
@Test
public void testTableInfoXML() throws IOException, JAXBException {
Response response = client.get("/" + TABLE + "/regions",
Constants.MIMETYPE_XML);
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
TableInfoModel model = (TableInfoModel)
context.createUnmarshaller()
.unmarshal(new ByteArrayInputStream(response.getBody()));
@ -225,19 +236,25 @@ public class TestTableResource {
@Test
public void testTableInfoJSON() throws IOException {
Response response = client.get("/" + TABLE + "/regions",
Constants.MIMETYPE_JSON);
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_JSON);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
@Test
public void testTableInfoPB() throws IOException, JAXBException {
Response response = client.get("/" + TABLE + "/regions",
Constants.MIMETYPE_PROTOBUF);
Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
TableInfoModel model = new TableInfoModel();
model.getObjectFromMessage(response.getBody());
checkTableInfo(model);
response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF_IETF);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new TableInfoModel();
model.getObjectFromMessage(response.getBody());
checkTableInfo(model);
}
}

View File

@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.rest.model.VersionModel;
import org.apache.hadoop.hbase.util.Bytes;
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -96,6 +97,7 @@ public class TestVersionResource {
public void testGetStargateVersionText() throws IOException {
Response response = client.get("/version", Constants.MIMETYPE_TEXT);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
String body = Bytes.toString(response.getBody());
assertTrue(body.length() > 0);
assertTrue(body.contains(RESTServlet.VERSION_STRING));
@ -113,6 +115,7 @@ public class TestVersionResource {
public void testGetStargateVersionXML() throws IOException, JAXBException {
Response response = client.get("/version", Constants.MIMETYPE_XML);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
VersionModel model = (VersionModel)
context.createUnmarshaller().unmarshal(
new ByteArrayInputStream(response.getBody()));
@ -124,23 +127,30 @@ public class TestVersionResource {
public void testGetStargateVersionJSON() throws IOException {
Response response = client.get("/version", Constants.MIMETYPE_JSON);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
@Test
public void testGetStargateVersionPB() throws IOException {
Response response = client.get("/version", Constants.MIMETYPE_PROTOBUF);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type"));
VersionModel model = new VersionModel();
model.getObjectFromMessage(response.getBody());
validate(model);
LOG.info("success retrieving Stargate version as protobuf");
response = client.get("/version", Constants.MIMETYPE_PROTOBUF_IETF);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type"));
model = new VersionModel();
model.getObjectFromMessage(response.getBody());
validate(model);
}
@Test
public void testGetStorageClusterVersionText() throws IOException {
Response response = client.get("/version/cluster",
Constants.MIMETYPE_TEXT);
Response response = client.get("/version/cluster", Constants.MIMETYPE_TEXT);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
}
@Test
@ -148,6 +158,7 @@ public class TestVersionResource {
JAXBException {
Response response = client.get("/version/cluster",Constants.MIMETYPE_XML);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
StorageClusterVersionModel clusterVersionModel =
(StorageClusterVersionModel)
context.createUnmarshaller().unmarshal(
@ -161,6 +172,7 @@ public class TestVersionResource {
public void doTestGetStorageClusterVersionJSON() throws IOException {
Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
}