aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/AssertIndexingScript.java
blob: 36f20c1858846f68fa3f89dacd71defd44c90710 (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
// 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.derived.IndexingScript;
import com.yahoo.vespa.indexinglanguage.expressions.Expression;
import com.yahoo.vespa.indexinglanguage.parser.ParseException;

import java.util.LinkedList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * @author Simon Thoresen Hult
 */
public abstract class AssertIndexingScript {

    public static void assertIndexing(List<String> expected, Schema schema) {
        assertIndexing(expected, new IndexingScript(schema).expressions());
    }

    public static void assertIndexing(List<String> expected, IndexingScript script) {
        assertIndexing(expected, script.expressions());
    }

    public static void assertIndexing(List<String> expected, Iterable<Expression> actual) {
        List<String> parsedExpected = new LinkedList<>();
        for (String str : expected) {
            try {
                parsedExpected.add(Expression.fromString(str).toString());
            } catch (ParseException e) {
                fail(e.getMessage());
            }
        }
        for (Expression actualExp : actual) {
            String str = actualExp.toString();
            assertTrue(parsedExpected.remove(str), "Unexpected: " + str);
        }
        assertTrue(parsedExpected.isEmpty(), "Missing: " + parsedExpected);
    }
}