Search in sources :

Example 1 with QueryException

use of com.yahoo.prelude.query.QueryException in project vespa by vespa-engine.

the class NativePropertiesTestCase method testNativeInStrict.

public void testNativeInStrict() {
    QueryProfileType strictType = new QueryProfileType("strict");
    strictType.setStrict(true);
    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) {
    // As expected.
    }
    try {
        new Query(HttpRequest.createTestRequest("?notnative=5", Method.GET), strict.compile(null));
        fail("Above statement should throw");
    } catch (QueryException e) {
        // As expected.
        assertThat(Exceptions.toMessageString(e), containsString("Could not set 'notnative' to '5':" + " 'notnative' is not declared in query profile type 'strict', and the type is strict"));
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryException(com.yahoo.prelude.query.QueryException) Query(com.yahoo.search.Query) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType)

Example 2 with QueryException

use of com.yahoo.prelude.query.QueryException in project vespa by vespa-engine.

the class SortingDegraderTestCase method testDegradingNonDefaultIllegalMaxFilterCoverage.

@Test
public void testDegradingNonDefaultIllegalMaxFilterCoverage() {
    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();
        assertTrue(rootE instanceof IllegalArgumentException);
        assertEquals("maxFilterCoverage must be in the range [0.0, 1.0]. It is 37.0", rootE.getMessage());
    }
}
Also used : QueryException(com.yahoo.prelude.query.QueryException) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 3 with QueryException

use of com.yahoo.prelude.query.QueryException in project vespa by vespa-engine.

the class QueryProfileTypeTestCase method testSettingValueInStrictTypeNestedUnderUntypedMaps.

/**
 * Tests setting a illegal value in a strict profile nested under untyped maps
 */
public void testSettingValueInStrictTypeNestedUnderUntypedMaps() {
    QueryProfile topMap = new QueryProfile("topMap");
    QueryProfile subMap = new QueryProfile("topSubMap");
    topMap.set("subMap", subMap, registry);
    QueryProfile test = new QueryProfile("test");
    test.setType(typeStrict);
    subMap.set("typeProfile", test, registry);
    registry.register(topMap);
    registry.register(subMap);
    registry.register(test);
    CompiledQueryProfileRegistry cRegistry = registry.compile();
    try {
        new Query(HttpRequest.createTestRequest("?subMap.typeProfile.someValue=value", com.yahoo.jdisc.http.HttpRequest.Method.GET), cRegistry.getComponent("topMap"));
        fail("Above statement should throw");
    } catch (QueryException 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"));
    }
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryException(com.yahoo.prelude.query.QueryException) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query)

Example 4 with QueryException

use of com.yahoo.prelude.query.QueryException in project vespa by vespa-engine.

the class QueryProfileTypeTestCase method testIllegalStrictAssignmentFromRequest.

public void testIllegalStrictAssignmentFromRequest() {
    QueryProfile profile = new QueryProfile("test");
    profile.setType(typeStrict);
    QueryProfile newUser = new QueryProfile("newUser");
    newUser.setType(userStrict);
    profile.set("myUserQueryProfile", newUser, registry);
    try {
        new Query(HttpRequest.createTestRequest("?myUserQueryProfile.nondeclared=someValue", com.yahoo.jdisc.http.HttpRequest.Method.GET), profile.compile(null));
        fail("Above statement should throw");
    } catch (QueryException 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"));
    }
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) QueryException(com.yahoo.prelude.query.QueryException) Query(com.yahoo.search.Query)

Aggregations

QueryException (com.yahoo.prelude.query.QueryException)4 Query (com.yahoo.search.Query)4 QueryProfile (com.yahoo.search.query.profile.QueryProfile)3 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)2 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)1 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)1 Test (org.junit.Test)1