aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/ConfigChangeTestUtils.java
blob: 64eb63e8a56a4d9ae8e624e4a6e9bb9d9e1a92aa (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation.change;

import com.yahoo.config.application.api.ValidationId;
import com.yahoo.config.model.api.ConfigChangeAction;
import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.config.provision.ClusterSpec;

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

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ConfigChangeTestUtils {

    public static VespaConfigChangeAction newRestartAction(ClusterSpec.Id id, String message) {
        return new VespaRestartAction(id, message);
    }

    public static VespaConfigChangeAction newRestartAction(ClusterSpec.Id id, String message, List<ServiceInfo> services) {
        return new VespaRestartAction(id, message, services);
    }

    public static VespaConfigChangeAction newRefeedAction(ClusterSpec.Id id, ValidationId validationId, String message) {
        return VespaRefeedAction.of(id, validationId, message);
    }

    public static VespaConfigChangeAction newRefeedAction(ClusterSpec.Id id, ValidationId validationId, String message,
                                                          List<ServiceInfo> services, String documentType) {
        return VespaRefeedAction.of(id, validationId, message, services, documentType);
    }

    public static VespaConfigChangeAction newReindexAction(ClusterSpec.Id id, ValidationId validationId, String message) {
        return VespaReindexAction.of(id, validationId, message);
    }

    public static VespaConfigChangeAction newReindexAction(ClusterSpec.Id id, ValidationId validationId, String message,
                                                           List<ServiceInfo> services, String documentType) {
        return VespaReindexAction.of(id, validationId, message, services, documentType);
    }

    public static List<ConfigChangeAction> normalizeServicesInActions(List<ConfigChangeAction> result) {
        return result.stream()
                .map(action -> ((VespaConfigChangeAction) action).modifyAction(
                        action.getMessage(),
                        normalizeServices(action.getServices()),
                        action.getType().equals(ConfigChangeAction.Type.REFEED) ?
                                ((VespaRefeedAction)action).getDocumentType() : ""))
                .collect(Collectors.toList());
    }

    public static List<ServiceInfo> normalizeServices(List<ServiceInfo> services) {
        return services.stream()
                .map(service -> new ServiceInfo(service.getServiceName(), "null", null, null,
                        service.getConfigId(), "null"))
                .toList();
    }

    public static void assertEqualActions(List<ConfigChangeAction> exp, List<ConfigChangeAction> act) {
        var mutableExp = new ArrayList<>(exp);
        var mutableAct = new ArrayList<>(act);
        mutableExp.sort((lhs, rhs) -> lhs.getMessage().compareTo(rhs.getMessage()));
        mutableAct.sort((lhs, rhs) -> lhs.getMessage().compareTo(rhs.getMessage()));
        assertEquals(mutableExp, mutableAct);
    }

}