/**
 * Copyright 2007 The Apache Software Foundation
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.hbase.filter;

import junit.framework.TestCase;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.SmallTests;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.experimental.categories.Category;

/**
 * Tests for {@link SingleColumnValueExcludeFilter}. Because this filter
 * extends {@link SingleColumnValueFilter}, only the added functionality is
 * tested. That is, method filterKeyValue(KeyValue).
 *
 * @author ferdy
 *
 */
@Category(SmallTests.class)
public class TestSingleColumnValueExcludeFilter extends TestCase {
  private static final byte[] ROW = Bytes.toBytes("test");
  private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test");
  private static final byte[] COLUMN_QUALIFIER = Bytes.toBytes("foo");
  private static final byte[] COLUMN_QUALIFIER_2 = Bytes.toBytes("foo_2");
  private static final byte[] VAL_1 = Bytes.toBytes("a");
  private static final byte[] VAL_2 = Bytes.toBytes("ab");

  /**
   * Test the overridden functionality of filterKeyValue(KeyValue)
   * @throws Exception
   */
  public void testFilterKeyValue() throws Exception {
    Filter filter = new SingleColumnValueExcludeFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
        CompareOp.EQUAL, VAL_1);

    // A 'match' situation
    KeyValue kv;
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);
    // INCLUDE expected because test column has not yet passed
    assertTrue("otherColumn", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1);
    // Test column will pass (will match), will SKIP because test columns are excluded
    assertTrue("testedMatch", filter.filterKeyValue(kv) == Filter.ReturnCode.SKIP);
    // Test column has already passed and matched, all subsequent columns are INCLUDE
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);
    assertTrue("otherColumn", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    assertFalse("allRemainingWhenMatch", filter.filterAllRemaining());

    // A 'mismatch' situation
    filter.reset();
    // INCLUDE expected because test column has not yet passed
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);
    assertTrue("otherColumn", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    // Test column will pass (wont match), expect NEXT_ROW
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_2);
    assertTrue("testedMismatch", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW);
    // After a mismatch (at least with LatestVersionOnly), subsequent columns are EXCLUDE
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);
    assertTrue("otherColumn", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW);
  }


  @org.junit.Rule
  public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
    new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
}


@@ -1167,16 +1167,67 @@
 ategory;
+%0Aimport java.util.List;%0Aimport java.util.ArrayList;
 %0A%0A/**%0A *
@@ -2249,24 +2249,29 @@
 ion%0A    
+List%3C
 KeyValue
  kv;%0A   
@@ -2266,16 +2266,55 @@
 alue
+%3E
  kv
-;%0A   
+s = new ArrayList%3CKeyValue%3E();%0A    KeyValue
  kv 
@@ -2380,155 +2380,81 @@
 1);%0A
-    // INCLUDE expected because test column has not yet passed%0A    assertTrue(%22otherColumn%22, filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE
+%0A    kvs.add (new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1)
 );%0A 
@@ -2454,27 +2454,31 @@
 _1));%0A    kv
- = 
+s.add (
 new KeyValue
@@ -2526,492 +2526,313 @@
 L_1)
+)
 ;%0A    
-// Test column will pass (will match), will SKIP because test columns are excluded%0A    assertTrue(%22testedMatch%22, filter.filterKeyValue(kv) == Filter.ReturnCode.SKIP);%0A    // Test column has already passed and matched, all subsequent columns are INCLUDE%0A    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1);%0A    assertTrue(%22otherColumn%22, filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);%0A    assertFalse(%22allRemainingWhenMatch%22, filter.filterAllRemaining()
+kvs.add (new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER_2, VAL_1));%0A%0A    filter.filterRow(kvs);%0A%0A    assertEquals(%22resultSize%22, kvs.size(), 2);%0A    assertTrue(%22leftKV1%22, KeyValue.COMPARATOR.compare(kvs.get(0), kv) == 0);%0A    assertTrue(%22leftKV2%22, KeyValue.COMPARATOR.compare(kvs.get(1), kv) == 0
 );%0A%0A
@@ -3714,11 +3714,10 @@
 Rule();%0A
+
 %7D%0A
-%0A

Modify test to match new filter logic.