summaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/search/ContentClusterFixture.java
blob: 51fdff7b1ac6398439fc0ce5579816a31eda4ba9 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation.change.search;

import com.yahoo.documentmodel.NewDocumentType;
import com.yahoo.vespa.model.application.validation.change.VespaConfigChangeAction;
import com.yahoo.vespa.model.content.cluster.ContentCluster;
import com.yahoo.vespa.model.content.utils.ContentClusterBuilder;
import com.yahoo.vespa.model.content.utils.ContentClusterUtils;
import com.yahoo.vespa.model.content.utils.SearchDefinitionBuilder;
import com.yahoo.vespa.model.search.DocumentDatabase;

import java.util.Arrays;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
 * Test fixture to setup current and next content clusters used for change validation.
 *
 * @author geirst
 */
public abstract class ContentClusterFixture {
    protected ContentCluster currentCluster;
    protected ContentCluster nextCluster;

    public ContentClusterFixture(String currentSd, String nextSd) throws Exception {
        currentCluster = createCluster(currentSd);
        nextCluster = createCluster(nextSd);
    }

    private static ContentCluster createCluster(String sdContent) throws Exception {
        return new ContentClusterBuilder().build(
                ContentClusterUtils.createMockRoot(
                        Arrays.asList(new SearchDefinitionBuilder().content(sdContent).build())));
    }

    protected DocumentDatabase currentDb() {
        return currentCluster.getSearch().getIndexed().getDocumentDbs().get(0);
    }

    protected NewDocumentType currentDocType() {
        return currentCluster.getDocumentDefinitions().get("test");
    }

    protected DocumentDatabase nextDb() {
        return nextCluster.getSearch().getIndexed().getDocumentDbs().get(0);
    }

    protected NewDocumentType nextDocType() {
        return nextCluster.getDocumentDefinitions().get("test");
    }

    public void assertValidation() {
        List<VespaConfigChangeAction> act = validate();
        assertThat(act.size(), is(0));
    }

    public void assertValidation(VespaConfigChangeAction exp) {
        assertValidation(Arrays.asList(exp));
    }

    public void assertValidation(List<VespaConfigChangeAction> exp) {
        List<VespaConfigChangeAction> act = validate();
        assertThat(act, equalTo(exp));
    }

    public abstract List<VespaConfigChangeAction> validate();

}