SearchOptionsHandler extends ActionHandler { protected boolean shouldBeIncluded(SearchableChannel channel, User user) { if(!channel.getCapabilities().canTextSearch()) { return false; } if(blacklist.contains(channel.getId())) { return false; } return channel.hasPermission(user); }  void setSearchService(SearchService service); @Override void init(); void handleAction(final ActionParameters params);  }
@Test public void testShouldBeIncludedNonTextualSearch() throws Exception { SearchChannel channel = mock(SearchChannel.class); mockCapabilities(channel, false); SearchOptionsHandler handler = getHandler(); assertFalse("Channel should not permitted if there's no textual capabilities", handler.shouldBeIncluded(channel, getGuestUser())); }
@Test public void testShouldBeIncludedTextualSearch() throws Exception { SearchChannel channel = mock(SearchChannel.class); mockCapabilities(channel, true); doReturn(true).when(channel).hasPermission(getGuestUser()); SearchOptionsHandler handler = getHandler(); assertTrue("Channel should be permitted if there's textual capabilities, no blacklist and user is permitted", handler.shouldBeIncluded(channel, getGuestUser())); }
@Test public void testShouldBeIncludedPermission() throws Exception { SearchChannel channel = mock(SearchChannel.class); mockCapabilities(channel, true); doReturn(false).when(channel).hasPermission(getGuestUser()); doReturn(true).when(channel).hasPermission(getLoggedInUser()); SearchOptionsHandler handler = getHandler(); assertFalse("Channel should not permitted for guest", handler.shouldBeIncluded(channel, getGuestUser())); assertTrue("Channel should be permitted for user", handler.shouldBeIncluded(channel, getLoggedInUser())); }
@Test public void testShouldBeIncludedBlacklist() throws Exception { SearchChannel channel = mock(SearchChannel.class); mockCapabilities(channel, true); doReturn(true).when(channel).hasPermission(any(User.class)); doReturn("TestChannel").when(channel).getId(); PropertyUtil.addProperty("actionhandler.SearchOptions.blacklist", "TestChannel"); SearchOptionsHandler handler = getHandler(); assertFalse("Channel should not permitted for guest", handler.shouldBeIncluded(channel, getGuestUser())); assertFalse("Channel should be permitted for user", handler.shouldBeIncluded(channel, getLoggedInUser())); PropertyUtil.clearProperties(); handler = getHandler(); assertTrue("Channel should not permitted for guest", handler.shouldBeIncluded(channel, getGuestUser())); assertTrue("Channel should be permitted for user", handler.shouldBeIncluded(channel, getLoggedInUser())); }