aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/restapi/impl/StatusPageResourceTest.java
blob: 2351b26f337c4193897cd93319aaed46925248b4 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.restapi.impl;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.jdisc.http.SecretStore;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.UriBuilder;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * @author frodelu
 */
public class StatusPageResourceTest {

    private StatusPageResource statusPage;

    @Before
    public void setup() throws IOException {

        Client mockClient = Mockito.mock(Client.class);
        WebTarget mockTarget = Mockito.mock(WebTarget.class);
        Invocation.Builder mockRequest = Mockito.mock(Invocation.Builder.class);
        SecretStore secretStore = Mockito.mock(SecretStore.class);

        Mockito.when(mockClient.target(Mockito.any(UriBuilder.class))).thenReturn(mockTarget);
        Mockito.when(mockTarget.request()).thenReturn(mockRequest);
        Mockito.when(mockRequest.get(JsonNode.class)).thenReturn(
            new ObjectMapper().readTree("{\"page\":{\"name\":\"Vespa\"}}"));
        Mockito.when(secretStore.getSecret(Mockito.any(String.class))).thenReturn("testpage:testkey");

        statusPage = new StatusPageResource(secretStore, mockClient);
    }


    @Test
    public void default_url() {
        UriBuilder uri = statusPage.statusPageURL("incidents", null);
        assertNotNull("URI not initialized", uri);
        assertEquals("https://testpage.statuspage.io/api/v2/incidents.json?api_key=testkey", uri.toTemplate());
    }

    @Test
    public void url_with_since_param() {
        UriBuilder uri = statusPage.statusPageURL("incidents", "2015-01-01T00:00+00:00");
        assertNotNull("URI not initialized", uri);
        assertEquals("https://testpage.statuspage.io/api/v2/incidents.json?api_key=testkey&since=2015-01-01T00%3A00%2B00%3A00", uri.toTemplate());
    }

    @Test
    public void valid_status_page() {
        JsonNode result = statusPage.statusPage("incidents", null);
        assertNotNull("No result from StatusPage.io", result);
        assertEquals("Vespa", result.get("page").get("name").asText());
    }
}