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


import com.yahoo.searchdefinition.SchemaBuilder;

import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;


import org.junit.rules.TemporaryFolder;

/**
 * Tests struct inheritance
 *
 * @author arnej
 */
public class StructInheritanceTestCase extends AbstractExportingTestCase {

    @Rule
    public TemporaryFolder tmpDir = new TemporaryFolder();

    @SuppressWarnings("deprecation")
    @Rule
    public final ExpectedException exceptionRule = ExpectedException.none();

    @Test
    public void requireThatStructCanInherit() throws IOException, ParseException {
        String dir = "src/test/derived/structinheritance/";
        SchemaBuilder builder = new SchemaBuilder();
        builder.importFile(dir + "simple.sd");
        builder.build(false);
        derive("structinheritance", builder, builder.getSchema("simple"));
        assertCorrectConfigFiles("structinheritance");
    }

    @Test
    public void requireThatRedeclareIsNotAllowed() throws IOException, ParseException {
        exceptionRule.expect(IllegalArgumentException.class);
        exceptionRule.expectMessage("cannot inherit from base and redeclare field name");
        String dir = "src/test/derived/structinheritance/";
        SchemaBuilder builder = new SchemaBuilder();
        builder.importFile(dir + "bad.sd");
        builder.build();
        derive("structinheritance", builder, builder.getSchema("bad"));
    }

}