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.client;
019
020import org.apache.hadoop.hbase.HBaseClassTestRule;
021import org.apache.hadoop.hbase.testclassification.ClientTests;
022import org.apache.hadoop.hbase.testclassification.SmallTests;
023import org.apache.hadoop.hbase.util.Bytes;
024import org.junit.Assert;
025import org.junit.Before;
026import org.junit.ClassRule;
027import org.junit.Test;
028import org.junit.experimental.categories.Category;
029
030@Category({ ClientTests.class, SmallTests.class })
031/**
032 * Addresses HBASE-6047 We test put.has call with all of its polymorphic magic
033 */
034public class TestPutDotHas {
035
036  @ClassRule
037  public static final HBaseClassTestRule CLASS_RULE =
038    HBaseClassTestRule.forClass(TestPutDotHas.class);
039
040  public static final byte[] ROW_01 = Bytes.toBytes("row-01");
041  public static final byte[] QUALIFIER_01 = Bytes.toBytes("qualifier-01");
042  public static final byte[] VALUE_01 = Bytes.toBytes("value-01");
043  public static final byte[] FAMILY_01 = Bytes.toBytes("family-01");
044  public static final long TS = 1234567L;
045  public Put put = new Put(ROW_01);
046
047  @Before
048  public void setUp() {
049    put.addColumn(FAMILY_01, QUALIFIER_01, TS, VALUE_01);
050  }
051
052  @Test
053  public void testHasIgnoreValueIgnoreTS() {
054    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01));
055    Assert.assertFalse(put.has(QUALIFIER_01, FAMILY_01));
056  }
057
058  @Test
059  public void testHasIgnoreValue() {
060    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, TS));
061    Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS + 1));
062  }
063
064  @Test
065  public void testHasIgnoreTS() {
066    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, VALUE_01));
067    Assert.assertFalse(put.has(FAMILY_01, VALUE_01, QUALIFIER_01));
068  }
069
070  @Test
071  public void testHas() {
072    Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, TS, VALUE_01));
073    // Bad TS
074    Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS + 1, VALUE_01));
075    // Bad Value
076    Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS, QUALIFIER_01));
077    // Bad Family
078    Assert.assertFalse(put.has(QUALIFIER_01, QUALIFIER_01, TS, VALUE_01));
079    // Bad Qual
080    Assert.assertFalse(put.has(FAMILY_01, FAMILY_01, TS, VALUE_01));
081  }
082}