Search in sources :

Example 6 with ServiceParams

use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.

the class ApiTemplateUnitTest method testServiceInput.

@Test
public void testServiceInput() throws Exception {
    JsonNode json = parseJson(JSON_CONFIG);
    ApiTemplate template = ApiTemplate.fromJSON(json);
    Map<String, String> fixed = template.getFixedParams();
    // Fixed params
    assertThat(fixed, hasKey("action"));
    assertThat(fixed, hasKey("prop"));
    assertThat(fixed, not(hasKey("cllimit")));
    assertThat(fixed, not(hasKey("titles")));
    // Input params with default
    assertThat(template.getInputDefault("cllimit"), equalTo("500"));
    assertThat(template.getInputDefault("cldir"), equalTo(""));
    assertNull(template.getInputDefault("titles"));
    // Bound params
    ServiceParams serviceParams = new ServiceParams();
    serviceParams.add(paramNameToURI("titles"), createConstant("sometitle"));
    serviceParams.add(paramNameToURI("name"), new VarNode("somevar"));
    serviceParams.add(paramNameToURI("ducks"), createConstant("extraParam"));
    Map<String, IVariableOrConstant> input = template.getInputVars(serviceParams);
    assertThat(input, hasKey("titles"));
    assertThat(input, hasKey("name"));
    assertThat(input, hasKey("cllimit"));
    assertThat(input, hasKey("ducks"));
    assertThat(input, hasKey("cldir"));
    // Bound constant
    assertTrue(input.get("titles").isConstant());
    assertTrue(input.get("ducks").isConstant());
    // Bound var
    assertTrue(input.get("name").isVar());
    assertThat(input.get("name").getName(), equalTo("somevar"));
    // Unbound vars have nulls
    assertNull(input.get("cllimit"));
    assertNull(input.get("cldir"));
}
Also used : VarNode(com.bigdata.rdf.sparql.ast.VarNode) IVariableOrConstant(com.bigdata.bop.IVariableOrConstant) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 7 with ServiceParams

use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.

the class ApiTemplateUnitTest method testMissingInputVar.

@Test(expected = IllegalArgumentException.class)
public void testMissingInputVar() throws Exception {
    JsonNode json = parseJson(JSON_CONFIG);
    ApiTemplate template = ApiTemplate.fromJSON(json);
    ServiceParams serviceParams = new ServiceParams();
    serviceParams.add(paramNameToURI("titles"), createConstant("sometitle"));
    template.getInputVars(serviceParams);
}
Also used : ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 8 with ServiceParams

use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactoryUnitTest method testGetLimitsFromParams_nonstandardProperties.

@Test
public void testGetLimitsFromParams_nonstandardProperties() throws IOException {
    try (Closeable maxResultsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_RESULTS, "100");
        Closeable maxContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_CONTINUATIONS, "75");
        Closeable maxEmptyContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_EMPTY_CONTINUATIONS, "10")) {
        MWApiServiceFactory factory = new MWApiServiceFactory(new ServiceConfig(), new Timer());
        ServiceParams serviceParams = new ServiceParams();
        MWApiLimits limits = factory.getLimitsFromParams(serviceParams);
        assertEquals(100, limits.limitResults);
        assertEquals(75, limits.limitContinuations);
        assertEquals(10, limits.limitEmptyContinuations);
    }
}
Also used : Timer(com.codahale.metrics.Timer) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 9 with ServiceParams

use of com.bigdata.rdf.sparql.ast.eval.ServiceParams in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactoryUnitTest method testGetLimitsFromParams_customParams.

@Test
public void testGetLimitsFromParams_customParams() throws IOException {
    try (Closeable maxResultsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_RESULTS, null);
        Closeable maxContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_CONTINUATIONS, null);
        Closeable maxEmptyContinuationsContext = SystemPropertyContext.setProperty(MWApiServiceFactory.CONFIG_MAX_EMPTY_CONTINUATIONS, null)) {
        MWApiServiceFactory factory = new MWApiServiceFactory(new ServiceConfig(), new Timer());
        ServiceParams serviceParams = new ServiceParams();
        serviceParams.set(MWApiServiceFactory.LIMIT_RESULTS_KEY, createConstant("100"));
        serviceParams.set(MWApiServiceFactory.LIMIT_CONTINUATIONS_KEY, createConstant("75"));
        serviceParams.set(MWApiServiceFactory.LIMIT_EMPTY_CONTINUATIONS_KEY, createConstant("10"));
        MWApiLimits limits = factory.getLimitsFromParams(serviceParams);
        assertEquals(100, limits.limitResults);
        assertEquals(75, limits.limitContinuations);
        assertEquals(10, limits.limitEmptyContinuations);
    }
}
Also used : Timer(com.codahale.metrics.Timer) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) Closeable(java.io.Closeable) Test(org.junit.Test)

Aggregations

ServiceParams (com.bigdata.rdf.sparql.ast.eval.ServiceParams)9 Test (org.junit.Test)7 Timer (com.codahale.metrics.Timer)6 Closeable (java.io.Closeable)5 IVariableOrConstant (com.bigdata.bop.IVariableOrConstant)2 IGroupMemberNode (com.bigdata.rdf.sparql.ast.IGroupMemberNode)2 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 TermNode (com.bigdata.rdf.sparql.ast.TermNode)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 URI (org.openrdf.model.URI)2 IVariable (com.bigdata.bop.IVariable)1 GraphPatternGroup (com.bigdata.rdf.sparql.ast.GraphPatternGroup)1 VarNode (com.bigdata.rdf.sparql.ast.VarNode)1 AbstractServiceFactory (com.bigdata.rdf.sparql.ast.eval.AbstractServiceFactory)1 BigdataNativeServiceOptions (com.bigdata.rdf.sparql.ast.service.BigdataNativeServiceOptions)1 BigdataServiceCall (com.bigdata.rdf.sparql.ast.service.BigdataServiceCall)1 IServiceOptions (com.bigdata.rdf.sparql.ast.service.IServiceOptions)1 ServiceCallCreateParams (com.bigdata.rdf.sparql.ast.service.ServiceCallCreateParams)1 ServiceNode (com.bigdata.rdf.sparql.ast.service.ServiceNode)1 ServiceRegistry (com.bigdata.rdf.sparql.ast.service.ServiceRegistry)1