aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/content/utils/SchemaBuilder.java
blob: fee16620e02adbf7437eca90aac8e387c5197f53 (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
// Copyright Yahoo. 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;

import static com.yahoo.config.model.test.TestUtil.joinLines;

/**
 * Class for building a search definition (used for testing only).
 *
 * @author geirst
 */
public class SchemaBuilder {

    private String name = "test";
    private String content = "";

    public SchemaBuilder() {
    }

    public SchemaBuilder name(String name) {
        this.name = name;
        return this;
    }

    public SchemaBuilder content(String content) {
        this.content = content;
        return this;
    }

    public String build() {
        return joinLines("search " + name + " {",
                "  document " + name + " {",
                content,
                "  }",
                "}");
    }

    public static List<String> createSchemas(String ... docTypes) {
        return Arrays.asList(docTypes)
                .stream()
                .map(type -> new SchemaBuilder().name(type).build())
                .toList();
    }

}