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.hbtop.screen.top;
019
020import static org.hamcrest.CoreMatchers.is;
021import static org.hamcrest.MatcherAssert.assertThat;
022import static org.mockito.ArgumentMatchers.argThat;
023import static org.mockito.Mockito.verify;
024
025import java.util.ArrayList;
026import java.util.List;
027import java.util.stream.Collectors;
028import org.apache.hadoop.hbase.hbtop.RecordFilter;
029import org.apache.hadoop.hbase.hbtop.field.Field;
030import org.apache.hadoop.hbase.hbtop.field.FieldInfo;
031import org.apache.hadoop.hbase.hbtop.mode.Mode;
032import org.apache.hadoop.hbase.testclassification.SmallTests;
033import org.junit.jupiter.api.BeforeEach;
034import org.junit.jupiter.api.Tag;
035import org.junit.jupiter.api.Test;
036import org.junit.jupiter.api.extension.ExtendWith;
037import org.mockito.Mock;
038import org.mockito.junit.jupiter.MockitoExtension;
039
040@Tag(SmallTests.TAG)
041@ExtendWith(MockitoExtension.class)
042public class TestFilterDisplayModeScreenPresenter {
043
044  @Mock
045  private FilterDisplayModeScreenView filterDisplayModeScreenView;
046
047  @Mock
048  private TopScreenView topScreenView;
049
050  private FilterDisplayModeScreenPresenter filterDisplayModeScreenPresenter;
051
052  @BeforeEach
053  public void setup() {
054    List<Field> fields =
055      Mode.REGION.getFieldInfos().stream().map(FieldInfo::getField).collect(Collectors.toList());
056
057    List<RecordFilter> filters = new ArrayList<>();
058    filters.add(RecordFilter.parse("NAMESPACE==namespace", fields, true));
059    filters.add(RecordFilter.parse("TABLE==table", fields, true));
060
061    filterDisplayModeScreenPresenter =
062      new FilterDisplayModeScreenPresenter(filterDisplayModeScreenView, filters, topScreenView);
063  }
064
065  @Test
066  public void testInit() {
067    filterDisplayModeScreenPresenter.init();
068    verify(filterDisplayModeScreenView).showFilters(argThat(
069      filters -> filters.size() == 2 && filters.get(0).toString().equals("NAMESPACE==namespace")
070        && filters.get(1).toString().equals("TABLE==table")));
071  }
072
073  @Test
074  public void testReturnToTopScreen() {
075    assertThat(filterDisplayModeScreenPresenter.returnToNextScreen(), is(topScreenView));
076  }
077}