summaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsSlimeConverterTest.java
blob: 84c69fef3a17d7ff62d01b98a71d8fb950685eb0 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.configchange;

import com.yahoo.slime.Cursor;
import com.yahoo.slime.JsonFormat;
import com.yahoo.slime.Slime;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static com.yahoo.vespa.config.server.configchange.Utils.*;

/**
 * @author geirst
 * @since 5.44
 */
public class ConfigChangeActionsSlimeConverterTest {

    private static String toJson(ConfigChangeActions actions) throws IOException {
        Slime slime = new Slime();
        Cursor root = slime.setObject();
        new ConfigChangeActionsSlimeConverter(actions).toSlime(root);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        new JsonFormat(false).encode(outputStream, slime);
        return outputStream.toString();
    }

    @Test
    public void json_representation_of_empty_actions() throws IOException {
        ConfigChangeActions actions = new ConfigChangeActionsBuilder().build();
        assertEquals(   "{\n" +
                        " \"configChangeActions\": {\n" +
                        "  \"restart\": [\n" +
                        "  ],\n" +
                        "  \"refeed\": [\n" +
                        "  ]\n" +
                        " }\n" +
                        "}\n",
                     toJson(actions));
    }

    @Test
    public void json_representation_of_restart_actions() throws IOException {
        ConfigChangeActions actions = new ConfigChangeActionsBuilder().
                restart(CHANGE_MSG, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME).
                restart(CHANGE_MSG, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME_2).
                restart(CHANGE_MSG_2, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME).
                restart(CHANGE_MSG_2, CLUSTER, CLUSTER_TYPE, SERVICE_TYPE, SERVICE_NAME_2).build();
        assertEquals("{\n" +
                        " \"configChangeActions\": {\n" +
                        "  \"restart\": [\n" +
                        "   {\n" +
                        "    \"clusterName\": \"foo\",\n" +
                        "    \"clusterType\": \"search\",\n" +
                        "    \"serviceType\": \"searchnode\",\n" +
                        "    \"messages\": [\n" +
                        "     \"change\",\n" +
                        "     \"other change\"\n" +
                        "    ],\n" +
                        "    \"services\": [\n" +
                        "     {\n" +
                        "      \"serviceName\": \"baz\",\n" +
                        "      \"serviceType\": \"searchnode\",\n" +
                        "      \"configId\": \"searchnode/baz\",\n" +
                        "      \"hostName\": \"hostname\"\n" +
                        "     },\n" +
                        "     {\n" +
                        "      \"serviceName\": \"qux\",\n" +
                        "      \"serviceType\": \"searchnode\",\n" +
                        "      \"configId\": \"searchnode/qux\",\n" +
                        "      \"hostName\": \"hostname\"\n" +
                        "     }\n" +
                        "    ]\n" +
                        "   }\n" +
                        "  ],\n" +
                        "  \"refeed\": [\n" +
                        "  ]\n" +
                        " }\n" +
                        "}\n",
                     toJson(actions));
    }

    @Test
    public void json_representation_of_refeed_actions() throws IOException {
        ConfigChangeActions actions = new ConfigChangeActionsBuilder().
                refeed(CHANGE_ID, true, CHANGE_MSG, DOC_TYPE, CLUSTER, SERVICE_TYPE).
                refeed(CHANGE_ID_2, false, CHANGE_MSG, DOC_TYPE_2, CLUSTER, SERVICE_TYPE).build();
        assertEquals("{\n" +
                        " \"configChangeActions\": {\n" +
                        "  \"restart\": [\n" +
                        "  ],\n" +
                        "  \"refeed\": [\n" +
                        "   {\n" +
                        "    \"name\": \"change-id\",\n" +
                        "    \"allowed\": true,\n" +
                        "    \"documentType\": \"music\",\n" +
                        "    \"clusterName\": \"foo\",\n" +
                        "    \"messages\": [\n" +
                        "     \"change\"\n" +
                        "    ],\n" +
                        "    \"services\": [\n" +
                        "     {\n" +
                        "      \"serviceName\": \"searchnode\",\n" +
                        "      \"serviceType\": \"myservicetype\",\n" +
                        "      \"configId\": \"myservicetype/searchnode\",\n" +
                        "      \"hostName\": \"hostname\"\n" +
                        "     }\n" +
                        "    ]\n" +
                        "   },\n" +
                        "   {\n" +
                        "    \"name\": \"other-change-id\",\n" +
                        "    \"allowed\": false,\n" +
                        "    \"documentType\": \"book\",\n" +
                        "    \"clusterName\": \"foo\",\n" +
                        "    \"messages\": [\n" +
                        "     \"change\"\n" +
                        "    ],\n" +
                        "    \"services\": [\n" +
                        "     {\n" +
                        "      \"serviceName\": \"searchnode\",\n" +
                        "      \"serviceType\": \"myservicetype\",\n" +
                        "      \"configId\": \"myservicetype/searchnode\",\n" +
                        "      \"hostName\": \"hostname\"\n" +
                        "     }\n" +
                        "    ]\n" +
                        "   }\n" +
                        "  ]\n" +
                        " }\n" +
                        "}\n",
                     toJson(actions));
    }

}