aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/tests/loadtypes/loadtypetest.cpp
blob: 9afd578354625f3d210bf6a7a081486ae1bd41bb (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/documentapi/loadtypes/loadtypeset.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/config/config.h>
#include <vespa/config/common/exceptions.h>

namespace documentapi {

struct LoadTypeTest : public CppUnit::TestFixture {

    void testConfig();

    CPPUNIT_TEST_SUITE(LoadTypeTest);
    CPPUNIT_TEST(testConfig);
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(LoadTypeTest);

#define ASSERT_CONFIG_FAILURE(configId, error) \
    try { \
        LoadTypeSet createdFromConfigId(vespalib::stringref(configId)); \
        CPPUNIT_FAIL("Config was expected to fail with error: " \
                     + string(error)); \
    } catch (config::InvalidConfigException& e) { \
        CPPUNIT_ASSERT_CONTAIN(string(error), e.getMessage()); \
    }

void
LoadTypeTest::testConfig()
{
        // Using id 0 is illegal. Reserved for default type.
    ASSERT_CONFIG_FAILURE(
            "raw:"
            "type[1]\n"
            "type[0].id 0\n"
            "type[0].name \"foo\"\n"
            "type[0].priority \"\"",
            "Load type identifiers need to be");
        // Using name "default" is illegal. Reserved for default type.
    ASSERT_CONFIG_FAILURE(
            "raw:"
            "type[1]\n"
            "type[0].id 1\n"
            "type[0].name \"default\"\n"
            "type[0].priority \"\"", "Load type names need to be");
        // Identifiers need to be unique.
    ASSERT_CONFIG_FAILURE(
            "raw:"
            "type[2]\n"
            "type[0].id 1\n"
            "type[0].name \"test\"\n"
            "type[0].priority \"\"\n"
            "type[1].id 1\n"
            "type[1].name \"testa\"\n"
            "type[1].priority \"\"",  "Load type identifiers need to be");
        // Names need to be unique.
    ASSERT_CONFIG_FAILURE(
            "raw:"
            "type[2]\n"
            "type[0].id 1\n"
            "type[0].name \"test\"\n"
            "type[0].priority \"\"\n"
            "type[1].id 2\n"
            "type[1].name \"test\"\n"
            "type[1].priority \"\"" , "Load type names need to be");
    LoadTypeSet set("raw:"
            "type[3]\n"
            "type[0].id 1\n"
            "type[0].name \"user\"\n"
            "type[0].priority \"\"\n"
            "type[1].id 2\n"
            "type[1].name \"maintenance\"\n"
            "type[1].priority \"\"\n"
            "type[2].id 3\n"
            "type[2].name \"put\"\n"
            "type[2].priority \"\""
    );
}

} // documentapi