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.junit.Assert.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.HBaseClassTestRule; 029import org.apache.hadoop.hbase.hbtop.RecordFilter; 030import org.apache.hadoop.hbase.hbtop.field.Field; 031import org.apache.hadoop.hbase.hbtop.field.FieldInfo; 032import org.apache.hadoop.hbase.hbtop.mode.Mode; 033import org.apache.hadoop.hbase.testclassification.SmallTests; 034import org.junit.Before; 035import org.junit.ClassRule; 036import org.junit.Test; 037import org.junit.experimental.categories.Category; 038import org.junit.runner.RunWith; 039import org.mockito.Mock; 040import org.mockito.runners.MockitoJUnitRunner; 041 042 043@Category(SmallTests.class) 044@RunWith(MockitoJUnitRunner.class) 045public class FilterDisplayModeScreenPresenterTest { 046 047 @ClassRule 048 public static final HBaseClassTestRule CLASS_RULE = 049 HBaseClassTestRule.forClass(FilterDisplayModeScreenPresenterTest.class); 050 051 @Mock 052 private FilterDisplayModeScreenView filterDisplayModeScreenView; 053 054 @Mock 055 private TopScreenView topScreenView; 056 057 private FilterDisplayModeScreenPresenter filterDisplayModeScreenPresenter; 058 059 @Before 060 public void setup() { 061 List<Field> fields = Mode.REGION.getFieldInfos().stream() 062 .map(FieldInfo::getField) 063 .collect(Collectors.toList()); 064 065 List<RecordFilter> filters = new ArrayList<>(); 066 filters.add(RecordFilter.parse("NAMESPACE==namespace", fields, true)); 067 filters.add(RecordFilter.parse("TABLE==table", fields, true)); 068 069 filterDisplayModeScreenPresenter = new FilterDisplayModeScreenPresenter( 070 filterDisplayModeScreenView, filters, topScreenView); 071 } 072 073 @Test 074 public void testInit() { 075 filterDisplayModeScreenPresenter.init(); 076 verify(filterDisplayModeScreenView).showFilters(argThat(filters -> filters.size() == 2 077 && filters.get(0).toString().equals("NAMESPACE==namespace") 078 && filters.get(1).toString().equals("TABLE==table"))); 079 } 080 081 @Test 082 public void testReturnToTopScreen() { 083 assertThat(filterDisplayModeScreenPresenter.returnToNextScreen(), is(topScreenView)); 084 } 085}