001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.rest; 019 020import static org.junit.Assert.assertEquals; 021 022import com.fasterxml.jackson.databind.ObjectMapper; 023import java.io.ByteArrayInputStream; 024import java.io.IOException; 025import java.io.StringWriter; 026import java.util.Base64; 027import java.util.HashMap; 028import java.util.Map; 029import javax.xml.bind.JAXBContext; 030import javax.xml.bind.JAXBException; 031import javax.xml.bind.Marshaller; 032import javax.xml.bind.Unmarshaller; 033import org.apache.hadoop.conf.Configuration; 034import org.apache.hadoop.hbase.HBaseTestingUtility; 035import org.apache.hadoop.hbase.HColumnDescriptor; 036import org.apache.hadoop.hbase.HTableDescriptor; 037import org.apache.hadoop.hbase.TableName; 038import org.apache.hadoop.hbase.client.Admin; 039import org.apache.hadoop.hbase.rest.client.Client; 040import org.apache.hadoop.hbase.rest.client.Cluster; 041import org.apache.hadoop.hbase.rest.client.Response; 042import org.apache.hadoop.hbase.rest.model.CellModel; 043import org.apache.hadoop.hbase.rest.model.CellSetModel; 044import org.apache.hadoop.hbase.rest.model.RowModel; 045import org.apache.hadoop.hbase.util.Bytes; 046import org.apache.http.Header; 047import org.apache.http.message.BasicHeader; 048import org.junit.After; 049import org.junit.AfterClass; 050import org.junit.Before; 051import org.junit.BeforeClass; 052 053import org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; 054import org.apache.hbase.thirdparty.javax.ws.rs.core.MediaType; 055 056public class RowResourceBase { 057 protected static final String TABLE = "TestRowResource"; 058 059 protected static final TableName TABLE_NAME = TableName.valueOf(TABLE); 060 061 protected static final String CFA = "a"; 062 protected static final String CFB = "b"; 063 protected static final String COLUMN_1 = CFA + ":1"; 064 protected static final String COLUMN_2 = CFB + ":2"; 065 protected static final String COLUMN_3 = CFA + ":"; 066 protected static final String ROW_1 = "testrow1"; 067 protected static final String VALUE_1 = "testvalue1"; 068 protected static final String ROW_2 = "testrow2"; 069 protected static final String VALUE_2 = "testvalue2"; 070 protected static final String ROW_3 = "testrow3"; 071 protected static final String VALUE_3 = "testvalue3"; 072 protected static final String ROW_4 = "testrow4"; 073 protected static final String VALUE_4 = "testvalue4"; 074 protected static final String VALUE_5 = "5"; 075 protected static final String VALUE_6 = "6"; 076 077 protected static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 078 protected static final HBaseRESTTestingUtility REST_TEST_UTIL = new HBaseRESTTestingUtility(); 079 protected static Client client; 080 protected static JAXBContext context; 081 protected static Marshaller xmlMarshaller; 082 protected static Unmarshaller xmlUnmarshaller; 083 protected static Configuration conf; 084 protected static ObjectMapper jsonMapper; 085 086 @BeforeClass 087 public static void setUpBeforeClass() throws Exception { 088 conf = TEST_UTIL.getConfiguration(); 089 TEST_UTIL.startMiniCluster(3); 090 REST_TEST_UTIL.startServletContainer(conf); 091 context = JAXBContext.newInstance(CellModel.class, CellSetModel.class, RowModel.class); 092 xmlMarshaller = context.createMarshaller(); 093 xmlUnmarshaller = context.createUnmarshaller(); 094 jsonMapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, 095 MediaType.APPLICATION_JSON_TYPE); 096 client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); 097 } 098 099 @AfterClass 100 public static void tearDownAfterClass() throws Exception { 101 REST_TEST_UTIL.shutdownServletContainer(); 102 TEST_UTIL.shutdownMiniCluster(); 103 } 104 105 @Before 106 public void beforeMethod() throws Exception { 107 Admin admin = TEST_UTIL.getAdmin(); 108 if (admin.tableExists(TABLE_NAME)) { 109 TEST_UTIL.deleteTable(TABLE_NAME); 110 } 111 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLE)); 112 htd.addFamily(new HColumnDescriptor(CFA)); 113 htd.addFamily(new HColumnDescriptor(CFB)); 114 admin.createTable(htd); 115 } 116 117 @After 118 public void afterMethod() throws Exception { 119 Admin admin = TEST_UTIL.getAdmin(); 120 if (admin.tableExists(TABLE_NAME)) { 121 TEST_UTIL.deleteTable(TABLE_NAME); 122 } 123 } 124 125 static Response putValuePB(String table, String row, String column, String value) 126 throws IOException { 127 StringBuilder path = new StringBuilder(); 128 path.append('/'); 129 path.append(table); 130 path.append('/'); 131 path.append(row); 132 path.append('/'); 133 path.append(column); 134 return putValuePB(path.toString(), table, row, column, value); 135 } 136 137 static Response putValuePB(String url, String table, String row, String column, String value) 138 throws IOException { 139 RowModel rowModel = new RowModel(row); 140 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value))); 141 CellSetModel cellSetModel = new CellSetModel(); 142 cellSetModel.addRow(rowModel); 143 Response response = 144 client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); 145 Thread.yield(); 146 return response; 147 } 148 149 protected static void checkValueXML(String url, String table, String row, String column, 150 String value) throws IOException, JAXBException { 151 Response response = getValueXML(url); 152 assertEquals(200, response.getCode()); 153 assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); 154 CellSetModel cellSet = 155 (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); 156 RowModel rowModel = cellSet.getRows().get(0); 157 CellModel cell = rowModel.getCells().get(0); 158 assertEquals(Bytes.toString(cell.getColumn()), column); 159 assertEquals(Bytes.toString(cell.getValue()), value); 160 } 161 162 protected static void checkValueXML(String table, String row, String column, String value) 163 throws IOException, JAXBException { 164 Response response = getValueXML(table, row, column); 165 assertEquals(200, response.getCode()); 166 assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); 167 CellSetModel cellSet = 168 (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody())); 169 RowModel rowModel = cellSet.getRows().get(0); 170 CellModel cell = rowModel.getCells().get(0); 171 assertEquals(Bytes.toString(cell.getColumn()), column); 172 assertEquals(Bytes.toString(cell.getValue()), value); 173 } 174 175 protected static void checkIncrementValueXML(String table, String row, String column, long value) 176 throws IOException, JAXBException { 177 Response response1 = getValueXML(table, row, column); 178 assertEquals(200, response1.getCode()); 179 assertEquals(Constants.MIMETYPE_XML, response1.getHeader("content-type")); 180 CellSetModel cellSet = 181 (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response1.getBody())); 182 RowModel rowModel = cellSet.getRows().get(0); 183 CellModel cell = rowModel.getCells().get(0); 184 assertEquals(Bytes.toString(cell.getColumn()), column); 185 assertEquals(Bytes.toLong(cell.getValue()), value); 186 } 187 188 protected static Response getValuePB(String url) throws IOException { 189 Response response = client.get(url, Constants.MIMETYPE_PROTOBUF); 190 return response; 191 } 192 193 protected static Response putValueXML(String table, String row, String column, String value) 194 throws IOException, JAXBException { 195 StringBuilder path = new StringBuilder(); 196 path.append('/'); 197 path.append(table); 198 path.append('/'); 199 path.append(row); 200 path.append('/'); 201 path.append(column); 202 return putValueXML(path.toString(), table, row, column, value); 203 } 204 205 protected static Response putValueXML(String url, String table, String row, String column, 206 String value) throws IOException, JAXBException { 207 RowModel rowModel = new RowModel(row); 208 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value))); 209 CellSetModel cellSetModel = new CellSetModel(); 210 cellSetModel.addRow(rowModel); 211 StringWriter writer = new StringWriter(); 212 xmlMarshaller.marshal(cellSetModel, writer); 213 Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString())); 214 Thread.yield(); 215 return response; 216 } 217 218 protected static Response getValuePB(String table, String row, String column) throws IOException { 219 StringBuilder path = new StringBuilder(); 220 path.append('/'); 221 path.append(table); 222 path.append('/'); 223 path.append(row); 224 path.append('/'); 225 path.append(column); 226 return getValuePB(path.toString()); 227 } 228 229 protected static void checkValuePB(String table, String row, String column, String value) 230 throws IOException { 231 Response response = getValuePB(table, row, column); 232 assertEquals(200, response.getCode()); 233 assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); 234 CellSetModel cellSet = new CellSetModel(); 235 cellSet.getObjectFromMessage(response.getBody()); 236 RowModel rowModel = cellSet.getRows().get(0); 237 CellModel cell = rowModel.getCells().get(0); 238 assertEquals(Bytes.toString(cell.getColumn()), column); 239 assertEquals(Bytes.toString(cell.getValue()), value); 240 } 241 242 protected static void checkIncrementValuePB(String table, String row, String column, long value) 243 throws IOException { 244 Response response = getValuePB(table, row, column); 245 assertEquals(200, response.getCode()); 246 assertEquals(Constants.MIMETYPE_PROTOBUF, response.getHeader("content-type")); 247 CellSetModel cellSet = new CellSetModel(); 248 cellSet.getObjectFromMessage(response.getBody()); 249 RowModel rowModel = cellSet.getRows().get(0); 250 CellModel cell = rowModel.getCells().get(0); 251 assertEquals(Bytes.toString(cell.getColumn()), column); 252 assertEquals(Bytes.toLong(cell.getValue()), value); 253 } 254 255 protected static Response checkAndPutValuePB(String url, String table, String row, String column, 256 String valueToCheck, String valueToPut, HashMap<String, String> otherCells) throws IOException { 257 RowModel rowModel = new RowModel(row); 258 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut))); 259 260 if (otherCells != null) { 261 for (Map.Entry<String, String> entry : otherCells.entrySet()) { 262 rowModel 263 .addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); 264 } 265 } 266 267 // This Cell need to be added as last cell. 268 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); 269 270 CellSetModel cellSetModel = new CellSetModel(); 271 cellSetModel.addRow(rowModel); 272 Response response = 273 client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); 274 Thread.yield(); 275 return response; 276 } 277 278 protected static Response checkAndPutValuePB(String table, String row, String column, 279 String valueToCheck, String valueToPut) throws IOException { 280 return checkAndPutValuePB(table, row, column, valueToCheck, valueToPut, null); 281 } 282 283 protected static Response checkAndPutValuePB(String table, String row, String column, 284 String valueToCheck, String valueToPut, HashMap<String, String> otherCells) throws IOException { 285 StringBuilder path = new StringBuilder(); 286 path.append('/'); 287 path.append(table); 288 path.append('/'); 289 path.append(row); 290 path.append("?check=put"); 291 return checkAndPutValuePB(path.toString(), table, row, column, valueToCheck, valueToPut, 292 otherCells); 293 } 294 295 protected static Response checkAndPutValueXML(String url, String table, String row, String column, 296 String valueToCheck, String valueToPut, HashMap<String, String> otherCells) 297 throws IOException, JAXBException { 298 RowModel rowModel = new RowModel(row); 299 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut))); 300 301 if (otherCells != null) { 302 for (Map.Entry<String, String> entry : otherCells.entrySet()) { 303 rowModel 304 .addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); 305 } 306 } 307 308 // This Cell need to be added as last cell. 309 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); 310 CellSetModel cellSetModel = new CellSetModel(); 311 cellSetModel.addRow(rowModel); 312 StringWriter writer = new StringWriter(); 313 xmlMarshaller.marshal(cellSetModel, writer); 314 Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString())); 315 Thread.yield(); 316 return response; 317 } 318 319 protected static Response checkAndPutValueXML(String table, String row, String column, 320 String valueToCheck, String valueToPut) throws IOException, JAXBException { 321 return checkAndPutValueXML(table, row, column, valueToCheck, valueToPut, null); 322 } 323 324 protected static Response checkAndPutValueXML(String table, String row, String column, 325 String valueToCheck, String valueToPut, HashMap<String, String> otherCells) 326 throws IOException, JAXBException { 327 StringBuilder path = new StringBuilder(); 328 path.append('/'); 329 path.append(table); 330 path.append('/'); 331 path.append(row); 332 path.append("?check=put"); 333 return checkAndPutValueXML(path.toString(), table, row, column, valueToCheck, valueToPut, 334 otherCells); 335 } 336 337 protected static Response checkAndDeleteXML(String url, String table, String row, String column, 338 String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException, JAXBException { 339 RowModel rowModel = new RowModel(row); 340 341 if (cellsToDelete != null) { 342 for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) { 343 rowModel 344 .addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); 345 } 346 } 347 // Add this at the end 348 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); 349 CellSetModel cellSetModel = new CellSetModel(); 350 cellSetModel.addRow(rowModel); 351 StringWriter writer = new StringWriter(); 352 xmlMarshaller.marshal(cellSetModel, writer); 353 Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString())); 354 Thread.yield(); 355 return response; 356 } 357 358 protected static Response checkAndDeleteXML(String table, String row, String column, 359 String valueToCheck) throws IOException, JAXBException { 360 return checkAndDeleteXML(table, row, column, valueToCheck, null); 361 } 362 363 protected static Response checkAndDeleteXML(String table, String row, String column, 364 String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException, JAXBException { 365 StringBuilder path = new StringBuilder(); 366 path.append('/'); 367 path.append(table); 368 path.append('/'); 369 path.append(row); 370 path.append("?check=delete"); 371 return checkAndDeleteXML(path.toString(), table, row, column, valueToCheck, cellsToDelete); 372 } 373 374 protected static Response checkAndDeleteJson(String table, String row, String column, 375 String valueToCheck) throws IOException { 376 return checkAndDeleteJson(table, row, column, valueToCheck, null); 377 } 378 379 protected static Response checkAndDeleteJson(String table, String row, String column, 380 String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException { 381 StringBuilder path = new StringBuilder(); 382 path.append('/'); 383 path.append(table); 384 path.append('/'); 385 path.append(row); 386 path.append("?check=delete"); 387 return checkAndDeleteJson(path.toString(), table, row, column, valueToCheck, cellsToDelete); 388 } 389 390 protected static Response checkAndDeleteJson(String url, String table, String row, String column, 391 String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException { 392 RowModel rowModel = new RowModel(row); 393 394 if (cellsToDelete != null) { 395 for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) { 396 rowModel 397 .addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); 398 } 399 } 400 // Add this at the end 401 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); 402 CellSetModel cellSetModel = new CellSetModel(); 403 cellSetModel.addRow(rowModel); 404 String jsonString = jsonMapper.writeValueAsString(cellSetModel); 405 Response response = client.put(url, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString)); 406 Thread.yield(); 407 return response; 408 } 409 410 protected static Response checkAndDeletePB(String table, String row, String column, String value) 411 throws IOException { 412 return checkAndDeletePB(table, row, column, value, null); 413 } 414 415 protected static Response checkAndDeletePB(String table, String row, String column, String value, 416 HashMap<String, String> cellsToDelete) throws IOException { 417 StringBuilder path = new StringBuilder(); 418 path.append('/'); 419 path.append(table); 420 path.append('/'); 421 path.append(row); 422 path.append("?check=delete"); 423 return checkAndDeleteValuePB(path.toString(), table, row, column, value, cellsToDelete); 424 } 425 426 protected static Response checkAndDeleteValuePB(String url, String table, String row, 427 String column, String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException { 428 RowModel rowModel = new RowModel(row); 429 430 if (cellsToDelete != null) { 431 for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) { 432 rowModel 433 .addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); 434 } 435 } 436 // Add this at the end 437 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); 438 CellSetModel cellSetModel = new CellSetModel(); 439 cellSetModel.addRow(rowModel); 440 Response response = 441 client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); 442 Thread.yield(); 443 return response; 444 } 445 446 protected static Response getValueXML(String table, String startRow, String endRow, String column) 447 throws IOException { 448 StringBuilder path = new StringBuilder(); 449 path.append('/'); 450 path.append(table); 451 path.append('/'); 452 path.append(startRow); 453 path.append(","); 454 path.append(endRow); 455 path.append('/'); 456 path.append(column); 457 return getValueXML(path.toString()); 458 } 459 460 protected static Response getValueXML(String url) throws IOException { 461 Response response = client.get(url, Constants.MIMETYPE_XML); 462 return response; 463 } 464 465 protected static Response getValueXML(String url, Header[] headers) throws IOException { 466 Header[] fullHeaders = new Header[headers.length + 1]; 467 for (int i = 0; i < headers.length; i++) 468 fullHeaders[i] = headers[i]; 469 fullHeaders[headers.length] = new BasicHeader("Accept", Constants.MIMETYPE_XML); 470 Response response = client.get(url, fullHeaders); 471 return response; 472 } 473 474 protected static Response getValueJson(String url) throws IOException { 475 Response response = client.get(url, Constants.MIMETYPE_JSON); 476 return response; 477 } 478 479 protected static Response deleteValue(String table, String row, String column) 480 throws IOException { 481 StringBuilder path = new StringBuilder(); 482 path.append('/'); 483 path.append(table); 484 path.append('/'); 485 path.append(row); 486 path.append('/'); 487 path.append(column); 488 Response response = client.delete(path.toString()); 489 Thread.yield(); 490 return response; 491 } 492 493 protected static Response deleteValueB64(String table, String row, String column, 494 boolean useQueryString) throws IOException { 495 StringBuilder path = new StringBuilder(); 496 Base64.Encoder encoder = Base64.getUrlEncoder(); 497 path.append('/'); 498 path.append(table); 499 path.append('/'); 500 path.append(encoder.encodeToString(row.getBytes("UTF-8"))); 501 path.append('/'); 502 path.append(encoder.encodeToString(column.getBytes("UTF-8"))); 503 504 Response response; 505 if (useQueryString) { 506 path.append("?e=b64"); 507 response = client.delete(path.toString()); 508 } else { 509 response = client.delete(path.toString(), new BasicHeader("Encoding", "b64")); 510 } 511 Thread.yield(); 512 return response; 513 } 514 515 protected static Response getValueXML(String table, String row, String column) 516 throws IOException { 517 StringBuilder path = new StringBuilder(); 518 path.append('/'); 519 path.append(table); 520 path.append('/'); 521 path.append(row); 522 path.append('/'); 523 path.append(column); 524 return getValueXML(path.toString()); 525 } 526 527 protected static Response deleteRow(String table, String row) throws IOException { 528 StringBuilder path = new StringBuilder(); 529 path.append('/'); 530 path.append(table); 531 path.append('/'); 532 path.append(row); 533 Response response = client.delete(path.toString()); 534 Thread.yield(); 535 return response; 536 } 537 538 protected static Response deleteRowB64(String table, String row, boolean useQueryString) 539 throws IOException { 540 StringBuilder path = new StringBuilder(); 541 Base64.Encoder encoder = Base64.getUrlEncoder(); 542 path.append('/'); 543 path.append(table); 544 path.append('/'); 545 path.append(encoder.encodeToString(row.getBytes("UTF-8"))); 546 547 Response response; 548 if (useQueryString) { 549 path.append("?e=b64"); 550 response = client.delete(path.toString()); 551 } else { 552 response = client.delete(path.toString(), new BasicHeader("Encoding", "b64")); 553 } 554 Thread.yield(); 555 return response; 556 } 557 558 protected static Response getValueJson(String table, String row, String column) 559 throws IOException { 560 StringBuilder path = new StringBuilder(); 561 path.append('/'); 562 path.append(table); 563 path.append('/'); 564 path.append(row); 565 path.append('/'); 566 path.append(column); 567 return getValueJson(path.toString()); 568 } 569 570 protected static void checkValueJSON(String table, String row, String column, String value) 571 throws IOException { 572 Response response = getValueJson(table, row, column); 573 assertEquals(200, response.getCode()); 574 assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); 575 ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, 576 MediaType.APPLICATION_JSON_TYPE); 577 CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class); 578 RowModel rowModel = cellSet.getRows().get(0); 579 CellModel cell = rowModel.getCells().get(0); 580 assertEquals(Bytes.toString(cell.getColumn()), column); 581 assertEquals(Bytes.toString(cell.getValue()), value); 582 } 583 584 protected static void checkIncrementValueJSON(String table, String row, String column, long value) 585 throws IOException { 586 Response response = getValueJson(table, row, column); 587 assertEquals(200, response.getCode()); 588 assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); 589 ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, 590 MediaType.APPLICATION_JSON_TYPE); 591 CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class); 592 RowModel rowModel = cellSet.getRows().get(0); 593 CellModel cell = rowModel.getCells().get(0); 594 assertEquals(Bytes.toString(cell.getColumn()), column); 595 assertEquals(Bytes.toLong(cell.getValue()), value); 596 } 597 598 protected static Response putValueJson(String table, String row, String column, String value) 599 throws IOException { 600 StringBuilder path = new StringBuilder(); 601 path.append('/'); 602 path.append(table); 603 path.append('/'); 604 path.append(row); 605 path.append('/'); 606 path.append(column); 607 return putValueJson(path.toString(), table, row, column, value); 608 } 609 610 protected static Response putValueJson(String url, String table, String row, String column, 611 String value) throws IOException { 612 RowModel rowModel = new RowModel(row); 613 rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value))); 614 CellSetModel cellSetModel = new CellSetModel(); 615 cellSetModel.addRow(rowModel); 616 String jsonString = jsonMapper.writeValueAsString(cellSetModel); 617 Response response = client.put(url, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString)); 618 Thread.yield(); 619 return response; 620 } 621 622 protected static Response appendValueXML(String table, String row, String column, String value) 623 throws IOException, JAXBException { 624 StringBuilder path = new StringBuilder(); 625 path.append('/'); 626 path.append(table); 627 path.append('/'); 628 path.append(row); 629 path.append("?check=append"); 630 return putValueXML(path.toString(), table, row, column, value); 631 } 632 633 protected static Response appendValuePB(String table, String row, String column, String value) 634 throws IOException { 635 StringBuilder path = new StringBuilder(); 636 path.append('/'); 637 path.append(table); 638 path.append('/'); 639 path.append(row); 640 path.append("?check=append"); 641 return putValuePB(path.toString(), table, row, column, value); 642 } 643 644 protected static Response appendValueJson(String table, String row, String column, String value) 645 throws IOException, JAXBException { 646 StringBuilder path = new StringBuilder(); 647 path.append('/'); 648 path.append(table); 649 path.append('/'); 650 path.append(row); 651 path.append("?check=append"); 652 return putValueJson(path.toString(), table, row, column, value); 653 } 654 655 protected static Response incrementValueXML(String table, String row, String column, String value) 656 throws IOException, JAXBException { 657 StringBuilder path = new StringBuilder(); 658 path.append('/'); 659 path.append(table); 660 path.append('/'); 661 path.append(row); 662 path.append("?check=increment"); 663 return putValueXML(path.toString(), table, row, column, value); 664 } 665 666 protected static Response incrementValuePB(String table, String row, String column, String value) 667 throws IOException { 668 StringBuilder path = new StringBuilder(); 669 path.append('/'); 670 path.append(table); 671 path.append('/'); 672 path.append(row); 673 path.append("?check=increment"); 674 return putValuePB(path.toString(), table, row, column, value); 675 } 676 677 protected static Response incrementValueJson(String table, String row, String column, 678 String value) throws IOException, JAXBException { 679 StringBuilder path = new StringBuilder(); 680 path.append('/'); 681 path.append(table); 682 path.append('/'); 683 path.append(row); 684 path.append("?check=increment"); 685 return putValueJson(path.toString(), table, row, column, value); 686 } 687}