/** * Send a GET request * @param path the path or URI * @return a Response object with response detail * @throws IOException */ public Response get(String path) throws IOException { return get(cluster, path); }
/** * Send a GET request * @param path the path or URI * @param accept Accept header value * @return a Response object with response detail * @throws IOException */ public Response get(String path, String accept) throws IOException { return get(cluster, path, accept); }
/** * Send a GET request * @param path the path or URI * @param headers the HTTP headers to include in the request, * <tt>Accept</tt> must be supplied * @return a Response object with response detail * @throws IOException */ public Response get(String path, Header[] headers) throws IOException { return get(cluster, path, headers); }
/** * Send a GET request * @param cluster the cluster definition * @param path the path or URI * @return a Response object with response detail * @throws IOException */ public Response get(Cluster cluster, String path) throws IOException { return get(cluster, path, EMPTY_HEADER_ARRAY); }
protected static Response getValueJson(String url) throws IOException { Response response = client.get(url, Constants.MIMETYPE_JSON); return response; }
protected static Response getValuePB(String url) throws IOException { Response response = client.get(url, Constants.MIMETYPE_PROTOBUF); return response; }
@Before public void setup() throws Exception { client = mock(Client.class); Response response = new Response(509); when(client.get(anyString(), anyString())).thenReturn(response); when(client.delete(anyString())).thenReturn(response); when(client.put(anyString(), anyString(), any())).thenReturn(response); when(client.post(anyString(), anyString(), any())).thenReturn(response); Configuration configuration = TEST_UTIL.getConfiguration(); configuration.setInt("hbase.rest.client.max.retries", RETRIES); configuration.setInt("hbase.rest.client.sleep", SLEEP_TIME); remoteAdmin = new RemoteAdmin(client, TEST_UTIL.getConfiguration(), "MyTable"); }
@Test public void testParsingClusterVersion() throws Exception { final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<ClusterVersion Version=\"2.0.0\"/>"; Client client = mock(Client.class); RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null); Response resp = new Response(200, null, Bytes.toBytes(xml)); when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp); StorageClusterVersionModel cv = admin.getClusterVersion(); assertEquals("2.0.0", cv.getVersion()); }
@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 testNoSuchCF() throws IOException, JAXBException { final String goodPath = "/" + TABLE + "/" + ROW_1 + "/" + CFA+":"; final String badPath = "/" + TABLE + "/" + ROW_1 + "/" + "BAD"; Response response = client.post(goodPath, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1)); assertEquals(200, response.getCode()); assertEquals(200, client.get(goodPath, Constants.MIMETYPE_BINARY).getCode()); assertEquals(404, client.get(badPath, Constants.MIMETYPE_BINARY).getCode()); assertEquals(200, client.get(goodPath, Constants.MIMETYPE_BINARY).getCode()); }
@Test public void testFilter() throws Exception { String path = "/status/cluster"; Response response = client.get(path); assertEquals(404, response.getCode()); } }
@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); }
@Test public void testTableInfoText() throws IOException { Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_TEXT); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); }
@Test public void testTableListJSON() throws IOException { Response response = client.get("/", Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); }
@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"); }
@Test public void testGetStorageClusterVersionText() throws IOException { Response response = client.get("/version/cluster", Constants.MIMETYPE_TEXT); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); }
@Test public void testTableListText() throws IOException { Response response = client.get("/", Constants.MIMETYPE_TEXT); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type")); }
@Test public void testTableInfoJSON() throws IOException { Response response = client.get("/" + TABLE + "/regions", Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); }