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

import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.schema.RankProfileRegistry;
import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.schema.parser.ParseException;
import org.junit.jupiter.api.Test;

import java.util.logging.Level;

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

/**
 * @author lesters
 */
public class ReservedRankingExpressionFunctionNamesTestCase {

    @Test
    void requireThatFunctionsWithReservedNamesIssueAWarning() throws ParseException {
        TestDeployLogger deployLogger = new TestDeployLogger();
        RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
        ApplicationBuilder builder = new ApplicationBuilder(deployLogger, rankProfileRegistry);
        builder.addSchema(
                "search test {\n" +
                        "    document test { \n" +
                        "        field a type string { \n" +
                        "            indexing: index \n" +
                        "        }\n" +
                        "    }\n" +
                        "    \n" +
                        "    rank-profile test_rank_profile {\n" +
                        "        function not_a_reserved_name(x) {\n" +
                        "            expression: x + x\n" +
                        "        }\n" +
                        "        function sigmoid(x) {\n" +
                        "            expression: x * x\n" +
                        "        }\n" +
                        "        first-phase {\n" +
                        "            expression: sigmoid(2) + not_a_reserved_name(1)\n" +
                        "        }\n" +
                        "    }\n" +
                        "    rank-profile test_rank_profile_2 inherits test_rank_profile {\n" +
                        "        function sin(x) {\n" +
                        "            expression: x * x\n" +
                        "        }\n" +
                        "        first-phase {\n" +
                        "            expression: sigmoid(2) + sin(1)\n" +
                        "        }\n" +
                        "    }\n" +
                        "}\n");
        builder.build(true);

        assertTrue(deployLogger.log.contains("sigmoid") && deployLogger.log.contains("test_rank_profile"));
        assertTrue(deployLogger.log.contains("sigmoid") && deployLogger.log.contains("test_rank_profile_2"));
        assertTrue(deployLogger.log.contains("sin") && deployLogger.log.contains("test_rank_profile_2"));
        assertFalse(deployLogger.log.contains("not_a_reserved_name") && deployLogger.log.contains("test_rank_profile"));
        assertFalse(deployLogger.log.contains("not_a_reserved_name") && deployLogger.log.contains("test_rank_profile_2"));

    }

    public static class TestDeployLogger implements DeployLogger {
        public String log = "";
        @Override
        public void log(Level level, String message) {
            log += message;
        }
    }
    
}