diff options
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java | 117 |
1 files changed, 71 insertions, 46 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java index 8f757a0dd49..4f473b29918 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/GroupingValidatorTestCase.java @@ -7,117 +7,142 @@ import com.yahoo.search.Query; import com.yahoo.search.config.ClusterConfig; import com.yahoo.search.grouping.request.GroupingOperation; import com.yahoo.search.searchchain.Execution; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import java.util.Arrays; import java.util.Collection; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author Simon Thoresen Hult */ public class GroupingValidatorTestCase { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void requireThatAvailableAttributesDoNotThrow() { - validateGrouping(Arrays.asList("foo", "bar"), + validateGrouping(List.of("foo", "bar"), "all(group(foo) each(output(max(bar))))");; } @Test public void requireThatUnavailableAttributesThrow() { - thrown.expect(UnavailableAttributeException.class); - thrown.expectMessage(createMessage("bar")); - validateGrouping(Arrays.asList("foo"), - "all(group(foo) each(output(max(bar))))"); + try { + validateGrouping(List.of("foo"), "all(group(foo) each(output(max(bar))))"); + fail("Excpected exception"); + } + catch (UnavailableAttributeException e) { + assertEquals(createMessage("bar"), e.getMessage()); + } } @Test public void requireThatEnableFlagPreventsThrow() { Query query = createQuery("all(group(foo) each(output(max(bar))))"); query.properties().set(GroupingValidator.PARAM_ENABLED, "false"); - validateGrouping(Arrays.asList("foo"), query); + validateGrouping(List.of("foo"), query); } @Test public void available_primitive_map_attribute_does_not_throw() { - validateGrouping(Arrays.asList("map.key", "map.value"), + validateGrouping(List.of("map.key", "map.value"), "all(group(map{\"foo\"}) each(output(count())))"); } @Test public void unavailable_primitive_map_key_attribute_throws() { - thrown.expect(UnavailableAttributeException.class); - thrown.expectMessage(createMessage("map.key")); - validateGrouping(Arrays.asList("null"), - "all(group(map{\"foo\"}) each(output(count())))"); + try { + validateGrouping(List.of("null"), "all(group(map{\"foo\"}) each(output(count())))"); + fail("Expected exception"); + } + catch (UnavailableAttributeException e) { + assertEquals(createMessage("map.key"), e.getMessage()); + } } @Test public void unavailable_primitive_map_value_attribute_throws() { - thrown.expect(UnavailableAttributeException.class); - thrown.expectMessage(createMessage("map.value")); - validateGrouping(Arrays.asList("map.key"), - "all(group(map{\"foo\"}) each(output(count())))"); + try { + validateGrouping(List.of("map.key"), "all(group(map{\"foo\"}) each(output(count())))"); + fail("Expected exception"); + } + catch (UnavailableAttributeException e) { + assertEquals(createMessage("map.value"), e.getMessage()); + } } @Test public void available_struct_map_attribute_does_not_throw() { - validateGrouping(Arrays.asList("map.key", "map.value.name"), + validateGrouping(List.of("map.key", "map.value.name"), "all(group(map{\"foo\"}.name) each(output(count())))"); } @Test public void unavailable_struct_map_key_attribute_throws() { - thrown.expect(UnavailableAttributeException.class); - thrown.expectMessage(createMessage("map.key")); - validateGrouping(Arrays.asList("null"), - "all(group(map{\"foo\"}.name) each(output(count())))"); + try { + validateGrouping(List.of("null"), "all(group(map{\"foo\"}.name) each(output(count())))"); + fail("Expected exception"); + } + catch (UnavailableAttributeException e) { + assertEquals(createMessage("map.key"), e.getMessage()); + } } @Test public void unavailable_struct_map_value_attribute_throws() { - thrown.expect(UnavailableAttributeException.class); - thrown.expectMessage(createMessage("map.value.name")); - validateGrouping(Arrays.asList("map.key"), - "all(group(map{\"foo\"}.name) each(output(count())))"); + try { + validateGrouping(List.of("map.key"), "all(group(map{\"foo\"}.name) each(output(count())))"); + fail("Expected exception"); + } + catch (UnavailableAttributeException e) { + assertEquals(createMessage("map.value.name"), e.getMessage()); + } } @Test public void available_key_source_attribute_does_not_throw() { - validateGrouping(Arrays.asList("map.key", "map.value", "key_source"), + validateGrouping(List.of("map.key", "map.value", "key_source"), "all(group(map{attribute(key_source)}) each(output(count())))"); } @Test public void unavailable_key_source_attribute_throws() { - thrown.expect(UnavailableAttributeException.class); - thrown.expectMessage(createMessage("key_source")); - validateGrouping(Arrays.asList("map.key", "map.value"), - "all(group(map{attribute(key_source)}) each(output(count())))"); + try { + validateGrouping(List.of("map.key", "map.value"), + "all(group(map{attribute(key_source)}) each(output(count())))"); + fail("Expected exception"); + } + catch (UnavailableAttributeException e) { + assertEquals(createMessage("key_source"), e.getMessage()); + } } @Test public void key_source_attribute_with_mismatching_data_type_throws() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Grouping request references key source attribute 'key_source' with data type 'INT32' " + - "that is different than data type 'STRING' of key attribute 'map.key'"); - - validateGrouping(setupMismatchingKeySourceAttribute(false), - "all(group(map{attribute(key_source)}) each(output(count())))"); + try { + validateGrouping(setupMismatchingKeySourceAttribute(false), + "all(group(map{attribute(key_source)}) each(output(count())))"); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("Grouping request references key source attribute 'key_source' with data type 'INT32' " + + "that is different than data type 'STRING' of key attribute 'map.key'", + e.getMessage()); + } } @Test public void key_source_attribute_with_multi_value_collection_type_throws() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Grouping request references key source attribute 'key_source' which is not of single value type"); - - validateGrouping(setupMismatchingKeySourceAttribute(true), - "all(group(map{attribute(key_source)}) each(output(count())))"); + try { + validateGrouping(setupMismatchingKeySourceAttribute(true), + "all(group(map{attribute(key_source)}) each(output(count())))"); + fail("Expected exception"); + } + catch (IllegalArgumentException e) { + assertEquals("Grouping request references key source attribute 'key_source' which is not of single value type", + e.getMessage()); + } } private static AttributesConfig setupMismatchingKeySourceAttribute(boolean matchingDataType) { |