blob: 190e4f772be4298331f8db3bded1890582bdb50f (
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
|
// Copyright Yahoo. 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.ConnectionException;
import com.yahoo.vespa.hosted.node.admin.configserver.state.bindings.HealthResponse;
import org.junit.jupiter.api.Test;
import java.net.ConnectException;
import static org.junit.jupiter.api.Assertions.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
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
void connectException() {
RuntimeException exception =
ConnectionException.handleException("Error: ", new ConnectException("connection refused"));
when(api.get(any(), any())).thenThrow(exception);
HealthCode code = state.getHealth();
assertEquals(HealthCode.DOWN, code);
}
}
|