From 0b9fed2df9b3b2d9f3fcf55446102411d8c66fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Mon, 22 Dec 2014 11:42:32 +0100 Subject: [PATCH] LPS-52321 Add tests to verify that Bobo browser does not admit null sort fields I sent Bobo mantainer a pull request to fix it: https://github.com/senseidb/bobo/pull/21 --- .../lucene/LuceneIndexSearcherTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 portal-impl/test/integration/com/liferay/portal/search/lucene/LuceneIndexSearcherTest.java diff --git a/portal-impl/test/integration/com/liferay/portal/search/lucene/LuceneIndexSearcherTest.java b/portal-impl/test/integration/com/liferay/portal/search/lucene/LuceneIndexSearcherTest.java new file mode 100644 index 00000000000000..d5828ad530097f --- /dev/null +++ b/portal-impl/test/integration/com/liferay/portal/search/lucene/LuceneIndexSearcherTest.java @@ -0,0 +1,86 @@ +/** + * 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.lucene; + +import com.liferay.portal.kernel.search.Hits; +import com.liferay.portal.kernel.search.Query; +import com.liferay.portal.kernel.search.SearchContext; +import com.liferay.portal.kernel.search.Sort; +import com.liferay.portal.kernel.test.AggregateTestRule; +import com.liferay.portal.test.LiferayIntegrationTestRule; +import com.liferay.portal.test.MainServletTestRule; + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; + +/** + * @author Manuel de la Peña + */ +public class LuceneIndexSearcherTest { + + @ClassRule + @Rule + public static final AggregateTestRule aggregateTestRule = + new AggregateTestRule( + new LiferayIntegrationTestRule(), MainServletTestRule.INSTANCE); + + @Test + public void testSearchWithEmptySort() throws Exception { + LuceneIndexSearcher luceneIndexSearcher = new LuceneIndexSearcher(); + + SearchContext searchContext = new SearchContext(); + + searchContext.setSorts(new Sort[] {}); + + Query query = new BooleanQueryImpl(); + + Hits hits = luceneIndexSearcher.search(searchContext, query); + + Assert.assertEquals(0, hits.getLength()); + } + + @Test + public void testSearchWithNullSort() throws Exception { + LuceneIndexSearcher luceneIndexSearcher = new LuceneIndexSearcher(); + + SearchContext searchContext = new SearchContext(); + + searchContext.setSorts(null); + + Query query = new BooleanQueryImpl(); + + Hits hits = luceneIndexSearcher.search(searchContext, query); + + Assert.assertEquals(0, hits.getLength()); + } + + @Test + public void testSearchWithNullSorts() throws Exception { + LuceneIndexSearcher luceneIndexSearcher = new LuceneIndexSearcher(); + + SearchContext searchContext = new SearchContext(); + + searchContext.setSorts(new Sort[]{ null }); + + Query query = new BooleanQueryImpl(); + + Hits hits = luceneIndexSearcher.search(searchContext, query); + + Assert.assertEquals(0, hits.getLength()); + } + +} \ No newline at end of file