/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.search.facet.faceted.searcher.test; import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; import com.liferay.portal.kernel.model.Group; import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.search.Hits; import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.service.GroupLocalServiceUtil; import com.liferay.portal.kernel.test.rule.AggregateTestRule; import com.liferay.portal.kernel.test.rule.Sync; import com.liferay.portal.kernel.test.rule.SynchronousDestinationTestRule; import com.liferay.portal.kernel.test.util.RandomTestUtil; import com.liferay.portal.kernel.test.util.SearchContextTestUtil; import com.liferay.portal.search.test.util.SearchMapUtil; import com.liferay.portal.test.rule.LiferayIntegrationTestRule; import java.util.Collections; import java.util.Map; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Andrew Betts */ @RunWith(Arquillian.class) @Sync public class FacetedSearcherTest extends BaseFacetedSearcherTestCase { @ClassRule @Rule public static final AggregateTestRule aggregateTestRule = new AggregateTestRule( new LiferayIntegrationTestRule(), SynchronousDestinationTestRule.INSTANCE); @Test public void testSearchByKeywords() throws Exception { Group group = userSearchFixture.addGroup(); String tag = RandomTestUtil.randomString(); User user = userSearchFixture.addUser(group, tag); assertSearch(tag, toMap(user, tag)); } @Test public void testSearchByKeywordsIgnoresInactiveSites() throws Exception { Group group1 = userSearchFixture.addGroup(); String prefix = RandomTestUtil.randomString(); String tag1 = prefix + " " + RandomTestUtil.randomString(); User user1 = userSearchFixture.addUser(group1, tag1); Group group2 = userSearchFixture.addGroup(); String tag2 = prefix + " " + RandomTestUtil.randomString(); User user2 = userSearchFixture.addUser(group2, tag2); assertSearch( prefix, SearchMapUtil.join(toMap(user1, tag1), toMap(user2, tag2))); deactivate(group1); assertSearch(prefix, toMap(user2, tag2)); deactivate(group2); assertSearch(prefix, Collections.<String, String>emptyMap()); } protected void assertSearch(String keywords, Map<String, String> expected) throws Exception { SearchContext searchContext = getSearchContext(keywords); Hits hits = search(searchContext); assertTags(keywords, hits, expected); } protected void deactivate(Group group) { group.setActive(false); GroupLocalServiceUtil.updateGroup(group); } protected SearchContext getSearchContext(String keywords) throws Exception { SearchContext searchContext = SearchContextTestUtil.getSearchContext(); searchContext.setKeywords(keywords); return searchContext; } }