summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/processing/TensorFieldTestCase.java
blob: 2fcf5809ea557b041ed7b1065638cf603e4614f9 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchdefinition.processing;

import com.yahoo.searchdefinition.SearchBuilder;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * @author geirst
 */
public class TensorFieldTestCase {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Test
    public void requireThatTensorFieldCannotBeOfCollectionType() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("For search 'test', field 'f1': A field with collection type of tensor is not supported. Use simple type 'tensor' instead.");
        SearchBuilder.createFromString(getSd("field f1 type array<tensor(x{})> {}"));
    }

    @Test
    public void requireThatTensorFieldCannotBeIndexField() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("For search 'test', field 'f1': A field of type 'tensor' cannot be specified as an 'index' field.");
        SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: index }"));
    }

    @Test
    public void requireThatTensorAttributeCannotBeFastSearch() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("For search 'test', field 'f1': An attribute of type 'tensor' cannot be 'fast-search'.");
        SearchBuilder.createFromString(getSd("field f1 type tensor(x{}) { indexing: attribute \n attribute: fast-search }"));
    }

    @Test
    public void requireThatIllegalTensorTypeSpecThrowsException() throws ParseException {
        exception.expect(IllegalArgumentException.class);
        exception.expectMessage("Field type: Illegal tensor type spec: Failed parsing element 'invalid' in type spec 'tensor(invalid)'");
        SearchBuilder.createFromString(getSd("field f1 type tensor(invalid) { indexing: attribute }"));
    }

    private static String getSd(String field) {
        return "search test {\n document test {\n" + field + "}\n}\n";
    }

}