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

import static org.junit.jupiter.api.Assertions.assertThrows;

/**
 * @author lesters
 */
public class DisallowComplexMapAndWsetKeyTypesTestCase {

    @Test
    void requireThatComplexTypesForMapKeysFail() throws ParseException {
        assertThrows(IllegalArgumentException.class, () -> {
            testFieldType("map<mystruct,string>");
        });
    }

    @Test
    void requireThatComplexTypesForWsetFail() throws ParseException {
        assertThrows(IllegalArgumentException.class, () -> {
            testFieldType("weightedset<mystruct>");
        });
    }

    @Test
    void requireThatNestedComplexTypesForMapFail() throws ParseException {
        assertThrows(IllegalArgumentException.class, () -> {
            testFieldType("array<map<mystruct,string>>");
        });
    }

    @Test
    void requireThatNestedComplexValuesForMapSucceed() throws ParseException {
        testFieldType("array<map<string,mystruct>>");
    }

    @Test
    void requireThatNestedComplexTypesForWsetFail() throws ParseException {
        assertThrows(IllegalArgumentException.class, () -> {
            testFieldType("array<weightedset<mystruct>>");
        });
    }

    @Test
    void requireThatDeepNestedComplexTypesForMapFail() throws ParseException {
        assertThrows(IllegalArgumentException.class, () -> {
            testFieldType("map<string,map<mystruct,string>>");
        });
    }

    private void testFieldType(String fieldType) throws ParseException {
        RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
        ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry);
        builder.addSchema(
                "search test {\n" +
                        "    document test { \n" +
                        "        struct mystruct {}\n" +
                        "        field a type " + fieldType + " {}\n" +
                        "    }\n" +
                        "}\n");
        builder.build(true);
    }

}