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

import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
 * Tests that "name" is not allowed as name for a field.
 * 
 * And that duplicate names are not allowed. 
 *
 * @author <a href="mailto:larschr@yahoo-inc.com">Lars Christian Jensen</a>
 */
public class NameFieldCheckTestCase extends SearchDefinitionTestCase {

    @Test
    public void testNameField() throws IOException, ParseException {
        try {
            SearchBuilder.buildFromFile("src/test/examples/name-check.sd");
            fail("Should throw exception.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testDuplicateNamesInSearchDifferentType() {
        try {
            SearchBuilder.buildFromFile("src/test/examples/duplicatenamesinsearchdifferenttype.sd");
            fail("Should throw exception.");
        } catch (Exception e) {
            e.printStackTrace();
            assertTrue(e.getMessage().matches(".*Duplicate.*different type.*"));
        }
    }

    @Test
    public void testDuplicateNamesInDoc() {
        try {
            SearchBuilder.buildFromFile("src/test/examples/duplicatenamesindoc.sd");
            fail("Should throw exception.");
        } catch (Exception e) {
            e.printStackTrace();
            assertTrue(e.getMessage().matches(".*Duplicate.*"));
        }
    }

}