aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/BoldingTestCase.java
blob: ede3b531f6add21d16938b0434e83f1a4bdea323 (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.AbstractSchemaTestCase;
import com.yahoo.schema.parser.ParseException;
import org.junit.jupiter.api.Test;

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

/**
 * @author bratseth
 */
public class BoldingTestCase extends AbstractSchemaTestCase {

    private final String boldonnonstring =
            "search boldnonstring {\n" +
            "    document boldnonstring {\n" +
            "        field title type string {\n" +
            "            indexing: summary | index\n" +
            "        }\n" +
            "\n" +
            "        field year4 type int {\n" +
            "            indexing: summary | attribute\n" +
            "            bolding: on\n" +
            "        }\n" +
            "    }\n" +
            "}\n";

    @Test
    void testBoldOnNonString() throws ParseException {
        try {
            ApplicationBuilder.createFromString(boldonnonstring);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            assertEquals("'bolding: on' for non-text field 'year4' (datatype int (code: 0)) is not allowed",
                    e.getMessage());
        }
    }

    private final String boldonwset =
            "search test {\n" +
            "    document test {\n" +
            "        field mywset type weightedset<string> {\n" +
            "            indexing: summary | index\n" +
            "            bolding: on\n" +
            "        }\n" +
            "    }\n" +
            "}\n";

    @Test
    void testBoldOnWsetThrowsException() throws ParseException {
        try {
            ApplicationBuilder.createFromString(boldonwset);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            assertEquals("'bolding: on' for non-text field 'mywset' (datatype WeightedSet<string> (code: 1328286588)) is not allowed",
                    e.getMessage());
        }
    }

}