aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/http/status/StatusHandlerTest.java
blob: 756ed52c316e25fbd8c27303fee9ad216849791d (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.config.server.http.status;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.model.NullConfigModelRegistry;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.model.VespaModelFactory;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

import static com.yahoo.jdisc.http.HttpRequest.Method.GET;
import static org.junit.Assert.assertEquals;

/**
 * @author hmusum
 */
public class StatusHandlerTest {

    private final ObjectMapper mapper = new ObjectMapper();

    @Test
    public void require_that_handler_works() throws IOException {
        ModelFactoryRegistry modelFactoryRegistry = new ModelFactoryRegistry(List.of(VespaModelFactory.createTestFactory()));
        ConfigserverConfig configserverConfig = new ConfigserverConfig.Builder().build();
        StatusHandler handler = new StatusHandler(StatusHandler.testContext(), modelFactoryRegistry, configserverConfig);

        HttpResponse response = handler.handle(HttpRequest.createTestRequest("/status", GET));
        JsonNode jsonNode = mapper.readTree(SessionHandlerTest.getRenderedString(response));

        assertEquals(configserverConfig.rpcport(), jsonNode.get("configserverConfig").get("rpcport").asInt());
        assertEquals(configserverConfig.applicationDirectory(), jsonNode.get("configserverConfig").get("applicationDirectory").asText());

        assertEquals(1, jsonNode.get("modelVersions").size());
    }

}