aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/content/utils/DocType.java
blob: 3ffb33a47c856d784f75164c512e0bc1ba6d8367 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content.utils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Definition of a document type used for testing.
 *
 * @author geirst
 */
public class DocType {
    private final String type;
    private final String mode;
    private final boolean global;

    private DocType(String type, String mode, boolean global) {
        this.type = type;
        this.mode = mode;
        this.global = global;
    }

    public String toXml() {
        return (global ? "<document mode='" + mode + "' type='" + type + "' global='true'/>" :
                "<document mode='" + mode + "' type='" + type + "'/>");
    }
    public String getType() { return type; }

    public static DocType create(String type, String mode) { return new DocType(type, mode, false); }
    public static DocType createGlobal(String type, String mode) { return new DocType(type, mode, true); }
    public static DocType storeOnly(String type) {
        return new DocType(type, "store-only", false);
    }

    public static DocType index(String type) {
        return new DocType(type, "index", false);
    }

    public static DocType indexGlobal(String type) {
        return new DocType(type, "index", true);
    }

    public static DocType streaming(String type) {
        return new DocType(type, "streaming", false);
    }

    public static String listToXml(DocType... docTypes) {
        return listToXml(Arrays.asList(docTypes));
    }

    public static String listToXml(List<DocType> docTypes) {
        return "<documents>\n" +
                docTypes.stream().map(DocType::toXml).collect(Collectors.joining("\n")) + "\n" +
                "</documents>";
    }

}