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"));
}
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);
}
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);
}
}
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);
}
}
Aggregations