aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-documentgen-plugin/src/test/java/com/yahoo/vespa/DocumentGenTest.java
blob: d0315f8427256016ceae449dd0e0d10aed3f1913 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa;

import com.yahoo.document.DataType;
import com.yahoo.document.StructDataType;
import com.yahoo.document.WeightedSetDataType;
import com.yahoo.schema.Schema;
import org.junit.Test;

import java.io.File;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

public class DocumentGenTest {

    @Test
    public void testMusic() {
        DocumentGenMojo mojo = new DocumentGenMojo();
        mojo.execute(new File("etc/music/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "com.yahoo.vespa.document");
        Map<String, Schema> searches = mojo.getSearches();
        assertEquals(searches.size(), 1);
        assertEquals(searches.get("music").getDocument("music").getField("title").getDataType(), DataType.STRING);
        assertEquals(searches.get("music").getDocument("music").getField("eitheror").getDataType(), DataType.BOOL);
        assertEquals(searches.get("music").getDocument("music").getField("tags").getDataType(),
                     searches.get("music").getSummaries().get("tags").getSummaryField("tags").getDataType());
    }

    @Test
    public void testComplex() {
        DocumentGenMojo mojo = new DocumentGenMojo();
        mojo.execute(new File("etc/complex/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "com.yahoo.vespa.document");
        Map<String, Schema> searches = mojo.getSearches();
        assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT);
        assertEquals(searches.get("book").getDocument("book").getField("sw1").getDataType(), DataType.FLOAT);
        assertTrue(searches.get("music3").getDocument("music3").getField("pos").getDataType() instanceof StructDataType);
        assertEquals(searches.get("music3").getDocument("music3").getField("pos").getDataType().getName(), "position");
        assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
        assertTrue(searches.get("book").getDocument("book").getField("mywsinteger").getDataType() instanceof WeightedSetDataType);
        assertSame(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType(), DataType.INT);
    }

    @Test
    public void testLocalApp() {
        DocumentGenMojo mojo = new DocumentGenMojo();
        mojo.execute(new File("etc/localapp/"), new File("target/generated-test-sources/vespa-documentgen-plugin/"), "com.yahoo.vespa.document");
        Map<String, Schema> searches = mojo.getSearches();
        assertEquals(searches.get("video").getDocument("video").getField("weight").getDataType(), DataType.FLOAT);
        assertTrue(searches.get("book").getDocument("book").getField("mystruct").getDataType() instanceof StructDataType);
        assertTrue(searches.get("book").getDocument("book").getField("mywsinteger").getDataType() instanceof WeightedSetDataType);
        assertSame(((WeightedSetDataType) (searches.get("book").getDocument("book").getField("mywsinteger").getDataType())).getNestedType(), DataType.INT);
    }

    @Test
    public void testEmptyPkgNameForbidden() {
        assertThrows(IllegalArgumentException.class,
                     () -> new DocumentGenMojo().execute(new File("etc/localapp/"),
                                                         new File("target/generated-test-sources/vespa-documentgen-plugin/"),
                                                         ""));
    }

}