blob: 2604aa0536725e8967d8db1908cf6d2730da09db (
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
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.configserver.state;
import com.yahoo.vespa.hosted.node.admin.configserver.ConfigServerApi;
import com.yahoo.vespa.hosted.node.admin.configserver.state.bindings.HealthResponse;
import org.junit.Test;
import java.net.ConnectException;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class StateImplTest {
private final ConfigServerApi api = mock(ConfigServerApi.class);
private final StateImpl state = new StateImpl(api);
@Test
public void testWhenUp() {
HealthResponse response = new HealthResponse();
response.status.code = "up";
when(api.get(any(), any())).thenReturn(response);
HealthCode code = state.getHealth();
assertEquals(HealthCode.UP, code);
}
@Test
public void connectException() {
RuntimeException exception = new RuntimeException(new ConnectException("connection refused"));
when(api.get(any(), any())).thenThrow(exception);
HealthCode code = state.getHealth();
assertEquals(HealthCode.DOWN, code);
}
}
|