aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/document/test/SDFieldTestCase.java
blob: 6a9565d4d16209027f74d4ff10b6420c3b154332 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.test;

import com.yahoo.document.DataType;
import com.yahoo.schema.AbstractSchemaTestCase;
import com.yahoo.schema.document.SDDocumentType;
import org.junit.jupiter.api.Test;

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

/**
 * @author Thomas Gundersen
 */
public class SDFieldTestCase extends AbstractSchemaTestCase {

    @Test
    void testIdSettingConflict() {
        SDDocumentType doc = new SDDocumentType("testdoc");
        doc.addField("one", DataType.STRING, 60);

        doc.addField("two", DataType.STRING, 61);

        try {
            doc.addField("three", DataType.STRING, 60);
            fail("Allowed to set duplicate id");
        }
        catch (IllegalArgumentException e) {
            // Success
        }
    }

    @Test
    void testSettingReservedId() {
        SDDocumentType doc = new SDDocumentType("testdoc");
        try {
            doc.addField("one", DataType.STRING, 127);
            fail("Allowed to set reserved id");
        }
        catch (IllegalArgumentException e) {
            // Success
        }

        try {
            doc.addField("one", DataType.STRING, 100);
            fail("Allowed to set reserved id");
        }
        catch (IllegalArgumentException e) {
            // Success
        }

        try {
            doc.addField("one", DataType.STRING, -1);
            fail("Allowed to set reserved id");
        }
        catch (IllegalArgumentException e) {
            // Success
        }
        doc.addField("one", DataType.STRING);
    }

}