/** * Convert the REST server's response to an XML reader. * * @param response The REST server's response. * @return A reader over the parsed XML document. * @throws IOException If the document fails to parse */ private XMLStreamReader getInputStream(Response response) throws IOException { try { // Prevent the parser from reading XMl with external entities defined XMLInputFactory xif = XMLInputFactory.newFactory(); xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); return xif.createXMLStreamReader(new ByteArrayInputStream(response.getBody())); } catch (XMLStreamException e) { throw new IOException("Failed to parse XML", e); } } }
@Test public void testGetStargateVersionXML() throws IOException, JAXBException { Response response = client.get("/version", Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); VersionModel model = (VersionModel) context.createUnmarshaller().unmarshal( new ByteArrayInputStream(response.getBody())); validate(model); LOG.info("success retrieving Stargate version as XML"); }
@Test public void testGetStargateVersionText() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_TEXT); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); String body = Bytes.toString(response.getBody()); assertTrue(body.length() > 0); assertTrue(body.contains(RESTServlet.VERSION_STRING)); assertTrue(body.contains(System.getProperty("java.vm.vendor"))); assertTrue(body.contains(System.getProperty("java.version"))); assertTrue(body.contains(System.getProperty("java.vm.version"))); assertTrue(body.contains(System.getProperty("os.name"))); assertTrue(body.contains(System.getProperty("os.version"))); assertTrue(body.contains(System.getProperty("os.arch"))); // TODO: fix when we actually get a jersey version // assertTrue(body.contains(ServletContainer.class.getPackage().getImplementationVersion())); }
@Test public void testGetClusterStatusXML() throws IOException, JAXBException { Response response = client.get("/status/cluster", Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); StorageClusterStatusModel model = (StorageClusterStatusModel) context.createUnmarshaller().unmarshal( new ByteArrayInputStream(response.getBody())); validate(model); }
@Test public void testTableListXML() throws IOException, JAXBException { Response response = client.get("/", Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); TableListModel model = (TableListModel) context.createUnmarshaller() .unmarshal(new ByteArrayInputStream(response.getBody())); checkTableList(model); }
@Test public void testTableInfoXML() throws IOException, JAXBException { Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); TableInfoModel model = (TableInfoModel) context.createUnmarshaller() .unmarshal(new ByteArrayInputStream(response.getBody())); checkTableInfo(model); }
protected static void checkValueXML(String url, String table, String row, String column, String value) throws IOException, JAXBException { Response response = getValueXML(url); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toString(cell.getValue()), value); }
protected static void checkValueXML(String table, String row, String column, String value) throws IOException, JAXBException { Response response = getValueXML(table, row, column); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toString(cell.getValue()), value); }
protected static void checkIncrementValueXML(String table, String row, String column, long value) throws IOException, JAXBException { Response response1 = getValueXML(table, row, column); assertEquals(200, response1.getCode()); assertEquals(Constants.MIMETYPE_XML, response1.getHeader("content-type")); CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response1.getBody())); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toLong(cell.getValue()), value); }
@Test public void testGetStorageClusterVersionXML() throws IOException, JAXBException { Response response = client.get("/version/cluster",Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); StorageClusterVersionModel clusterVersionModel = (StorageClusterVersionModel) context.createUnmarshaller().unmarshal( new ByteArrayInputStream(response.getBody())); assertNotNull(clusterVersionModel); assertNotNull(clusterVersionModel.getVersion()); LOG.info("success retrieving storage cluster version as XML"); }
protected static void checkValueJSON(String table, String row, String column, String value) throws IOException, JAXBException { Response response = getValueJson(table, row, column); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); ObjectMapper mapper = new JacksonJaxbJsonProvider() .locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toString(cell.getValue()), value); }
@Test public void testGetStargateVersionJSON() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); ObjectMapper mapper = new JacksonJaxbJsonProvider() .locateMapper(VersionModel.class, MediaType.APPLICATION_JSON_TYPE); VersionModel model = mapper.readValue(response.getBody(), VersionModel.class); validate(model); LOG.info("success retrieving Stargate version as JSON"); }
protected static void checkValuePB(String table, String row, String column, String value) throws IOException { Response response = getValuePB(table, row, column); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toString(cell.getValue()), value); }
protected static void checkIncrementValueJSON(String table, String row, String column, long value) throws IOException, JAXBException { Response response = getValueJson(table, row, column); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); ObjectMapper mapper = new JacksonJaxbJsonProvider() .locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toLong(cell.getValue()), value); }
protected static void checkIncrementValuePB(String table, String row, String column, long value) throws IOException { Response response = getValuePB(table, row, column); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); CellSetModel cellSet = new CellSetModel(); cellSet.getObjectFromMessage(response.getBody()); RowModel rowModel = cellSet.getRows().get(0); CellModel cell = rowModel.getCells().get(0); assertEquals(Bytes.toString(cell.getColumn()), column); assertEquals(Bytes.toLong(cell.getValue()), value); }
@Test public void testGetStorageClusterVersionJSON() throws IOException { Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); ObjectMapper mapper = new JacksonJaxbJsonProvider() .locateMapper(StorageClusterVersionModel.class, MediaType.APPLICATION_JSON_TYPE); StorageClusterVersionModel clusterVersionModel = mapper.readValue(response.getBody(), StorageClusterVersionModel.class); assertNotNull(clusterVersionModel); assertNotNull(clusterVersionModel.getVersion()); LOG.info("success retrieving storage cluster version as JSON"); } }
@Test public void testTableListPB() throws IOException, JAXBException { Response response = client.get("/", Constants.MIMETYPE_PROTOBUF); assertEquals(200, response.getCode()); 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(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); model = new TableListModel(); model.getObjectFromMessage(response.getBody()); checkTableList(model); }
@Test public void testGetStargateVersionPB() throws IOException { Response response = client.get("/version", Constants.MIMETYPE_PROTOBUF); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); VersionModel model = new VersionModel(); model.getObjectFromMessage(response.getBody()); validate(model); response = client.get("/version", Constants.MIMETYPE_PROTOBUF_IETF); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); model = new VersionModel(); model.getObjectFromMessage(response.getBody()); validate(model); }
@Test public void testTableInfoPB() throws IOException, JAXBException { Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_PROTOBUF); assertEquals(200, response.getCode()); 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(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); model = new TableInfoModel(); model.getObjectFromMessage(response.getBody()); checkTableInfo(model); }
@Test public void testGetClusterStatusPB() throws IOException { Response response = client.get("/status/cluster", Constants.MIMETYPE_PROTOBUF); assertEquals(200, response.getCode()); 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(200, response.getCode()); assertEquals(Constants.MIMETYPE_PROTOBUF_IETF, response.getHeader("content-type")); model = new StorageClusterStatusModel(); model.getObjectFromMessage(response.getBody()); validate(model); } }