aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
committerJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
commit5c24dc5c9642a8d9ed70aee4c950fd0678a1ebec (patch)
treebd9b74bf00c832456f0b83c1b2cd7010be387d68 /config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java
parentf17c4fe7de4c55f5c4ee61897eab8c2f588d8405 (diff)
Rename the 'searchdefinition' package to 'schema'
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java b/config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java
new file mode 100644
index 00000000000..de061defb87
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/schema/RankProfileRegistryTest.java
@@ -0,0 +1,58 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema;
+
+import com.yahoo.config.model.application.provider.FilesApplicationPackage;
+import com.yahoo.config.model.test.MockApplicationPackage;
+import com.yahoo.config.model.test.TestDriver;
+import com.yahoo.config.model.test.TestRoot;
+import com.yahoo.searchlib.rankingexpression.ExpressionFunction;
+import com.yahoo.searchlib.rankingexpression.RankingExpression;
+import com.yahoo.vespa.config.search.RankProfilesConfig;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * @author Ulf Lilleengen
+ */
+public class RankProfileRegistryTest {
+
+ private static final String TESTDIR = "src/test/cfg/search/data/v2/inherited_rankprofiles";
+
+ @Test
+ public void testRankProfileInheritance() {
+ TestRoot root = new TestDriver().buildModel(FilesApplicationPackage.fromFile(new File(TESTDIR)));
+ RankProfilesConfig left = root.getConfig(RankProfilesConfig.class, "inherit/search/cluster.inherit/left");
+ RankProfilesConfig right = root.getConfig(RankProfilesConfig.class, "inherit/search/cluster.inherit/right");
+ assertEquals(3, left.rankprofile().size());
+ assertEquals(2, right.rankprofile().size());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRankProfileDuplicateNameIsIllegal() {
+ Schema schema = new Schema("foo", MockApplicationPackage.createEmpty());
+ RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(schema);
+ RankProfile barRankProfile = new RankProfile("bar", schema, rankProfileRegistry);
+ rankProfileRegistry.add(barRankProfile);
+ rankProfileRegistry.add(barRankProfile);
+ }
+
+ @Test
+ public void testRankProfileDuplicateNameLegalForOverridableRankProfiles() {
+ Schema schema = new Schema("foo", MockApplicationPackage.createEmpty());
+ RankProfileRegistry rankProfileRegistry = RankProfileRegistry.createRankProfileRegistryWithBuiltinRankProfiles(schema);
+
+ for (String rankProfileName : RankProfileRegistry.overridableRankProfileNames) {
+ assertNull(rankProfileRegistry.get(schema, rankProfileName).getFunctions().get("foo"));
+ RankProfile rankProfileWithAddedFunction = new RankProfile(rankProfileName, schema, rankProfileRegistry);
+ rankProfileWithAddedFunction.addFunction(new ExpressionFunction("foo", RankingExpression.from("1+2")), true);
+ rankProfileRegistry.add(rankProfileWithAddedFunction);
+ assertNotNull(rankProfileRegistry.get(schema, rankProfileName).getFunctions().get("foo"));
+ }
+ }
+
+}