aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/IndexingOutputsTestCase.java
blob: 58956b89a076cf0b067b0f3353f2f11b225ce315 (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
// Copyright Vespa.ai. 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 com.yahoo.yolean.Exceptions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * @author Simon Thoresen Hult
 */
public class IndexingOutputsTestCase {

    @Test
    void requireThatOutputOtherFieldThrows() throws ParseException {
        try {
            var schema = """
                    search indexing_output_other_field {
                        document indexing_output_other_field {
                            field foo type string {
                                indexing: index bar
                            }
                        }
                        field bar type string {
                        }
                    }
                    """;
            ApplicationBuilder.createFromString(schema);
            fail("Expected exception");
        }
        catch (IllegalArgumentException e) {
            assertEquals("For schema 'indexing_output_other_field', field 'foo': Indexing expression 'index bar' " +
                         "attempts to write to a field other than 'foo'.",
                         Exceptions.toMessageString(e));
        }
    }

    @Test
    void requireThatOutputConflictThrows() throws ParseException {
        try {
            var schema = """
                    search indexing_output_confict {
                        document indexing_output_confict {
                            field foo type string {
                            }
                        }
                        field bar type string {
                            indexing: input foo | attribute | lowercase | index
                        }
                    }
                    """;
            ApplicationBuilder.createFromString(schema);
            fail("Expected exception");
        }
        catch (IllegalArgumentException e) {
            assertEquals("For schema 'indexing_output_confict', field 'bar': For expression 'index bar': Attempting " +
                         "to assign conflicting values to field 'bar'.",
                         Exceptions.toMessageString(e));
        }
    }

}