use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestVersionResource method testGetStargateVersionJSON.
@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");
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestVersionResource method testGetStargateVersionXML.
@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");
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestVersionResource method testGetStargateVersionText.
@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()));
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestNamespacesInstanceResource method testCannotDeleteDefaultAndHbaseNamespaces.
@Test
public void testCannotDeleteDefaultAndHbaseNamespaces() throws IOException {
String defaultPath = "/namespaces/default";
String hbasePath = "/namespaces/hbase";
Response response;
// Check that doesn't exist via non-REST call.
Admin admin = TEST_UTIL.getAdmin();
assertNotNull(findNamespace(admin, "default"));
assertNotNull(findNamespace(admin, "hbase"));
// Try (but fail) to delete namespaces via REST.
response = client.delete(defaultPath);
assertEquals(503, response.getCode());
response = client.delete(hbasePath);
assertEquals(503, response.getCode());
assertNotNull(findNamespace(admin, "default"));
assertNotNull(findNamespace(admin, "hbase"));
}
use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.
the class TestNamespacesInstanceResource method testNamespaceCreateAndDeleteXMLAndJSON.
@Test
public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBException {
String namespacePath1 = "/namespaces/" + NAMESPACE1;
String namespacePath2 = "/namespaces/" + NAMESPACE2;
NamespacesInstanceModel model1;
NamespacesInstanceModel model2;
Response response;
// Check that namespaces don't exist via non-REST call.
Admin admin = TEST_UTIL.getAdmin();
assertNull(findNamespace(admin, NAMESPACE1));
assertNull(findNamespace(admin, NAMESPACE2));
model1 = testNamespacesInstanceModel.buildTestModel(NAMESPACE1, NAMESPACE1_PROPS);
testNamespacesInstanceModel.checkModel(model1, NAMESPACE1, NAMESPACE1_PROPS);
model2 = testNamespacesInstanceModel.buildTestModel(NAMESPACE2, NAMESPACE2_PROPS);
testNamespacesInstanceModel.checkModel(model2, NAMESPACE2, NAMESPACE2_PROPS);
// Test cannot PUT (alter) non-existent namespace.
response = client.put(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
assertEquals(403, response.getCode());
String jsonString = jsonMapper.writeValueAsString(model2);
response = client.put(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(403, response.getCode());
// Test cannot create tables when in read only mode.
conf.set("hbase.rest.readonly", "true");
response = client.post(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
assertEquals(403, response.getCode());
jsonString = jsonMapper.writeValueAsString(model2);
response = client.post(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(403, response.getCode());
NamespaceDescriptor nd1 = findNamespace(admin, NAMESPACE1);
NamespaceDescriptor nd2 = findNamespace(admin, NAMESPACE2);
assertNull(nd1);
assertNull(nd2);
conf.set("hbase.rest.readonly", "false");
// Create namespace via XML and JSON.
response = client.post(namespacePath1, Constants.MIMETYPE_XML, toXML(model1));
assertEquals(201, response.getCode());
jsonString = jsonMapper.writeValueAsString(model2);
response = client.post(namespacePath2, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
assertEquals(201, response.getCode());
// check passing null content-type with a payload returns 415
Header[] nullHeaders = null;
response = client.post(namespacePath1, nullHeaders, toXML(model1));
assertEquals(415, response.getCode());
response = client.post(namespacePath1, nullHeaders, Bytes.toBytes(jsonString));
assertEquals(415, response.getCode());
// Check that created namespaces correctly.
nd1 = findNamespace(admin, NAMESPACE1);
nd2 = findNamespace(admin, NAMESPACE2);
assertNotNull(nd1);
assertNotNull(nd2);
checkNamespaceProperties(nd1, NAMESPACE1_PROPS);
checkNamespaceProperties(nd1, NAMESPACE1_PROPS);
// Test cannot delete tables when in read only mode.
conf.set("hbase.rest.readonly", "true");
response = client.delete(namespacePath1);
assertEquals(403, response.getCode());
response = client.delete(namespacePath2);
assertEquals(403, response.getCode());
nd1 = findNamespace(admin, NAMESPACE1);
nd2 = findNamespace(admin, NAMESPACE2);
assertNotNull(nd1);
assertNotNull(nd2);
conf.set("hbase.rest.readonly", "false");
// Delete namespaces via XML and JSON.
response = client.delete(namespacePath1);
assertEquals(200, response.getCode());
response = client.delete(namespacePath2);
assertEquals(200, response.getCode());
nd1 = findNamespace(admin, NAMESPACE1);
nd2 = findNamespace(admin, NAMESPACE2);
assertNull(nd1);
assertNull(nd2);
}
Aggregations