aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/content/utils/ApplicationPackageBuilder.java
blob: 8479bbc25b37424f375a5b744eeb01e4a581445f (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
// 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 com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg;

import java.util.ArrayList;
import java.util.List;

/**
 * Class for building an application package with content clusters (used for testing only).
 *
 * @author geirst
 */
public class ApplicationPackageBuilder {

    private List<ContentClusterBuilder> contentClusters = new ArrayList<>();
    private List<String> schemas = new ArrayList<>();

    public ApplicationPackageBuilder() {
    }

    public ApplicationPackageBuilder addCluster(ContentClusterBuilder contentCluster) {
        contentClusters.add(contentCluster);
        return this;
    }

    public ApplicationPackageBuilder addSchemas(String schemas) {
        this.schemas.add(schemas);
        return this;
    }

    public VespaModelCreatorWithMockPkg buildCreator() {
        return new VespaModelCreatorWithMockPkg(null, getServices(), schemas);
    }

    private String getServices() {
        return "<services version='1.0'>\n" +
                contentClusters.stream().map(cluster -> cluster.getXml() + "\n").reduce("", (acc, element) -> acc + element) +
                "</services>";
    }

}