|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2024 Eclipse RDF4J contributors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Distribution License v1.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: BSD-3-Clause |
| 10 | + *******************************************************************************/ |
| 11 | +package org.eclipse.rdf4j.federated.repository; |
| 12 | + |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; |
| 14 | + |
| 15 | +import java.io.InputStream; |
| 16 | + |
| 17 | +import org.eclipse.rdf4j.federated.FedXConfig; |
| 18 | +import org.eclipse.rdf4j.model.Model; |
| 19 | +import org.eclipse.rdf4j.model.Resource; |
| 20 | +import org.eclipse.rdf4j.model.impl.TreeModel; |
| 21 | +import org.eclipse.rdf4j.model.util.Models; |
| 22 | +import org.eclipse.rdf4j.model.util.Values; |
| 23 | +import org.eclipse.rdf4j.rio.RDFFormat; |
| 24 | +import org.eclipse.rdf4j.rio.Rio; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +public class FedXConfigParserTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testParse() throws Exception { |
| 31 | + Model model = readConfig("/tests/rdf4jserver/config-fedXConfig-only.ttl"); |
| 32 | + |
| 33 | + FedXConfig config = FedXConfigParser.parse(new FedXConfig(), model, Values.iri("http://example.org/conf")); |
| 34 | + |
| 35 | + assertThat(config.getEnforceMaxQueryTime()).isEqualTo(1234); |
| 36 | + assertThat(config.isEnableMonitoring()).isTrue(); |
| 37 | + assertThat(config.isLogQueryPlan()).isTrue(); |
| 38 | + assertThat(config.isDebugQueryPlan()).isTrue(); |
| 39 | + assertThat(config.isLogQueries()).isTrue(); |
| 40 | + assertThat(config.getSourceSelectionCacheSpec()).isEqualTo("spec-goes-here"); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testParseWithEmptyConfig() throws Exception { |
| 45 | + Model model = new TreeModel(); |
| 46 | + |
| 47 | + FedXConfig config = FedXConfigParser.parse(new FedXConfig(), model, Values.iri("http://example.org/conf")); |
| 48 | + |
| 49 | + // expecting defaults |
| 50 | + assertThat(config.getEnforceMaxQueryTime()).isEqualTo(30); |
| 51 | + assertThat(config.isEnableMonitoring()).isFalse(); |
| 52 | + assertThat(config.isLogQueryPlan()).isFalse(); |
| 53 | + assertThat(config.isDebugQueryPlan()).isFalse(); |
| 54 | + assertThat(config.isLogQueries()).isFalse(); |
| 55 | + assertThat(config.getSourceSelectionCacheSpec()).isNull(); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testExport() throws Exception { |
| 60 | + Model model = readConfig("/tests/rdf4jserver/config-fedXConfig-only.ttl"); |
| 61 | + |
| 62 | + FedXConfig config = FedXConfigParser.parse(new FedXConfig(), model, Values.iri("http://example.org/conf")); |
| 63 | + |
| 64 | + Model export = new TreeModel(); |
| 65 | + Resource configNode = FedXConfigParser.export(config, export); |
| 66 | + |
| 67 | + assertThat(export.filter(configNode, null, null)).hasSize(6); |
| 68 | + |
| 69 | + assertThat( |
| 70 | + Models.objectLiteral( |
| 71 | + export.getStatements(configNode, FedXConfigParser.CONFIG_ENFORCE_MAX_QUERY_TIME, null))) |
| 72 | + .hasValueSatisfying(v -> assertThat(v.intValue()).isEqualTo(1234)); |
| 73 | + assertThat( |
| 74 | + Models.objectLiteral( |
| 75 | + export.getStatements(configNode, FedXConfigParser.CONFIG_ENABLE_MONITORING, null))) |
| 76 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isTrue()); |
| 77 | + assertThat( |
| 78 | + Models.objectLiteral( |
| 79 | + export.getStatements(configNode, FedXConfigParser.CONFIG_LOG_QUERY_PLAN, null))) |
| 80 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isTrue()); |
| 81 | + assertThat( |
| 82 | + Models.objectLiteral( |
| 83 | + export.getStatements(configNode, FedXConfigParser.CONFIG_DEBUG_QUERY_PLAN, null))) |
| 84 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isTrue()); |
| 85 | + assertThat( |
| 86 | + Models.objectLiteral( |
| 87 | + export.getStatements(configNode, FedXConfigParser.CONFIG_LOG_QUERIES, null))) |
| 88 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isTrue()); |
| 89 | + assertThat( |
| 90 | + Models.objectLiteral( |
| 91 | + export.getStatements(configNode, FedXConfigParser.CONFIG_SOURCE_SELECTION_CACHE_SPEC, null))) |
| 92 | + .hasValueSatisfying(v -> assertThat(v.stringValue()).isEqualTo("spec-goes-here")); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testExportWithEmptyConfig() throws Exception { |
| 97 | + Model export = new TreeModel(); |
| 98 | + Resource configNode = FedXConfigParser.export(new FedXConfig(), export); |
| 99 | + |
| 100 | + // Note: 5 instead of 6 since CONFIG_SOURCE_SELECTION_CACHE_SPEC is null and thus should not be populated |
| 101 | + assertThat(export.filter(configNode, null, null)).hasSize(5); |
| 102 | + |
| 103 | + assertThat( |
| 104 | + Models.objectLiteral( |
| 105 | + export.getStatements(configNode, FedXConfigParser.CONFIG_ENFORCE_MAX_QUERY_TIME, null))) |
| 106 | + .hasValueSatisfying(v -> assertThat(v.intValue()).isEqualTo(30)); |
| 107 | + assertThat( |
| 108 | + Models.objectLiteral( |
| 109 | + export.getStatements(configNode, FedXConfigParser.CONFIG_ENABLE_MONITORING, null))) |
| 110 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isFalse()); |
| 111 | + assertThat( |
| 112 | + Models.objectLiteral( |
| 113 | + export.getStatements(configNode, FedXConfigParser.CONFIG_LOG_QUERY_PLAN, null))) |
| 114 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isFalse()); |
| 115 | + assertThat( |
| 116 | + Models.objectLiteral( |
| 117 | + export.getStatements(configNode, FedXConfigParser.CONFIG_DEBUG_QUERY_PLAN, null))) |
| 118 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isFalse()); |
| 119 | + assertThat( |
| 120 | + Models.objectLiteral( |
| 121 | + export.getStatements(configNode, FedXConfigParser.CONFIG_LOG_QUERIES, null))) |
| 122 | + .hasValueSatisfying(v -> assertThat(v.booleanValue()).isFalse()); |
| 123 | + } |
| 124 | + |
| 125 | + protected Model readConfig(String configResource) throws Exception { |
| 126 | + try (InputStream in = FedXRepositoryConfigTest.class.getResourceAsStream(configResource)) { |
| 127 | + return Rio.parse(in, "http://example.org/", RDFFormat.TURTLE); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments