aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo/document/FieldTestCase.java
blob: d699de9a6ecbc149863ff6b9e13671ade41d7676 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;

import org.junit.Test;

import static org.junit.Assert.fail;

/**
 * @author Thomas Gundersen
 */
public class FieldTestCase {

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

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

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

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

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

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

}