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

import com.yahoo.document.DataType;
import com.yahoo.document.DocumentType;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.document.DocumentTypeManagerConfigurer;
import com.yahoo.document.Field;
import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.schema.derived.Deriver;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;

/**
 * @author Einar M R Rosenvinge
 */
public class FieldOfTypeDocumentTestCase extends AbstractSchemaTestCase {

    @Test
    void testDocument() throws IOException {

        List<String> sds = new ArrayList<>();
        sds.add("src/test/examples/music.sd");
        sds.add("src/test/examples/fieldoftypedocument.sd");
        DocumentmanagerConfig.Builder value = Deriver.getDocumentManagerConfig(sds);
        assertConfigFile("src/test/examples/fieldoftypedocument.cfg",
                new DocumentmanagerConfig(value).toString() + "\n");

        DocumentTypeManager manager = new DocumentTypeManager();
        DocumentTypeManagerConfigurer.configure(manager, "raw:" + new DocumentmanagerConfig(value).toString());


        DocumentType musicType = manager.getDocumentType("music");
        assertEquals(3, musicType.getFieldCount());

        Field intField = musicType.getField("intfield");
        assertEquals(DataType.INT, intField.getDataType());
        Field stringField = musicType.getField("stringfield");
        assertEquals(DataType.STRING, stringField.getDataType());
        Field longField = musicType.getField("longfield");
        assertEquals(DataType.LONG, longField.getDataType());


        DocumentType bookType = manager.getDocumentType("book");
        assertEquals(1, bookType.getFieldCount());

        Field musicField = bookType.getField("soundtrack");
        assertSame(musicType, musicField.getDataType());
    }

}