aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@vespa.ai>2023-09-27 18:28:03 +0200
committerJon Bratseth <bratseth@vespa.ai>2023-09-27 18:28:03 +0200
commita29d3f706ca32fca53428d03931579bce8cb43be (patch)
tree2b57d2ff1a04cf6930adc99b457ad6269daa029d /config-model/src/test/java/com/yahoo/schema/processing
parentfbe72324295a4b9190ec20a64bfe2fe0989554f8 (diff)
Simplify tests
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/processing')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java25
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java176
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java1
3 files changed, 147 insertions, 55 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java b/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java
deleted file mode 100644
index 010cf849419..00000000000
--- a/config-model/src/test/java/com/yahoo/schema/processing/AssertSearchBuilder.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.schema.processing;
-
-import com.yahoo.schema.ApplicationBuilder;
-import com.yahoo.schema.parser.ParseException;
-
-import java.io.IOException;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-/**
- * @author Simon Thoresen Hult
- */
-public abstract class AssertSearchBuilder {
-
- public static void assertBuildFails(String searchDefinitionFileName, String expectedException)
- throws IOException, ParseException {
- try {
- ApplicationBuilder.buildFromFile(searchDefinitionFileName);
- fail(searchDefinitionFileName);
- } catch (IllegalArgumentException e) {
- assertEquals(expectedException, e.getMessage());
- }
- }
-}
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java
index aa8a2922e8f..4343abbf548 100644
--- a/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java
@@ -4,13 +4,15 @@ package com.yahoo.schema.processing;
import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.derived.AbstractExportingTestCase;
import com.yahoo.schema.parser.ParseException;
+import com.yahoo.yolean.Exceptions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Arrays;
import static com.yahoo.schema.processing.AssertIndexingScript.assertIndexing;
-import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Simon Thoresen Hult
@@ -18,45 +20,135 @@ import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails;
public class IndexingValidationTestCase extends AbstractExportingTestCase {
@Test
- void testAttributeChanged() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_attribute_changed.sd",
- "For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " +
- "Attempting to assign conflicting values to field 'foo'.");
+ void testAttributeChanged() throws ParseException {
+ try {
+ var schema = """
+ search indexing_attribute_changed {
+ document indexing_attribute_changed {
+ field foo type string {
+ indexing: summary | lowercase | attribute
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_attribute_changed', field 'foo': For expression 'attribute foo': " +
+ "Attempting to assign conflicting values to field 'foo'.",
+ Exceptions.toMessageString(e));
+ }
}
@Test
- void testAttributeOther() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_attribute_other.sd",
- "For schema 'indexing_attribute_other', field 'foo': Indexing expression 'attribute bar' " +
- "attempts to write to a field other than 'foo'.");
+ void testAttributeOther() throws ParseException {
+ try {
+ var schema = """
+ search indexing_attribute_other {
+ document indexing_attribute_other {
+ field foo type string {
+ indexing: attribute bar
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_attribute_other', field 'foo': Indexing expression 'attribute bar' " +
+ "attempts to write to a field other than 'foo'.",
+ Exceptions.toMessageString(e));
+ }
}
@Test
- void testIndexChanged() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_index_changed.sd",
- "For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " +
- "Attempting to assign conflicting values to field 'foo'.");
+ void testIndexChanged() throws ParseException {
+ try {
+ var schema = """
+ search indexing_index_changed {
+ document indexing_index_changed {
+ field foo type string {
+ indexing: attribute | lowercase | index
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_index_changed', field 'foo': For expression 'index foo': " +
+ "Attempting to assign conflicting values to field 'foo'.",
+ Exceptions.toMessageString(e));
+ }
}
@Test
- void testIndexOther() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_index_other.sd",
- "For schema 'indexing_index_other', field 'foo': Indexing expression 'index bar' " +
- "attempts to write to a field other than 'foo'.");
+ void testIndexOther() throws ParseException {
+ try {
+ var schema = """
+ search indexing_index_other {
+ document indexing_index_other {
+ field foo type string {
+ indexing: index bar\s
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_index_other', field 'foo': Indexing expression 'index bar' " +
+ "attempts to write to a field other than 'foo'.",
+ Exceptions.toMessageString(e));
+ }
}
@Test
- void testSummaryChanged() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_summary_changed.sd",
- "For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " +
- "to assign conflicting values to field 'foo'.");
+ void testSummaryChanged() throws ParseException {
+ try {
+ var schema = """
+ search indexing_summary_fail {
+ document indexing_summary_fail {
+ field foo type string {
+ indexing: index | lowercase | summary\s
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_summary_fail', field 'foo': For expression 'summary foo': Attempting " +
+ "to assign conflicting values to field 'foo'.",
+ Exceptions.toMessageString(e));
+ }
}
@Test
- void testSummaryOther() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_summary_other.sd",
- "For schema 'indexing_summary_other', field 'foo': Indexing expression 'summary bar' " +
- "attempts to write to a field other than 'foo'.");
+ void testSummaryOther() throws ParseException {
+ try {
+ var schema = """
+ search indexing_summary_other {
+ document indexing_summary_other {
+ field foo type string {
+ indexing: summary bar
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_summary_other', field 'foo': Indexing expression 'summary bar' " +
+ "attempts to write to a field other than 'foo'.",
+ Exceptions.toMessageString(e));
+ }
}
@Test
@@ -68,9 +160,35 @@ public class IndexingValidationTestCase extends AbstractExportingTestCase {
}
@Test
- void requireThatMultilineOutputConflictThrows() throws IOException, ParseException {
- assertBuildFails("src/test/examples/indexing_multiline_output_conflict.sd",
- "For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " +
- "Attempting to assign conflicting values to field 'cox'.");
+ void requireThatMultilineOutputConflictThrows() throws ParseException {
+ try {
+ var schema = """
+ search indexing_multiline_output_confict {
+ document indexing_multiline_output_confict {
+ field foo type string {
+ }
+ field bar type string {
+ }
+ field baz type string {
+ }
+ }
+ field cox type string {
+ indexing {
+ input foo | attribute;
+ input bar | index;
+ input baz | summary;
+ }
+ }
+ }
+ """;
+ ApplicationBuilder.createFromString(schema);
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("For schema 'indexing_multiline_output_confict', field 'cox': For expression 'index cox': " +
+ "Attempting to assign conflicting values to field 'cox'.",
+ Exceptions.toMessageString(e));
+ }
}
+
}
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java
index dc04fc9772f..85ec80d2610 100644
--- a/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java
+++ b/config-model/src/test/java/com/yahoo/schema/processing/MatchPhaseSettingsValidatorTestCase.java
@@ -5,7 +5,6 @@ import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.yolean.Exceptions;
import org.junit.jupiter.api.Test;
-import static com.yahoo.schema.processing.AssertSearchBuilder.assertBuildFails;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;