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 java.io.IOException; 023import javax.xml.bind.JAXBException; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.rest.client.Response; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.apache.hadoop.hbase.testclassification.RestTests; 028import org.junit.ClassRule; 029import org.junit.Test; 030import org.junit.experimental.categories.Category; 031 032@Category({RestTests.class, MediumTests.class}) 033public class TestDeleteRow extends RowResourceBase { 034 035 @ClassRule 036 public static final HBaseClassTestRule CLASS_RULE = 037 HBaseClassTestRule.forClass(TestDeleteRow.class); 038 039 @Test 040 public void testDeleteNonExistentColumn() throws Exception { 041 Response response = putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1); 042 assertEquals(200, response.getCode()); 043 044 response = checkAndDeleteJson(TABLE, ROW_1, COLUMN_1, VALUE_2); 045 assertEquals(304, response.getCode()); 046 assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode()); 047 048 response = checkAndDeleteJson(TABLE, ROW_2, COLUMN_1, VALUE_2); 049 assertEquals(304, response.getCode()); 050 assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode()); 051 052 response = checkAndDeleteJson(TABLE, ROW_1, "dummy", VALUE_1); 053 assertEquals(400, response.getCode()); 054 assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode()); 055 056 response = checkAndDeleteJson(TABLE, ROW_1, "dummy:test", VALUE_1); 057 assertEquals(404, response.getCode()); 058 assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode()); 059 060 response = checkAndDeleteJson(TABLE, ROW_1, "a:test", VALUE_1); 061 assertEquals(304, response.getCode()); 062 assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode()); 063 } 064 065 @Test 066 public void testDeleteXML() throws IOException, JAXBException { 067 Response response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); 068 assertEquals(200, response.getCode()); 069 response = putValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); 070 assertEquals(200, response.getCode()); 071 checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); 072 checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); 073 074 response = deleteValue(TABLE, ROW_1, COLUMN_1); 075 assertEquals(200, response.getCode()); 076 response = getValueXML(TABLE, ROW_1, COLUMN_1); 077 assertEquals(404, response.getCode()); 078 checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); 079 080 response = putValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); 081 assertEquals(200, response.getCode()); 082 response = checkAndDeletePB(TABLE, ROW_1, COLUMN_1, VALUE_1); 083 assertEquals(200, response.getCode()); 084 response = getValueXML(TABLE, ROW_1, COLUMN_1); 085 assertEquals(404, response.getCode()); 086 087 response = deleteRow(TABLE, ROW_1); 088 assertEquals(200, response.getCode()); 089 response = getValueXML(TABLE, ROW_1, COLUMN_1); 090 assertEquals(404, response.getCode()); 091 response = getValueXML(TABLE, ROW_1, COLUMN_2); 092 assertEquals(404, response.getCode()); 093 094 //Delete a row in non existent table 095 response = deleteValue("dummy", ROW_1, COLUMN_1); 096 assertEquals(404, response.getCode()); 097 098 //Delete non existent column 099 response = deleteValue(TABLE, ROW_1, "dummy"); 100 assertEquals(404, response.getCode()); 101 } 102 103}