metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickal...@apache.org
Subject [metron] branch master updated: METRON-1996 Solr search throws NPE for group search if the group parameter is null or empty (MohanDV via nickwallen) closes apache/metron#1333
Date Tue, 26 Feb 2019 16:21:13 GMT
This is an automated email from the ASF dual-hosted git repository.

nickallen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metron.git


The following commit(s) were added to refs/heads/master by this push:
     new cc30c0e  METRON-1996 Solr search throws NPE for group search if the group parameter
is null or empty (MohanDV via nickwallen) closes apache/metron#1333
cc30c0e is described below

commit cc30c0e21656fa95b488adb47a3c9fcec94af67a
Author: MohanDV <mohan.dv@gmail.com>
AuthorDate: Tue Feb 26 11:20:14 2019 -0500

    METRON-1996 Solr search throws NPE for group search if the group parameter is null or
empty (MohanDV via nickwallen) closes apache/metron#1333
---
 .../org/apache/metron/solr/dao/SolrSearchDao.java  |  3 ++
 .../apache/metron/solr/dao/SolrSearchDaoTest.java  | 36 ++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrSearchDao.java
b/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrSearchDao.java
index 4a8d482..134d28c 100644
--- a/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrSearchDao.java
+++ b/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrSearchDao.java
@@ -105,6 +105,9 @@ public class SolrSearchDao implements SearchDao {
   @Override
   public GroupResponse group(GroupRequest groupRequest) throws InvalidSearchException {
     try {
+      if (groupRequest.getGroups() == null || groupRequest.getGroups().size() == 0) {
+        throw new InvalidSearchException("At least 1 group must be provided.");
+      }
       String groupNames = groupRequest.getGroups().stream().map(Group::getField).collect(
           Collectors.joining(","));
       SolrQuery query = new SolrQuery()
diff --git a/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrSearchDaoTest.java
b/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrSearchDaoTest.java
index fe27a55..bf9458f 100644
--- a/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrSearchDaoTest.java
+++ b/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrSearchDaoTest.java
@@ -136,6 +136,42 @@ public class SolrSearchDaoTest {
   }
 
   @Test
+  public void searchShouldThrowInvalidSearchExceptionOnNullGroup() throws Exception {
+    exception.expect(InvalidSearchException.class);
+    exception.expectMessage("At least 1 group must be provided.");
+
+    GroupRequest groupRequest = mock(GroupRequest.class);
+    GroupResponse groupResponse = mock(GroupResponse.class);
+
+    solrSearchDao = spy(new SolrSearchDao(client, accessConfig));
+    when(groupRequest.getQuery()).thenReturn("query");
+    when(groupRequest.getGroups()).thenReturn(null);
+    when(groupRequest.getScoreField()).thenReturn(Optional.of("scoreField"));
+    when(groupRequest.getIndices()).thenReturn(Arrays.asList("bro", "snort"));
+
+    assertEquals(groupResponse, solrSearchDao.group(groupRequest));
+    verifyNoMoreInteractions(client);
+  }
+
+  @Test
+  public void searchShouldThrowInvalidSearchExceptionOnEmptyGroup() throws Exception {
+    exception.expect(InvalidSearchException.class);
+    exception.expectMessage("At least 1 group must be provided.");
+
+    GroupRequest groupRequest = mock(GroupRequest.class);
+    GroupResponse groupResponse = mock(GroupResponse.class);
+
+    solrSearchDao = spy(new SolrSearchDao(client, accessConfig));
+    when(groupRequest.getQuery()).thenReturn("query");
+    when(groupRequest.getGroups()).thenReturn(Collections.EMPTY_LIST);
+    when(groupRequest.getScoreField()).thenReturn(Optional.of("scoreField"));
+    when(groupRequest.getIndices()).thenReturn(Arrays.asList("bro", "snort"));
+
+    assertEquals(groupResponse, solrSearchDao.group(groupRequest));
+    verifyNoMoreInteractions(client);
+  }
+
+  @Test
   public void searchShouldThrowSearchResultSizeException() throws Exception {
     exception.expect(InvalidSearchException.class);
     exception.expectMessage("Search result size must be less than 100");


Mime
View raw message