|
11 | 11 | package com.redhat.devtools.intellij.common.kubernetes;
|
12 | 12 |
|
13 | 13 | import io.fabric8.kubernetes.client.KubernetesClient;
|
14 |
| -import io.fabric8.kubernetes.client.KubernetesClientException; |
15 | 14 | import io.fabric8.kubernetes.client.VersionInfo;
|
16 | 15 | import io.fabric8.openshift.client.OpenShiftClient;
|
17 | 16 | import org.junit.Test;
|
18 | 17 |
|
19 |
| -import java.net.HttpURLConnection; |
20 |
| - |
21 | 18 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 19 | import static org.junit.Assert.assertEquals;
|
23 | 20 | import static org.junit.Assert.assertFalse;
|
24 | 21 | import static org.junit.Assert.assertTrue;
|
25 |
| -import static org.mockito.Mockito.doReturn; |
26 |
| -import static org.mockito.Mockito.doThrow; |
27 | 22 | import static org.mockito.Mockito.mock;
|
28 | 23 | import static org.mockito.Mockito.when;
|
29 | 24 |
|
@@ -77,46 +72,24 @@ public void testOCP3OrOCP4AdminUserCluster() {
|
77 | 72 | }
|
78 | 73 |
|
79 | 74 | @Test
|
80 |
| - public void isOpenShift_should_return_true_if_isSupported() { |
| 75 | + public void isOpenShift_should_return_true_if_has_api_group() { |
81 | 76 | // given
|
82 |
| - OpenShiftClient oclient = mock(OpenShiftClient.class); |
83 |
| - doReturn(true) |
84 |
| - .when(oclient).isSupported(); |
85 | 77 | KubernetesClient client = mock(KubernetesClient.class);
|
86 |
| - when(client.adapt(OpenShiftClient.class)).thenReturn(oclient); |
| 78 | + when(client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false)).thenReturn(true); |
87 | 79 | // when
|
88 | 80 | boolean isOpenShift = ClusterHelper.isOpenShift(client);
|
89 | 81 | // then
|
90 | 82 | assertThat(isOpenShift).isTrue();
|
91 | 83 | }
|
92 | 84 |
|
93 | 85 | @Test
|
94 |
| - public void isOpenShift_should_return_false_if_isSupported_throws() { |
| 86 | + public void isOpenShift_should_return_false_if_has_not_api_group() { |
95 | 87 | // given
|
96 |
| - OpenShiftClient oclient = mock(OpenShiftClient.class); |
97 |
| - doThrow(KubernetesClientException.class) |
98 |
| - .when(oclient).isSupported(); |
99 | 88 | KubernetesClient client = mock(KubernetesClient.class);
|
100 |
| - when(client.adapt(OpenShiftClient.class)).thenReturn(oclient); |
| 89 | + when(client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false)).thenReturn(false); |
101 | 90 | // when
|
102 | 91 | boolean isOpenShift = ClusterHelper.isOpenShift(client);
|
103 | 92 | // then
|
104 | 93 | assertThat(isOpenShift).isFalse();
|
105 | 94 | }
|
106 |
| - |
107 |
| - @Test |
108 |
| - public void isOpenShift_should_return_true_if_isSupported_throws_unauthorized() { |
109 |
| - // given |
110 |
| - OpenShiftClient oclient = mock(OpenShiftClient.class); |
111 |
| - KubernetesClientException e = new KubernetesClientException("ouch", HttpURLConnection.HTTP_UNAUTHORIZED, null); |
112 |
| - doThrow(e) |
113 |
| - .when(oclient).isSupported(); |
114 |
| - KubernetesClient client = mock(KubernetesClient.class); |
115 |
| - when(client.adapt(OpenShiftClient.class)).thenReturn(oclient); |
116 |
| - // when |
117 |
| - boolean isOpenShift = ClusterHelper.isOpenShift(client); |
118 |
| - // then |
119 |
| - assertThat(isOpenShift).isTrue(); |
120 |
| - } |
121 |
| - |
122 | 95 | }
|
0 commit comments