aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/derived/SimpleInheritTestCase.java
blob: e5b95e8a6caabf19af2f2eec1bf004209f99dab0 (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
// 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.Schema;
import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.parser.ParseException;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

/**
 * Tests really simple inheriting
 */
public class SimpleInheritTestCase extends AbstractExportingTestCase {

    @Test
    void testEmptyChild() throws IOException, ParseException {
        String name = "emptychild";
        final String expectedResultsDirName = "src/test/derived/" + name + "/";

        ApplicationBuilder builder = new ApplicationBuilder();
        builder.addSchemaFile(expectedResultsDirName + "parent.sd");
        builder.addSchemaFile(expectedResultsDirName + "child.sd");
        builder.build(true);

        Schema schema = builder.getSchema("child");

        String toDirName = "temp/" + name;
        File toDir = new File(toDirName);
        toDir.mkdirs();
        deleteContent(toDir);

        DerivedConfiguration config = new DerivedConfiguration(schema, builder.getRankProfileRegistry());
        config.export(toDirName);

        checkDir(toDirName, expectedResultsDirName);
    }

    private void checkDir(String toDirName, String expectedResultsDirName) throws IOException {
        File[] files = new File(expectedResultsDirName).listFiles();
        for (File file : files) {
            if ( ! file.getName().endsWith(".cfg")) continue;
            assertEqualFiles(file.getPath(), toDirName + "/" + file.getName(), false);
        }
    }
}