aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/TokensTransformValidatorTest.java
blob: 6da536efe86dfce9c48142fdc47aa6badb1f456f (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
// 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.Schema;
import com.yahoo.schema.parser.ParseException;
import com.yahoo.vespa.documentmodel.SummaryTransform;
import org.junit.jupiter.api.Test;

import static com.yahoo.config.model.test.TestUtil.joinLines;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class TokensTransformValidatorTest {
    private void buildSchema(String fieldType) throws ParseException {
        String sd = joinLines(
                "search test {",
                "  document test {",
                "      field f type " + fieldType + " {",
                "          indexing: index | summary",
                "          summary: tokens",
                "      }",
                "  }",
                "}"
        );
        Schema schema = ApplicationBuilder.createFromString(sd).getSchema();
    }

    void buildSchemaShouldFail(String fieldType, String expFail) throws ParseException {
        try {
            buildSchema(fieldType);
            fail("expected IllegalArgumentException with message '" + expFail + "'");
        } catch (IllegalArgumentException e) {
            assertEquals(expFail, e.getMessage());
        }
    }

    @Test
    void testTokensTransformWithPlainString() throws ParseException {
        buildSchema("string");
    }

    @Test
    void testTokensTransformWithArrayOfString() throws ParseException {
        buildSchema("array<string>");
    }

    @Test
    void testTokensTransformWithWeightedSetOfString() throws ParseException {
        buildSchema("weightedset<string>");
    }

    @Test
    void testTokensTransformWithWeightedSetOfInteger() throws ParseException {
        buildSchemaShouldFail("weightedset<int>", "For schema 'test', document-summary 'default'" +
                ", summary field 'f', source field 'f', source field type 'WeightedSet<int>'" +
                ": transform 'tokens' is only allowed for fields of type string, array<string> or weightedset<string>");
    }
}