Search in sources :

Example 51 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class MandatoryTestCase method testMandatoryNestedInMaps.

/**
 * Same as above except the whole thing is nested in maps
 */
@Test
public void testMandatoryNestedInMaps() {
    Fixture1 fixture = new Fixture1();
    QueryProfile topMap = new QueryProfile("topMap");
    fixture.registry.register(topMap);
    QueryProfile subMap = new QueryProfile("topSubMap");
    topMap.set("subMap", subMap, fixture.registry);
    fixture.registry.register(subMap);
    QueryProfile test = new QueryProfile("test");
    test.setType(fixture.type);
    subMap.set("test", test, fixture.registry);
    fixture.registry.register(test);
    QueryProfile myUser = new QueryProfile("user");
    myUser.setType(fixture.user);
    myUser.set("myUserInteger", 1, fixture.registry);
    test.set("myUserQueryProfile", myUser, fixture.registry);
    fixture.registry.register(myUser);
    CompiledQueryProfileRegistry cRegistry = fixture.registry.compile();
    // Underspecified request 1
    assertError("Incomplete query: Parameter 'subMap.test.myString' is mandatory in query profile 'topMap' but is not set", new Query(HttpRequest.createTestRequest("", Method.GET), cRegistry.getComponent("topMap")));
    // Underspecified request 2
    assertError("Incomplete query: Parameter 'subMap.test.myUserQueryProfile.myUserString' is mandatory in query profile 'topMap' but is not set", new Query(HttpRequest.createTestRequest("?subMap.test.myString=aString", Method.GET), cRegistry.getComponent("topMap")));
    // Fully specified request
    assertError(null, new Query(HttpRequest.createTestRequest("?subMap.test.myString=aString&subMap.test.myUserQueryProfile.myUserString=userString", Method.GET), cRegistry.getComponent("topMap")));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) Test(org.junit.Test)

Example 52 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileSubstitutionTestCase method testUnclosedSubstitution1.

public void testUnclosedSubstitution1() {
    try {
        QueryProfile p = new QueryProfile("test");
        p.set("message1", "%{greeting} %{entity}%{exclamation", (QueryProfileRegistry) null);
        fail("Should have produced an exception");
    } catch (IllegalArgumentException e) {
        assertEquals("Could not set 'message1' to '%{greeting} %{entity}%{exclamation': Unterminated value substitution '%{exclamation'", Exceptions.toMessageString(e));
    }
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile)

Example 53 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileSubstitutionTestCase method testUnclosedSubstitution2.

public void testUnclosedSubstitution2() {
    try {
        QueryProfile p = new QueryProfile("test");
        p.set("message1", "%{greeting} %{entity%{exclamation}", (QueryProfileRegistry) null);
        fail("Should have produced an exception");
    } catch (IllegalArgumentException e) {
        assertEquals("Could not set 'message1' to '%{greeting} %{entity%{exclamation}': Unterminated value substitution '%{entity%{exclamation}'", Exceptions.toMessageString(e));
    }
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile)

Example 54 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile in project vespa by vespa-engine.

the class QueryProfileVariantsCloneTestCase method test_that_interior_and_leaf_values_on_a_path_are_preserved_when_cloning.

/**
 * Test for Ticket 4882480.
 */
@Test
public void test_that_interior_and_leaf_values_on_a_path_are_preserved_when_cloning() {
    Map<String, String> dimensionBinding = createDimensionBinding("location", "norway");
    QueryProfile profile = new QueryProfile("profile");
    profile.setDimensions(keys(dimensionBinding));
    DimensionValues dimensionValues = DimensionValues.createFrom(values(dimensionBinding));
    profile.set("interior.leaf", "leafValue", dimensionValues, null);
    profile.set("interior", "interiorValue", dimensionValues, null);
    CompiledQueryProfile clone = profile.compile(null).clone();
    assertEquals(profile.get("interior", dimensionBinding, null), clone.get("interior", dimensionBinding));
    assertEquals(profile.get("interior.leaf", dimensionBinding, null), clone.get("interior.leaf", dimensionBinding));
}
Also used : CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) QueryProfile(com.yahoo.search.query.profile.QueryProfile) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) DimensionValues(com.yahoo.search.query.profile.DimensionValues) Test(org.junit.Test)

Example 55 with QueryProfile

use of com.yahoo.search.query.profile.QueryProfile 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)

Aggregations

QueryProfile (com.yahoo.search.query.profile.QueryProfile)161 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)92 Query (com.yahoo.search.Query)63 BackedOverridableQueryProfile (com.yahoo.search.query.profile.BackedOverridableQueryProfile)35 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)28 Test (org.junit.Test)26 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)24 QueryProfileProperties (com.yahoo.search.query.profile.QueryProfileProperties)21 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)12 Properties (com.yahoo.search.query.Properties)8 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 SubstituteString (com.yahoo.search.query.profile.SubstituteString)4 QueryProfilesConfig (com.yahoo.search.query.profile.config.QueryProfilesConfig)4 Element (org.w3c.dom.Element)4 QueryException (com.yahoo.prelude.query.QueryException)3 Properties (com.yahoo.processing.request.Properties)3 QueryProfileXMLReader (com.yahoo.search.query.profile.config.QueryProfileXMLReader)3 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)3 ComponentSpecification (com.yahoo.component.ComponentSpecification)2