diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-08-18 11:15:50 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-08-18 11:15:50 +0200 |
commit | c30bbdb0fa50cedc56eec71feeadc969ba5a3edf (patch) | |
tree | 6935b4d042618900ee0f7fd291c14ed55ae06cf8 /container-search/src/test | |
parent | 529694a88d48270298171fdcb87d1439f183202b (diff) |
Skip logging only for IllegalInputException
- Add IllegalInputException to signal cases where we know the exception
is caused by illegal input received from the requestor.
- Only skip logging for IllegalInputException instead of the superclass
IllegalArgumentException as that is also used to signal illegal
arguments to methods due to bugs which are otherwise hard to debug.
- Throw IllegalInputException rather than IllegalArgumentException
where appropriate.
- Deprecated QueryException as it was only used to be able to separate
between query string and query parameter exceptions, and not doing
that consistently, and is in a package we don't want more use of.
- Clean up some cases where the wrong exception was thrown.
Diffstat (limited to 'container-search/src/test')
14 files changed, 56 insertions, 65 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java b/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java index a080ae653e5..204ccff7fb3 100644 --- a/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/query/ItemsCommonStuffTestCase.java @@ -42,7 +42,7 @@ public class ItemsCommonStuffTestCase { a.addItem(as); try { as.addItem(a); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { caught = true; } assertTrue(caught); @@ -51,7 +51,7 @@ public class ItemsCommonStuffTestCase { as.addItem(a); try { a.addItem(as); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { caught = true; } assertTrue(caught); @@ -235,21 +235,21 @@ public class ItemsCommonStuffTestCase { boolean caught = false; try { as.removeItem(firstItem); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { caught = true; } assertTrue(caught); caught = false; try { as.addItem(new WordItem("puppy")); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { caught= true; } assertTrue(caught); caught = false; try { as.addItem(1, new WordItem("kvalp")); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { caught = true; } assertTrue(caught); diff --git a/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java index 4b2ced1b771..a04834b261c 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/QueryTestCase.java @@ -8,25 +8,21 @@ import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.SearchDefinition; -import com.yahoo.prelude.query.QueryException; import com.yahoo.prelude.query.WordItem; import com.yahoo.search.Query; import com.yahoo.search.query.Sorting; import com.yahoo.search.searchchain.Execution; import com.yahoo.yolean.Exceptions; import org.hamcrest.Matcher; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import java.util.Collections; import java.util.List; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.anyOf; import static org.junit.Assert.*; -import static org.junit.Assume.assumeTrue; /** * Tests for query class @@ -376,7 +372,7 @@ public class QueryTestCase { try { newQuery(queryString); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. assertThat(Exceptions.toMessageString(e), expectedErrorMessage); } diff --git a/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java index 8ff03b35b60..86ab96a2197 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/UniqueGroupingSearcherTestCase.java @@ -2,7 +2,6 @@ package com.yahoo.search.grouping; import com.yahoo.component.chain.Chain; -import com.yahoo.prelude.query.QueryException; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; @@ -41,18 +40,19 @@ public class UniqueGroupingSearcherTestCase { new MockResultProvider(0, false)); assertEquals(0, result.hits().size()); } + @Test public void testIllegalSortingSpec() { try { search("?query=foo&unique=fingerprint&sorting=-1", new MockResultProvider(0, true).addGroupList(new GroupList("fingerprint"))); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. assertThat( Exceptions.toMessageString(e), containsString( - "Invalid request parameter: Could not set 'ranking.sorting' to '-1': " + + "Could not set 'ranking.sorting' to '-1': " + "Illegal attribute name '1' for sorting. Requires '[\\[]*[a-zA-Z_][\\.a-zA-Z0-9_-]*[\\]]*'")); } } diff --git a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java index 272092b6fc0..3cca053d0e5 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/handler/test/JSONSearchHandlerTestCase.java @@ -169,7 +169,7 @@ public class JSONSearchHandlerTestCase { String response = responseHandler.readAll(); assertThat(responseHandler.getStatus(), is(400)); assertThat(response, containsString("offset")); - assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.INVALID_QUERY_PARAMETER.code)); + assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.ILLEGAL_QUERY.code)); } @Test diff --git a/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java b/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java index c96af2ed4d1..7d03e065fa9 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/handler/test/SearchHandlerTestCase.java @@ -201,7 +201,7 @@ public class SearchHandlerTestCase { String response = responseHandler.readAll(); assertThat(responseHandler.getStatus(), is(400)); assertThat(response, containsString("offset")); - assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.INVALID_QUERY_PARAMETER.code)); + assertThat(response, containsString("\"code\":" + com.yahoo.container.protect.Error.ILLEGAL_QUERY.code)); } @Test diff --git a/container-search/src/test/java/com/yahoo/search/query/MatchingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/MatchingTestCase.java index 462e5284972..3b6b3c7d7c6 100644 --- a/container-search/src/test/java/com/yahoo/search/query/MatchingTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/MatchingTestCase.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query; -import com.yahoo.prelude.query.QueryException; import com.yahoo.search.Query; import org.junit.Test; @@ -12,9 +11,10 @@ import static org.junit.Assert.assertEquals; * @author baldersheim */ public class MatchingTestCase { + @Test public void testDefaultsInQuery() { - Query query=new Query("?query=test"); + Query query = new Query("?query=test"); assertNull(query.getRanking().getMatching().getTermwiseLimit()); assertNull(query.getRanking().getMatching().getNumThreadsPerSearch()); assertNull(query.getRanking().getMatching().getNumSearchPartitions()); @@ -24,7 +24,7 @@ public class MatchingTestCase { @Test public void testQueryOverride() { - Query query=new Query("?query=test&ranking.matching.termwiselimit=0.7&ranking.matching.numthreadspersearch=17&ranking.matching.numsearchpartitions=13&ranking.matching.minhitsperthread=3"); + Query query = new Query("?query=test&ranking.matching.termwiselimit=0.7&ranking.matching.numthreadspersearch=17&ranking.matching.numsearchpartitions=13&ranking.matching.minhitsperthread=3"); assertEquals(Double.valueOf(0.7), query.getRanking().getMatching().getTermwiseLimit()); assertEquals(Integer.valueOf(17), query.getRanking().getMatching().getNumThreadsPerSearch()); assertEquals(Integer.valueOf(13), query.getRanking().getMatching().getNumSearchPartitions()); @@ -40,16 +40,17 @@ public class MatchingTestCase { private void verifyException(String key, String value) { try { new Query("?query=test&ranking.matching."+key+"="+value); - assertFalse(true); - } catch (QueryException e) { - assertEquals("Invalid request parameter", e.getMessage()); - assertEquals("Could not set 'ranking.matching." + key + "' to '" + value +"'", e.getCause().getMessage()); - assertEquals(key + " must be in the range [0.0, 1.0]. It is " + value, e.getCause().getCause().getMessage()); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Could not set 'ranking.matching." + key + "' to '" + value +"'", e.getMessage()); + assertEquals(key + " must be in the range [0.0, 1.0]. It is " + value, e.getCause().getMessage()); } } + @Test public void testLimits() { verifyException("termwiselimit", "-0.1"); verifyException("termwiselimit", "1.1"); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java b/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java index dff6d4c26c3..a15038ff7e2 100644 --- a/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/SoftTimeoutTestCase.java @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query; -import com.yahoo.prelude.query.QueryException; import com.yahoo.search.Query; import org.junit.Test; import static org.junit.Assert.*; @@ -10,9 +9,10 @@ import static org.junit.Assert.*; * @author baldersheim */ public class SoftTimeoutTestCase { + @Test public void testDefaultsInQuery() { - Query query=new Query("?query=test"); + Query query = new Query("?query=test"); assertTrue(query.getRanking().getSoftTimeout().getEnable()); assertNull(query.getRanking().getSoftTimeout().getFactor()); assertNull(query.getRanking().getSoftTimeout().getTailcost()); @@ -20,7 +20,7 @@ public class SoftTimeoutTestCase { @Test public void testQueryOverride() { - Query query=new Query("?query=test&ranking.softtimeout.factor=0.7&ranking.softtimeout.tailcost=0.3"); + Query query = new Query("?query=test&ranking.softtimeout.factor=0.7&ranking.softtimeout.tailcost=0.3"); assertTrue(query.getRanking().getSoftTimeout().getEnable()); assertEquals(Double.valueOf(0.7), query.getRanking().getSoftTimeout().getFactor()); assertEquals(Double.valueOf(0.3), query.getRanking().getSoftTimeout().getTailcost()); @@ -49,13 +49,13 @@ public class SoftTimeoutTestCase { private void verifyException(String key, String value) { try { new Query("?query=test&ranking.softtimeout."+key+"="+value); - assertFalse(true); - } catch (QueryException e) { - assertEquals("Invalid request parameter", e.getMessage()); - assertEquals("Could not set 'ranking.softtimeout." + key + "' to '" + value +"'", e.getCause().getMessage()); - assertEquals(key + " must be in the range [0.0, 1.0], got " + value, e.getCause().getCause().getMessage()); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Could not set 'ranking.softtimeout." + key + "' to '" + value +"'", e.getMessage()); + assertEquals(key + " must be in the range [0.0, 1.0], got " + value, e.getCause().getMessage()); } } + @Test public void testLimits() { verifyException("factor", "-0.1"); @@ -63,4 +63,5 @@ public class SoftTimeoutTestCase { verifyException("tailcost", "-0.1"); verifyException("tailcost", "1.1"); } + } diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java index 224b0c82339..2ced2ba9323 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NativePropertiesTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.search.query.profile.types.test; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.prelude.query.QueryException; import com.yahoo.search.Query; import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.types.QueryProfileType; @@ -23,22 +22,22 @@ public class NativePropertiesTestCase { @Test public void testNativeInStrict() { - QueryProfileType strictType=new QueryProfileType("strict"); + QueryProfileType strictType = new QueryProfileType("strict"); strictType.setStrict(true); - QueryProfile strict=new QueryProfile("profile"); + QueryProfile strict = new QueryProfile("profile"); strict.setType(strictType); try { new Query(HttpRequest.createTestRequest("?hits=10&tracelevel=5", Method.GET), strict.compile(null)); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. } try { new Query(HttpRequest.createTestRequest("?notnative=5", Method.GET), strict.compile(null)); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. assertThat( Exceptions.toMessageString(e), diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java index ecebbead866..a0bf0972281 100644 --- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java @@ -2,9 +2,7 @@ package com.yahoo.search.query.profile.types.test; import com.yahoo.component.ComponentId; -import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.prelude.query.QueryException; import com.yahoo.tensor.Tensor; import com.yahoo.yolean.Exceptions; import com.yahoo.search.Query; @@ -434,7 +432,7 @@ public class QueryProfileTypeTestCase { com.yahoo.jdisc.http.HttpRequest.Method.GET), profile.compile(null)); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. assertThat(Exceptions.toMessageString(e), containsString("Could not set 'myUserQueryProfile.nondeclared' to 'someValue': 'nondeclared' is not declared in query profile type 'userStrict', and the type is strict")); @@ -549,7 +547,7 @@ public class QueryProfileTypeTestCase { com.yahoo.jdisc.http.HttpRequest.Method.GET), cRegistry.getComponent("topMap")); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. assertThat(Exceptions.toMessageString(e), containsString("Could not set 'subMap.typeProfile.someValue' to 'value': 'someValue' is not declared in query profile type 'testtypeStrict', and the type is strict")); diff --git a/container-search/src/test/java/com/yahoo/search/querytransform/test/SortingDegraderTestCase.java b/container-search/src/test/java/com/yahoo/search/querytransform/test/SortingDegraderTestCase.java index 5a14cff1818..ab65e258477 100644 --- a/container-search/src/test/java/com/yahoo/search/querytransform/test/SortingDegraderTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/querytransform/test/SortingDegraderTestCase.java @@ -6,7 +6,6 @@ import com.yahoo.prelude.Index; import com.yahoo.prelude.IndexFacts; import com.yahoo.prelude.IndexModel; import com.yahoo.prelude.SearchDefinition; -import com.yahoo.prelude.query.QueryException; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; @@ -16,8 +15,6 @@ import com.yahoo.search.querytransform.SortingDegrader; import com.yahoo.search.searchchain.Execution; import org.junit.Test; -import java.util.Collections; - import static org.junit.Assert.*; /** @@ -67,12 +64,10 @@ public class SortingDegraderTestCase { try { Query query = new Query("?ranking.sorting=-a1%20-a2&ranking.matchPhase.maxFilterCoverage=37"); assertTrue(false); - } catch (QueryException qe) { - assertEquals("Invalid request parameter", qe.getMessage()); - Throwable setE = qe.getCause(); - assertTrue(setE instanceof IllegalArgumentException); - assertEquals("Could not set 'ranking.matchPhase.maxFilterCoverage' to '37'", setE.getMessage()); - Throwable rootE = setE.getCause(); + } catch (IllegalArgumentException qe) { + assertTrue(qe instanceof IllegalArgumentException); + assertEquals("Could not set 'ranking.matchPhase.maxFilterCoverage' to '37'", qe.getMessage()); + Throwable rootE = qe.getCause(); assertTrue(rootE instanceof IllegalArgumentException); assertEquals("maxFilterCoverage must be in the range [0.0, 1.0]. It is 37.0", rootE.getMessage()); } diff --git a/container-search/src/test/java/com/yahoo/search/searchers/test/InputCheckingSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/searchers/test/InputCheckingSearcherTestCase.java index aa507d38be5..9bf5b654a6d 100644 --- a/container-search/src/test/java/com/yahoo/search/searchers/test/InputCheckingSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/searchers/test/InputCheckingSearcherTestCase.java @@ -85,7 +85,7 @@ public class InputCheckingSearcherTestCase { assertNull(r.hits().getErrorHit()); r = execution.search(new Query("/search/?query=%22a.b.0.0.0.0.0.0.c%22")); assertNotNull(r.hits().getErrorHit()); - assertEquals("More than 5 ocurrences of term '0' in a row detected in phrase : \"a b 0 0 0 0 0 0 c\"", + assertEquals("More than 5 occurrences of term '0' in a row detected in phrase : \"a b 0 0 0 0 0 0 c\"", r.hits().getErrorHit().errorIterator().next().getDetailedMessage()); r = execution.search(new Query("/search/?query=a.b.0.0.0.1.0.0.0.c")); assertNull(r.hits().getErrorHit()); @@ -97,7 +97,7 @@ public class InputCheckingSearcherTestCase { assertNull(r.hits().getErrorHit()); r = execution.search(new Query("/search/?query=%22a.b.0.0.0.0.0.0.c%22")); assertNotNull(r.hits().getErrorHit()); - assertEquals("More than 5 ocurrences of term '0' in a row detected in phrase : \"a b 0 0 0 0 0 0 c\"", + assertEquals("More than 5 occurrences of term '0' in a row detected in phrase : \"a b 0 0 0 0 0 0 c\"", r.hits().getErrorHit().errorIterator().next().getDetailedMessage()); r = execution.search(new Query("/search/?query=%22a.b.0.0.0.1.0.0.0.c%22")); assertNull(r.hits().getErrorHit()); diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index 3a67245e912..a42a2ee55aa 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -23,7 +23,6 @@ import com.yahoo.prelude.query.IndexedItem; import com.yahoo.prelude.query.IntItem; import com.yahoo.prelude.query.Item; import com.yahoo.prelude.query.OrItem; -import com.yahoo.prelude.query.QueryException; import com.yahoo.prelude.query.RankItem; import com.yahoo.prelude.query.WordItem; import com.yahoo.processing.request.CompoundName; @@ -47,7 +46,6 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -289,7 +287,7 @@ public class QueryTestCase { try { new Query(httpEncode("/search?timeout=nalle")); fail("Above statement should throw"); - } catch (QueryException e) { + } catch (IllegalArgumentException e) { // As expected. assertTrue(Exceptions.toMessageString(e).contains("Could not set 'timeout' to 'nalle': Error parsing 'nalle': Invalid number 'nalle'")); } @@ -865,7 +863,7 @@ public class QueryTestCase { root.addItem(child); fail("Expected exception"); } - catch (QueryException e) { + catch (IllegalArgumentException e) { assertEquals("Cannot add OR (AND ) to (AND ) as it would create a cycle", e.getMessage()); } @@ -875,7 +873,7 @@ public class QueryTestCase { child.addItem(root); fail("Expected exception"); } - catch (QueryException e) { + catch (IllegalArgumentException e) { assertEquals("Cannot add (AND (OR )) to (OR ) as it would create a cycle", e.getMessage()); } } diff --git a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java index 1b8324c9de8..f5e22e30f45 100644 --- a/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/yql/YqlParserTestCase.java @@ -449,8 +449,8 @@ public class YqlParserTestCase { "title contains ([{\"id\": 1, \"connectivity\": {\"id\": 4, \"weight\": 7.0}}]\"madonna\") " + "and title contains ([{\"id\": 2}]\"saint\") " + "and title contains ([{\"id\": 3}]\"angel\");", - new NullPointerException("Item 'title:madonna' was specified to connect to item with ID 4, " + - "which does not exist in the query.")); + new IllegalArgumentException("Item 'title:madonna' was specified to connect to item with ID 4, " + + "which does not exist in the query.")); } @Test diff --git a/container-search/src/test/java/com/yahoo/select/SelectTestCase.java b/container-search/src/test/java/com/yahoo/select/SelectTestCase.java index f297fd69f24..c802eb18c0f 100644 --- a/container-search/src/test/java/com/yahoo/select/SelectTestCase.java +++ b/container-search/src/test/java/com/yahoo/select/SelectTestCase.java @@ -14,6 +14,7 @@ import com.yahoo.prelude.query.SuffixItem; import com.yahoo.prelude.query.WeakAndItem; import com.yahoo.prelude.query.WordAlternativesItem; import com.yahoo.prelude.query.WordItem; +import com.yahoo.processing.IllegalInputException; import com.yahoo.search.Query; import com.yahoo.search.grouping.GroupingRequest; import com.yahoo.search.grouping.request.AllOperation; @@ -423,7 +424,7 @@ public class SelectTestCase { assertParseFail("{ \"and\": [ {\"contains\" : { \"children\" : [\"title\", \"madonna\"], \"attributes\" : {\"id\": 1, \"connectivity\": {\"id\": 4, \"weight\": 7.0}} } }, " + "{ \"contains\" : { \"children\" : [\"title\", \"saint\"], \"attributes\" : {\"id\": 2} } }, " + "{ \"contains\" : { \"children\" : [\"title\", \"angel\"], \"attributes\" : {\"id\": 3} } } ] }", - new NullPointerException("Item 'title:madonna' was specified to connect to item with ID 4, " + + new IllegalArgumentException("Item 'title:madonna' was specified to connect to item with ID 4, " + "which does not exist in the query.")); } @@ -618,7 +619,7 @@ public class SelectTestCase { parseWhere("{ \"range\" : { \"children\":[ \"foo\", { \">=\" : 0, \"<=\" : 1 }], \"attributes\" : {\"hitLimit\": 38, \"ascending\": true, \"descending\": false} } }"); } catch (IllegalArgumentException e) { assertTrue("Expected information about abuse of settings.", - e.getMessage().contains("both ascending and descending ordering set")); + e.getCause().getMessage().contains("both ascending and descending ordering set")); gotExceptionFromParse = true; } assertTrue(gotExceptionFromParse); @@ -775,12 +776,14 @@ public class SelectTestCase { private void assertParseFail(String where, Throwable expectedException) { try { parseWhere(where).toString(); - } catch (Throwable t) { - assertEquals(expectedException.getClass(), t.getClass()); - assertEquals(expectedException.getMessage(), t.getMessage()); - return; + fail("Parse succeeded: " + where); + } catch (Throwable outer) { + assertEquals(IllegalInputException.class, outer.getClass()); + assertEquals("Illegal JSON query", outer.getMessage()); + Throwable cause = outer.getCause(); + assertEquals(expectedException.getClass(), cause.getClass()); + assertEquals(expectedException.getMessage(), cause.getMessage()); } - fail("Parse succeeded: " + where); } private void assertRootClass(String where, Class<? extends Item> expectedRootClass) { |