aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderTestCase.java
blob: 7fe58c934347bf6a9413056b0165aec267e60fa5 (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
61
62
63
64
65
66
67
68
69
70
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.documentmodel;

import com.yahoo.document.config.DocumenttypesConfig;
import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.AbstractSchemaTestCase;
import com.yahoo.schema.parser.ParseException;
import com.yahoo.vespa.configmodel.producers.DocumentManager;
import com.yahoo.vespa.configmodel.producers.DocumentTypes;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class DocumentModelBuilderTestCase extends AbstractSchemaTestCase {

    @Test
    void testDocumentManagerSimple()  throws IOException, ParseException {
        DocumentModel model = createAndTestModel("src/test/configmodel/types/types.sd");

        DocumentmanagerConfig.Builder documentmanagerCfg = new DocumentManager().produce(model, new DocumentmanagerConfig.Builder());
        assertConfigFile("src/test/configmodel/types/documentmanager.cfg",
                new DocumentmanagerConfig(documentmanagerCfg).toString());
    }

    // This is ignored as enums in config are not testable in this way. See bug 4748050
    @Test
    void testDocumentTypesSimple()  throws IOException, ParseException {
        DocumentModel model = createAndTestModel("src/test/configmodel/types/types.sd");

        DocumenttypesConfig.Builder documenttypesCfg = new DocumentTypes().produce(model, new DocumenttypesConfig.Builder());
        assertConfigFile("src/test/configmodel/types/documenttypes.cfg",
                new DocumenttypesConfig(documenttypesCfg).toString());
    }

    @Test
    void testDocumentTypesWithDocumentField()  throws IOException, ParseException {
        ApplicationBuilder search = new ApplicationBuilder();
        search.addSchemaFile("src/test/configmodel/types/other_doc.sd");
        search.addSchemaFile("src/test/configmodel/types/type_with_doc_field.sd");
        search.build(true);
        DocumentModel model = search.getModel();

        DocumenttypesConfig.Builder documenttypesCfg = new DocumentTypes().produce(model, new DocumenttypesConfig.Builder());
        assertConfigFile("src/test/configmodel/types/documenttypes_with_doc_field.cfg",
                new DocumenttypesConfig(documenttypesCfg).toString());
    }

    @Test
    void testMultipleInheritanceArray() throws IOException, ParseException {
        ApplicationBuilder search = new ApplicationBuilder();
        search.addSchemaFile("src/test/cfg/search/data/travel/schemas/TTData.sd");
        search.addSchemaFile("src/test/cfg/search/data/travel/schemas/TTEdge.sd");
        search.addSchemaFile("src/test/cfg/search/data/travel/schemas/TTPOI.sd");
        search.build(true);
    }

    private DocumentModel createAndTestModel(String sd) throws IOException, ParseException {
        ApplicationBuilder search = ApplicationBuilder.createFromFile(sd);
        DocumentModel model = search.getModel();

        assertEquals(2, model.getDocumentManager().getTypes().size());
        assertNotNull(model.getDocumentManager().getDocumentType("document"));
        assertNotNull(model.getDocumentManager().getDocumentType("types"));
        return model;
    }

}