/**
* 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.search.Field;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.search.facet.Facet;
import com.liferay.portal.kernel.search.facet.MultiValueFacetFactory;
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.SearchContextTestUtil;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
import com.liferay.registry.Registry;
import com.liferay.registry.RegistryUtil;
import java.util.Collections;
import java.util.Map;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Andrew Betts
* @author André de Oliveira
*/
@RunWith(Arquillian.class)
@Sync
public class AssetTagNamesFacetedSearcherTest
extends BaseFacetedSearcherTestCase {
@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new AggregateTestRule(
new LiferayIntegrationTestRule(),
SynchronousDestinationTestRule.INSTANCE);
@Before
@Override
public void setUp() throws Exception {
super.setUp();
Registry registry = RegistryUtil.getRegistry();
_multiValueFacetFactory = registry.getService(
MultiValueFacetFactory.class);
}
@Test
public void testSearchByFacet() throws Exception {
Group group = userSearchFixture.addGroup();
String tag = "enterprise. open-source for life";
userSearchFixture.addUser(group, tag);
SearchContext searchContext = getSearchContext(tag);
Facet facet = _multiValueFacetFactory.newInstance(searchContext);
facet.setFieldName(Field.ASSET_TAG_NAMES);
searchContext.addFacet(facet);
search(searchContext);
Map<String, Integer> frequencies = Collections.singletonMap(tag, 1);
assertFrequencies(facet.getFieldName(), searchContext, frequencies);
}
protected SearchContext getSearchContext(String keywords) throws Exception {
SearchContext searchContext = SearchContextTestUtil.getSearchContext();
searchContext.setKeywords(keywords);
return searchContext;
}
private MultiValueFacetFactory _multiValueFacetFactory;
}