aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/tests/fixed_bucket_spaces_test.cpp
blob: 12c248adf37f9bc7d10ef18f69122c134793b913 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/document/bucket/fixed_bucket_spaces.h>
#include <cppunit/extensions/HelperMacros.h>

namespace document {

struct FixedBucketSpacesTest : CppUnit::TestFixture {
    CPPUNIT_TEST_SUITE(FixedBucketSpacesTest);
    CPPUNIT_TEST(bucket_space_from_name_is_defined_for_default_space);
    CPPUNIT_TEST(bucket_space_from_name_is_defined_for_global_space);
    CPPUNIT_TEST(bucket_space_from_name_throws_exception_for_unknown_space);
    CPPUNIT_TEST(name_from_bucket_space_is_defined_for_default_space);
    CPPUNIT_TEST(name_from_bucket_space_is_defined_for_global_space);
    CPPUNIT_TEST(name_from_bucket_space_throws_exception_for_unknown_space);
    CPPUNIT_TEST_SUITE_END();

    void bucket_space_from_name_is_defined_for_default_space();
    void bucket_space_from_name_is_defined_for_global_space();
    void bucket_space_from_name_throws_exception_for_unknown_space();
    void name_from_bucket_space_is_defined_for_default_space();
    void name_from_bucket_space_is_defined_for_global_space();
    void name_from_bucket_space_throws_exception_for_unknown_space();
};

CPPUNIT_TEST_SUITE_REGISTRATION(FixedBucketSpacesTest);

void FixedBucketSpacesTest::bucket_space_from_name_is_defined_for_default_space() {
    CPPUNIT_ASSERT_EQUAL(FixedBucketSpaces::default_space(), FixedBucketSpaces::from_string("default"));
}

void FixedBucketSpacesTest::bucket_space_from_name_is_defined_for_global_space() {
    CPPUNIT_ASSERT_EQUAL(FixedBucketSpaces::global_space(), FixedBucketSpaces::from_string("global"));
}

void FixedBucketSpacesTest::bucket_space_from_name_throws_exception_for_unknown_space() {
    try {
        FixedBucketSpaces::from_string("banana");
        CPPUNIT_FAIL("Expected exception on unknown bucket space name");
    } catch (document::UnknownBucketSpaceException& e) {
    }
}

void FixedBucketSpacesTest::name_from_bucket_space_is_defined_for_default_space() {
    CPPUNIT_ASSERT_EQUAL(vespalib::stringref("default"),
                         FixedBucketSpaces::to_string(FixedBucketSpaces::default_space()));
    CPPUNIT_ASSERT_EQUAL(vespalib::stringref("default"), FixedBucketSpaces::default_space_name());
}

void FixedBucketSpacesTest::name_from_bucket_space_is_defined_for_global_space() {
    CPPUNIT_ASSERT_EQUAL(vespalib::stringref("global"),
                         FixedBucketSpaces::to_string(FixedBucketSpaces::global_space()));
    CPPUNIT_ASSERT_EQUAL(vespalib::stringref("global"), FixedBucketSpaces::global_space_name());
}

void FixedBucketSpacesTest::name_from_bucket_space_throws_exception_for_unknown_space() {
    try {
        FixedBucketSpaces::to_string(BucketSpace(4567));
        CPPUNIT_FAIL("Expected exception on unknown bucket space value");
    } catch (document::UnknownBucketSpaceException& e) {
    }
}

}