aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/NameFieldCheckTestCase.java
blob: b3e20d543720e7f426e02feac689eef24f6bffe4 (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
77
78
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema;

import org.junit.jupiter.api.Test;

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

/**
 * Tests that "name" is not allowed as name for a field.
 * 
 * And that duplicate names are not allowed. 
 *
 * @author Lars Christian Jensen
 */
public class NameFieldCheckTestCase extends AbstractSchemaTestCase {

    @Test
    void testNameField() {
        try {
            ApplicationBuilder.createFromString(
                    "search simple {\n" +
                            "  document name-check {\n" +
                            "    field title type string {\n" +
                            "      indexing: summary | index\n" +
                            "    }\n" +
                            "    # reserved name, should trigger error\n" +
                            "    field sddocname type string {\n" +
                            "      indexing: index\n" +
                            "    }\n" +
                            "  }\n" +
                            "}");
            fail("Should throw exception.");
        } catch (Exception expected) {
            // Success
        }
    }

    @Test
    void testDuplicateNamesInSearchDifferentType() {
        try {
            ApplicationBuilder.createFromString(
                    "search duplicatenamesinsearch {\n" +
                            "  document {\n" +
                            "    field grpphotoids64 type string { }\n" +
                            "  }\n" +
                            "  field grpphotoids64 type array<long> {\n" +
                            "    indexing: input grpphotoids64 | split \" \" | for_each {\n" +
                            "      base64decode } | attribute\n" +
                            "  }\n" +
                            "}");
            fail("Should throw exception.");
        } catch (Exception e) {
            assertEquals("For schema 'duplicatenamesinsearch', field 'grpphotoids64': " +
                    "Incompatible types. Expected Array<long> for index field 'grpphotoids64', got string.", e.getMessage());
        }
    }

    @Test
    void testDuplicateNamesInDoc() {
        try {
            ApplicationBuilder.createFromString(
                    "search duplicatenamesindoc {\n" +
                            "  document {\n" +
                            "    field foo type int {\n" +
                            "      indexing: attribute\n" +
                            "    }\n" +
                            "    field fOo type string {\n" +
                            "      indexing: index\n" +
                            "    }\n" +
                            "  }\n" +
                            "}");
            fail("Should throw exception.");
        } catch (Exception e) {
            assertTrue(e.getMessage().matches(".*Duplicate.*"));
        }
    }

}