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