@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); testTableSchemaModel = new TestTableSchemaModel(); context = JAXBContext.newInstance( ColumnSchemaModel.class, TableSchemaModel.class); }
@Test public void testTableCreateAndDeleteXML() throws IOException, JAXBException { String schemaPath = "/" + TABLE1 + "/schema"; TableSchemaModel model; Response response; HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); assertFalse(admin.tableExists(TABLE1)); // create the table model = TestTableSchemaModel.buildTestModel(TABLE1); TestTableSchemaModel.checkModel(model, TABLE1); response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model)); assertEquals(response.getCode(), 201); // recall the same put operation but in read-only mode conf.set("hbase.rest.readonly", "true"); response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model)); assertEquals(response.getCode(), 403); // 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); // test delete schema operation is forbidden in read-only mode response = client.delete(schemaPath); assertEquals(response.getCode(), 403); // return read-only setting back to default conf.set("hbase.rest.readonly", "false"); // delete the table and make sure HBase concurs response = client.delete(schemaPath); assertEquals(response.getCode(), 200); assertFalse(admin.tableExists(TABLE1)); }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, ""); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); testTableSchemaModel = new TestTableSchemaModel(); context = JAXBContext.newInstance( ColumnSchemaModel.class, TableSchemaModel.class); }
@Test public void testTableCreateAndDeleteXML() throws IOException, JAXBException { String schemaPath = "/" + TABLE1 + "/schema"; TableSchemaModel model; Response response; HBaseAdmin admin = TEST_UTIL.getHBaseAdmin(); assertFalse(admin.tableExists(TABLE1)); // create the table model = TestTableSchemaModel.buildTestModel(TABLE1); TestTableSchemaModel.checkModel(model, TABLE1); response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model)); assertEquals(response.getCode(), 201); // recall the same put operation but in read-only mode conf.set("hbase.rest.readonly", "true"); response = client.put(schemaPath, Constants.MIMETYPE_XML, toXML(model)); assertEquals(response.getCode(), 403); // 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); // delete the table client.delete(schemaPath); // make sure HBase concurs assertFalse(admin.tableExists(TABLE1)); // return read-only setting back to default conf.set("hbase.rest.readonly", "false"); }