summaryrefslogtreecommitdiffstats
path: root/config-model/src
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-08-24 11:04:11 +0200
committerJon Bratseth <bratseth@gmail.com>2022-08-24 11:04:11 +0200
commit750442815177bf4f1ed6ff375ab5c0160a065090 (patch)
tree034a144f4f19365a8f8cd390dd59465f49a9aa53 /config-model/src
parent26d0b997cc573bac2a1d7eda7a2494449452e121 (diff)
Add tests and more error checking
Diffstat (limited to 'config-model/src')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java12
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java19
2 files changed, 24 insertions, 7 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java
index 82ce8070c29..068ed2ee11f 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/EmbedderConfigTransformer.java
@@ -51,6 +51,10 @@ public class EmbedderConfigTransformer {
addConfigValue(child, config, deployState.isHosted());
component.appendChild(config);
}
+ else if ( ! XML.getChildren(embedder).isEmpty()) {
+ throw new IllegalArgumentException("Embedder '" + embedder.getAttribute("id") + "' does not specify " +
+ "a 'def' parameter so it cannot contain config values");
+ }
return component;
}
@@ -104,13 +108,9 @@ public class EmbedderConfigTransformer {
}
private static String embedderClassFrom(Element spec) {
- if (spec.hasAttribute("class")) {
+ if (spec.hasAttribute("class"))
return spec.getAttribute("class");
- }
- if (spec.hasAttribute("id")) {
- return spec.getAttribute("id");
- }
- throw new IllegalArgumentException("An <embedder> element must have a 'class' or 'id' attribute");
+ return spec.getAttribute("id");
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java
index d64e726eb6a..27d7470acac 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/EmbedderTestCase.java
@@ -32,7 +32,7 @@ public class EmbedderTestCase {
private static final String PREDEFINED_EMBEDDER_CONFIG = "embedding.bert-base-embedder";
@Test
- void testGenericEmbedConfig() throws IOException, SAXException {
+ void testApplicationEmbedder() throws IOException, SAXException {
String embedder = "<embedder id='test' class='ai.vespa.test' bundle='bundle' def='def.name'>" +
" <val>123</val>" +
"</embedder>";
@@ -45,6 +45,23 @@ public class EmbedderTestCase {
}
@Test
+ void testApplicationEmbedderWithoutConfig() throws IOException, SAXException {
+ String embedder = "<embedder id='test' class='ai.vespa.test' bundle='bundle'>" +
+ "</embedder>";
+ String component = "<component id='test' class='ai.vespa.test' bundle='bundle'>" +
+ "</component>";
+ assertTransform(embedder, component);
+ }
+
+ @Test
+ void testApplicationEmbedderWithoutConfigAttemptsToSetConfig() throws IOException, SAXException {
+ String embedder = "<embedder id='test' class='ai.vespa.test' bundle='bundle'>" +
+ " <val>123</val>" +
+ "</embedder>";
+ assertTransformThrows(embedder, "Embedder 'test' does not specify a 'def' parameter so it cannot contain config values", false);
+ }
+
+ @Test
void testPredefinedEmbedConfigSelfHosted() throws IOException, SAXException {
String embedder = "<embedder id='test' class='" + PREDEFINED_EMBEDDER_CLASS + "'>" +
" <transformerModel id='my_model_id' url='my-model-url' />" +