aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/ImplicitSchemaFieldsTestCase.java
blob: c758d49f79fe3f9bcad93941a863efec46a27b9d (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.processing;

import com.yahoo.schema.Schema;
import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.AbstractSchemaTestCase;
import com.yahoo.schema.derived.DerivedConfiguration;
import com.yahoo.schema.document.SDDocumentType;
import com.yahoo.schema.parser.ParseException;
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 ImplicitSchemaFieldsTestCase extends AbstractSchemaTestCase {

    @Test
    void testRequireThatExtraFieldsAreIncluded() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/extrafield.sd");
        assertNotNull(schema);

        SDDocumentType docType = schema.getDocument();
        assertNotNull(docType);
        assertNotNull(docType.getField("foo"));
        assertNotNull(docType.getField("bar"));
        assertEquals(2, docType.getFieldCount());
    }

    @Test
    void testRequireThatSummaryFieldsAreIncluded() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/summaryfield.sd");
        assertNotNull(schema);

        SDDocumentType docType = schema.getDocument();
        assertNotNull(docType);
        assertNotNull(docType.getField("foo"));
        assertNotNull(docType.getField("bar"));
        assertNotNull(docType.getField("cox"));
        assertNotNull(docType.getField("mytags"));
        assertNotNull(docType.getField("alltags"));
        assertEquals(5, docType.getFieldCount());
    }

    @Test
    void testRequireThatBoldedSummaryFieldsAreIncluded() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/boldedsummaryfields.sd");
        assertNotNull(schema);

        SDDocumentType docType = schema.getDocument();
        assertNotNull(docType);
        assertNotNull(docType.getField("foo"));
        assertNotNull(docType.getField("bar"));
        assertNotNull(docType.getField("baz"));
        assertNotNull(docType.getField("cox"));
        assertEquals(4, docType.getFieldCount());
    }

    @Test
    void testRequireThatUntransformedSummaryFieldsAreIgnored() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/untransformedsummaryfields.sd");
        assertNotNull(schema);

        SDDocumentType docType = schema.getDocument();
        assertNotNull(docType);
        assertNotNull(docType.getField("foo"));
        assertNotNull(docType.getField("bar"));
        assertNotNull(docType.getField("baz"));
        assertEquals(3, docType.getFieldCount());
    }

    @Test
    void testRequireThatDynamicSummaryFieldsAreIgnored() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/nextgen/dynamicsummaryfields.sd");
        assertNotNull(schema);

        SDDocumentType docType = schema.getDocument();
        assertNotNull(docType);
        assertNotNull(docType.getField("foo"));
        assertNotNull(docType.getField("bar"));
        assertEquals(2, docType.getFieldCount());
    }

    @Test
    void testRequireThatDerivedConfigurationWorks() throws IOException, ParseException {
        ApplicationBuilder sb = new ApplicationBuilder();
        sb.addSchemaFile("src/test/examples/nextgen/simple.sd");
        sb.build(true);
        assertNotNull(sb.getSchema());
        new DerivedConfiguration(sb.getSchema(), sb.getRankProfileRegistry());
    }

}