aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderImportedFieldsTestCase.java
blob: 3995ca2412da3b998a8234ab169bf2e386677f33 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.documentmodel;

import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.parser.ParseException;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static com.yahoo.config.model.test.TestUtil.joinLines;

public class DocumentModelBuilderImportedFieldsTestCase extends AbstractReferenceFieldTestCase {

    @Test
    void imported_fields_are_included_in_generated_document_configs() throws ParseException, IOException {
        assertDocumentConfigs(new TestDocumentModelBuilder().addCampaign().addPerson().build(joinLines(
                        "search ad {",
                        "  document ad {",
                        "    field campaign_ref type reference<campaign> { indexing: attribute }",
                        "    field person_ref type reference<person> { indexing: attribute }",
                        "  }",
                        "  import field campaign_ref.cool_field as my_cool_field {}",
                        "  import field campaign_ref.swag_field as my_swag_field {}",
                        "  import field person_ref.name as my_name {}",
                        "}")),
                "multiple_imported_fields");
    }

    private static class TestDocumentModelBuilder {
        private final ApplicationBuilder builder = new ApplicationBuilder();
        public TestDocumentModelBuilder addCampaign() throws ParseException {
            builder.addSchema(joinLines("search campaign {",
                                        "  document campaign {",
                                        "    field cool_field type string { indexing: attribute }",
                                        "    field swag_field type long { indexing: attribute }",
                                        "  }",
                                        "}"));
            return this;
        }
        public TestDocumentModelBuilder addPerson() throws ParseException {
            builder.addSchema(joinLines("search person {",
                                        "  document person {",
                                        "    field name type string { indexing: attribute }",
                                        "  }",
                                        "}"));
            return this;
        }
        public DocumentModel build(String adSdContent) throws ParseException {
            builder.addSchema(adSdContent);
            builder.build(true);
            return builder.getModel();
        }
    }

}