aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/derived/StructInheritanceTestCase.java
blob: 092e64420e8d5790f93d28536777e494a0412f64 (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.schema.derived;


import com.yahoo.schema.ApplicationBuilder;

import com.yahoo.schema.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/";
        ApplicationBuilder builder = new ApplicationBuilder();
        builder.addSchemaFile(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/";
        ApplicationBuilder builder = new ApplicationBuilder();
        builder.addSchemaFile(dir + "bad.sd");
        builder.build(true);
        derive("structinheritance", builder, builder.getSchema("bad"));
    }

}