summaryrefslogtreecommitdiffstats
path: root/configgen/src/test
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-09-07 12:25:37 +0200
committerHarald Musum <musum@yahooinc.com>2023-09-07 12:25:37 +0200
commitcac205f35b56d0bd584013b79b88a6635dee5ab4 (patch)
treebcf8461b3091c44ae78e5d9355a2109ba7d6a77a /configgen/src/test
parentdaba552c567f1fcb9e300ae65825c1d97cedbb5e (diff)
Support optional 'path' config type
Initial work needed for this to work (config definition and config library)
Diffstat (limited to 'configgen/src/test')
-rw-r--r--configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java21
-rw-r--r--configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java4
-rw-r--r--configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java2
-rw-r--r--configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java2
-rw-r--r--configgen/src/test/resources/allfeatures.reference28
-rw-r--r--configgen/src/test/resources/configgen.allfeatures.def1
6 files changed, 53 insertions, 5 deletions
diff --git a/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java b/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java
index 0e2f6cc4d05..bb6b8eb64b4 100644
--- a/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java
+++ b/configgen/src/test/java/com/yahoo/config/codegen/DefLineParsingTest.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.codegen;
+import java.util.Optional;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@@ -246,4 +247,24 @@ public class DefLineParsingTest {
assertTrue(r1.getRestart());
}
+ @Test
+ void testParseOptionalPathWithDefault() {
+ DefLine l = new DefLine("pathWithDef path optional");
+
+ assertEquals("pathWithDef", l.getName());
+ assertNull(l.getDefault());
+ assertTrue(l.isOptional());
+ assertEquals("optionalPath", l.getType().getName());
+ }
+
+ @Test
+ void testParsPathWithDefault() {
+ DefLine l = new DefLine("pathWithDef path");
+
+ assertEquals("pathWithDef", l.getName());
+ assertNull(l.getDefault());
+ assertFalse(l.isOptional());
+ assertEquals("path", l.getType().getName());
+ }
+
}
diff --git a/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java b/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java
index 45d1f21763c..e5227282c05 100644
--- a/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java
+++ b/configgen/src/test/java/com/yahoo/config/codegen/DefParserTest.java
@@ -28,7 +28,7 @@ public class DefParserTest {
CNode root = new DefParser("test", new FileReader(defFile)).getTree();
assertNotNull(root);
CNode[] children = root.getChildren();
- assertEquals(37, children.length);
+ assertEquals(38, children.length);
int numGrandChildren = 0;
int numGreatGrandChildren = 0;
@@ -70,7 +70,7 @@ public class DefParserTest {
void testMd5Sum() throws IOException {
File defFile = new File(DEF_NAME);
CNode root = new DefParser("test", new FileReader(defFile)).getTree();
- assertEquals("0501f9e2c4ecc8c283e100e0b1178ca4", root.defMd5);
+ assertEquals("ee37973499305fde315da46256e64b2e", root.defMd5);
}
@Test
diff --git a/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java b/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java
index 428576e340f..c3145c03fff 100644
--- a/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java
+++ b/configgen/src/test/java/com/yahoo/config/codegen/JavaClassBuilderTest.java
@@ -120,7 +120,7 @@ public class JavaClassBuilderTest {
}
for (int i = 0; i < referenceClassLines.size(); i++) {
if (configClassLines.length <= i)
- fail("Missing lines i generated config class. First missing line:\n" + referenceClassLines.get(i));
+ fail("Missing lines in generated config class. First missing line:\n" + referenceClassLines.get(i));
assertEquals(referenceClassLines.get(i), configClassLines[i], "Line " + i);
}
}
diff --git a/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java b/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java
index 57b3ed962eb..18608102ffa 100644
--- a/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java
+++ b/configgen/src/test/java/com/yahoo/config/codegen/NormalizedDefinitionTest.java
@@ -70,7 +70,7 @@ public class NormalizedDefinitionTest {
}
assertNotNull(out);
- assertEquals(75, out.size());
+ assertEquals(76, out.size());
assertNotNull(fileReader);
fileReader.close();
diff --git a/configgen/src/test/resources/allfeatures.reference b/configgen/src/test/resources/allfeatures.reference
index b7a79f663e7..79508b3a25f 100644
--- a/configgen/src/test/resources/allfeatures.reference
+++ b/configgen/src/test/resources/allfeatures.reference
@@ -35,7 +35,7 @@ import com.yahoo.config.*;
*/
public final class AllfeaturesConfig extends ConfigInstance {
- public final static String CONFIG_DEF_MD5 = "0501f9e2c4ecc8c283e100e0b1178ca4";
+ public final static String CONFIG_DEF_MD5 = "ee37973499305fde315da46256e64b2e";
public final static String CONFIG_DEF_NAME = "allfeatures";
public final static String CONFIG_DEF_NAMESPACE = "configgen";
public final static String[] CONFIG_DEF_SCHEMA = {
@@ -56,6 +56,7 @@ public final class AllfeaturesConfig extends ConfigInstance {
"refwithdef reference default=\":parent:\"",
"fileVal file",
"pathVal path",
+ "optionalPathVal path optional",
"urlVal url",
"modelVal model",
"boolarr[] bool",
@@ -130,6 +131,7 @@ public final class AllfeaturesConfig extends ConfigInstance {
private String refwithdef = null;
private String fileVal = null;
private FileReference pathVal = null;
+ private Optional<FileReference> optionalPathVal = Optional.empty();
private UrlReference urlVal = null;
private ModelReference modelVal = null;
public List<Boolean> boolarr = new ArrayList<>();
@@ -171,6 +173,7 @@ public final class AllfeaturesConfig extends ConfigInstance {
refwithdef(config.refwithdef());
fileVal(config.fileVal().value());
pathVal(config.pathVal.getFileReference());
+ optionalPathVal(config.optionalPathVal.getFileReference());
urlVal(config.urlVal.getUrlReference());
modelVal(config.modelVal.getModelReference());
boolarr(config.boolarr());
@@ -231,6 +234,8 @@ public final class AllfeaturesConfig extends ConfigInstance {
fileVal(__superior.fileVal);
if (__superior.pathVal != null)
pathVal(__superior.pathVal);
+ if (__superior.optionalPathVal != null)
+ optionalPathVal(__superior.optionalPathVal);
if (__superior.urlVal != null)
urlVal(__superior.urlVal);
if (__superior.modelVal != null)
@@ -412,6 +417,17 @@ public final class AllfeaturesConfig extends ConfigInstance {
}
+ public Builder optionalPathVal(Optional<FileReference> __value) {
+ if (__value == null) throw new IllegalArgumentException("Null value is not allowed.");
+ optionalPathVal = __value;
+ __uninitialized.remove("optionalPathVal");
+ return this;
+ }
+
+ private Builder optionalPathVal(FileReference __value) {
+ return optionalPathVal(Optional.of(__value));
+ }
+
public Builder urlVal(UrlReference __value) {
if (__value == null) throw new IllegalArgumentException("Null value is not allowed.");
urlVal = __value;
@@ -759,6 +775,7 @@ public final class AllfeaturesConfig extends ConfigInstance {
private final ReferenceNode refwithdef;
private final FileNode fileVal;
private final PathNode pathVal;
+ private final OptionalPathNode optionalPathVal;
private final UrlNode urlVal;
private final ModelNode modelVal;
private final LeafNodeVector<Boolean, BooleanNode> boolarr;
@@ -822,6 +839,8 @@ public final class AllfeaturesConfig extends ConfigInstance {
new FileNode() : new FileNode(builder.fileVal);
pathVal = (builder.pathVal == null) ?
new PathNode() : new PathNode(builder.pathVal);
+ optionalPathVal = (builder.optionalPathVal == null) ?
+ new OptionalPathNode() : new OptionalPathNode(builder.optionalPathVal);
urlVal = (builder.urlVal == null) ?
new UrlNode() : new UrlNode(builder.urlVal);
modelVal = (builder.modelVal == null) ?
@@ -960,6 +979,13 @@ public final class AllfeaturesConfig extends ConfigInstance {
}
/**
+ * @return allfeatures.optionalPathVal
+ */
+ public Optional<Path> optionalPathVal() {
+ return optionalPathVal.value();
+ }
+
+ /**
* @return allfeatures.urlVal
*/
public File urlVal() {
diff --git a/configgen/src/test/resources/configgen.allfeatures.def b/configgen/src/test/resources/configgen.allfeatures.def
index 1f93e29b73b..eee39dc18f3 100644
--- a/configgen/src/test/resources/configgen.allfeatures.def
+++ b/configgen/src/test/resources/configgen.allfeatures.def
@@ -39,6 +39,7 @@ refVal reference
refwithdef reference default=":parent:"
fileVal file
pathVal path
+optionalPathVal path optional
urlVal url
modelVal model