aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/IndexingValidationTestCase.java
blob: aa8a2922e8f639c47f8e81afd8b525c49bb8d6ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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.derived.AbstractExportingTestCase;
import com.yahoo.schema.parser.ParseException;
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;

/**
 * @author Simon Thoresen Hult
 */
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'.");
    }

    @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'.");
    }

    @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'.");
    }

    @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'.");
    }

    @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'.");
    }

    @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'.");
    }

    @Test
    void testExtraField() throws IOException, ParseException {
        assertIndexing(
                Arrays.asList("clear_state | guard { input my_index | tokenize normalize stem:\"BEST\" | index my_index | summary my_index }",
                        "clear_state | guard { input my_input | tokenize normalize stem:\"BEST\" | index my_extra | summary my_extra }"),
                ApplicationBuilder.buildFromFile("src/test/examples/indexing_extra.sd"));
    }

    @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'.");
    }
}