summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/document/test/SDFieldTestCase.java
blob: 1055842b5afcd7d39a1379d0bb4102743da437da (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
// Copyright 2017 Yahoo Holdings. 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.searchdefinition.SearchDefinitionTestCase;
import com.yahoo.searchdefinition.document.SDDocumentType;
import com.yahoo.searchdefinition.document.SDField;
import org.junit.Test;

import static org.junit.Assert.fail;

/**
   @author  <a href="thomasg@yahoo-inc.com>Thomas Gundersen</a>
*/
public class SDFieldTestCase extends SearchDefinitionTestCase {
    @Test
    public void testIdSettingConflict() {
        SDDocumentType doc=new SDDocumentType("testdoc");
        SDField one=(SDField) doc.addField("one", DataType.STRING, false, 60);

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

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

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

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

}