aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java
diff options
context:
space:
mode:
authorbjormel <bjormel@yahooinc.com>2023-10-01 12:23:12 +0000
committerbjormel <bjormel@yahooinc.com>2023-10-01 12:23:12 +0000
commite9058b555d4dfea2f6c872d9a677e8678b569569 (patch)
treefa1b67c6e39712c1e0d9f308b0dd55573b43f913 /config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java
parent0ad931fa86658904fe9212b014d810236b0e00e4 (diff)
parent16030193ec04ee41e98779a3d7ee6a6c1d0d0d6f (diff)
Merge branch 'master' into bjormel/aws-main-controller
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java176
1 files changed, 147 insertions, 29 deletions
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));
+ }
}
+
}