Skip to content

Commit f9caa81

Browse files
committed
remove this commit: linter issues
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent b750e91 commit f9caa81

File tree

6 files changed

+66
-59
lines changed

6 files changed

+66
-59
lines changed

core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.4.0
2+
- **Feature:** Added core wait handler structure which can be used by every service waiter implementation.
3+
14
## v0.3.0
25
- **Feature:** New exception types for better error handling
36
- `AuthenticationException`: New exception for authentication-related failures (token generation, refresh, validation)

core/src/test/java/cloud/stackit/sdk/core/wait/AsyncWaitHandlerTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,28 @@
1414
import org.mockito.Mock;
1515
import org.mockito.MockitoAnnotations;
1616

17-
public class AsyncWaitHandlerTest {
17+
class AsyncWaitHandlerTest {
18+
19+
@Mock private ApiHelper apiClient;
1820

1921
// Helper class for testing
2022
public static class ApiHelper {
2123

22-
private final String response = "APIResponse";
23-
24-
public ApiHelper() {}
24+
private static final String RESPONSE = "APIResponse";
2525

2626
public String callApi() throws ApiException {
27-
return response;
27+
return RESPONSE;
2828
}
2929
}
3030

31-
@Mock private ApiHelper apiClient;
32-
3331
@BeforeEach
3432
public void setUp() {
3533
MockitoAnnotations.openMocks(this);
3634
}
3735

3836
// testWaitHandler just calls the ApiHelper function
39-
public static AsyncActionHandler<Void> testWaitHandler(ApiHelper apiClient) {
37+
@SuppressWarnings("PMD.AvoidRethrowingException")
38+
private static AsyncActionHandler<Void> testWaitHandler(ApiHelper apiClient) {
4039
CheckFunction<AsyncActionResult<Void>> checkFn =
4140
() -> {
4241
try {

examples/resourcemanager/src/main/java/cloud/stackit/sdk/resourcemanager/examples/ResourcemanagerExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ final class ResourcemanagerExample {
2525
private ResourcemanagerExample() {}
2626

2727
@SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidThrowingRawExceptionTypes"})
28-
public static void main(String[] args) throws IOException {
28+
public static void main(String[] args)
29+
throws IOException, ApiException, InterruptedException, ExecutionException {
2930
// Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env
3031
// STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
3132
ResourceManagerApi resourceManagerApi = new ResourceManagerApi();

services/iaas/src/test/java/cloud/stackit/sdk/iaas/api/DefaultApiTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
package cloud.stackit.sdk.iaas;
13+
package cloud.stackit.sdk.iaas.api;
1414

1515
import cloud.stackit.sdk.core.KeyFlowAuthenticator;
1616
import cloud.stackit.sdk.core.auth.SetupAuth;
1717
import cloud.stackit.sdk.core.config.CoreConfiguration;
1818
import cloud.stackit.sdk.core.utils.TestUtils;
19+
import cloud.stackit.sdk.iaas.ApiClient;
1920
import java.io.IOException;
2021
import okhttp3.Authenticator;
2122
import okhttp3.OkHttpClient;

services/resourcemanager/src/test/java/cloud/stackit/sdk/resourcemanager/ResourcemanagerWaitTestmanagerWaitTest.java

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package cloud.stackit.sdk.resourcemanager;
22

3-
import static org.junit.jupiter.api.Assertions.assertNotNull;
4-
import static org.junit.jupiter.api.Assertions.assertThrows;
5-
import static org.junit.jupiter.api.Assertions.assertTrue;
6-
import static org.mockito.Mockito.times;
7-
import static org.mockito.Mockito.verify;
8-
import static org.mockito.Mockito.when;
3+
import static org.junit.jupiter.api.Assertions.*;
4+
import static org.mockito.Mockito.*;
95

106
import cloud.stackit.sdk.core.exception.ApiException;
117
import cloud.stackit.sdk.core.wait.AsyncActionHandler;
@@ -21,11 +17,17 @@
2117
import org.mockito.Mock;
2218
import org.mockito.MockitoAnnotations;
2319

24-
public class ResourcemanagerWaitTestmanagerWaitTest {
20+
/**
21+
* @SuppressWarnings is used here to suppress the PMD.TooManyMethods warning because this class is
22+
* an intentional testing class with many tests.
23+
*/
24+
@SuppressWarnings("PMD.TooManyMethods")
25+
class ResourcemanagerWaitTestmanagerWaitTest {
2526

2627
@Mock private ResourceManagerApi apiClient;
2728

28-
private final String containerId = "my-test-container";
29+
private static final String CONTAINER_ID = "MY_TEST_CONTAINER";
30+
private static final int SECOND_CALL = 1;
2931

3032
@BeforeEach
3133
public void setUp() {
@@ -36,45 +38,45 @@ public void setUp() {
3638
void testCreateProjectSuccess() throws Exception {
3739
// First call returns "CREATING", second call returns "ACTIVE"
3840
GetProjectResponse creatingResponse = new GetProjectResponse();
39-
creatingResponse.setContainerId(containerId);
41+
creatingResponse.setContainerId(CONTAINER_ID);
4042
creatingResponse.setLifecycleState(LifecycleState.CREATING);
4143

4244
GetProjectResponse activeResponse = new GetProjectResponse();
43-
activeResponse.setContainerId(containerId);
45+
activeResponse.setContainerId(CONTAINER_ID);
4446
activeResponse.setLifecycleState(LifecycleState.ACTIVE);
4547

4648
AtomicInteger callCount = new AtomicInteger(0);
47-
when(apiClient.getProject(containerId, false))
49+
when(apiClient.getProject(CONTAINER_ID, false))
4850
.thenAnswer(
4951
invocation -> {
50-
if (callCount.getAndIncrement() < 1) {
52+
if (callCount.getAndIncrement() < SECOND_CALL) {
5153
return creatingResponse;
5254
}
5355
return activeResponse;
5456
});
5557

5658
AsyncActionHandler<GetProjectResponse> handler =
57-
ResourcemanagerWait.createProjectWaitHandler(apiClient, containerId);
59+
ResourcemanagerWait.createProjectWaitHandler(apiClient, CONTAINER_ID);
5860
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
5961
handler.setThrottle(10, TimeUnit.MILLISECONDS);
6062
handler.setTimeout(2, TimeUnit.SECONDS);
6163

6264
GetProjectResponse result = handler.waitWithContextAsync().get();
6365

6466
assertNotNull(result);
65-
verify(apiClient, times(2)).getProject(containerId, false);
67+
verify(apiClient, times(2)).getProject(CONTAINER_ID, false);
6668
}
6769

6870
@Test
6971
void testCreateProjectTimeout() throws Exception {
7072
// Always return "CREATING" to trigger the timeout
7173
GetProjectResponse creatingResponse = new GetProjectResponse();
72-
creatingResponse.setContainerId(containerId);
74+
creatingResponse.setContainerId(CONTAINER_ID);
7375
creatingResponse.setLifecycleState(LifecycleState.CREATING);
74-
when(apiClient.getProject(containerId, false)).thenReturn(creatingResponse);
76+
when(apiClient.getProject(CONTAINER_ID, false)).thenReturn(creatingResponse);
7577

7678
AsyncActionHandler<GetProjectResponse> handler =
77-
ResourcemanagerWait.createProjectWaitHandler(apiClient, containerId);
79+
ResourcemanagerWait.createProjectWaitHandler(apiClient, CONTAINER_ID);
7880
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
7981
handler.setThrottle(10, TimeUnit.MILLISECONDS);
8082
handler.setTimeout(500, TimeUnit.MILLISECONDS);
@@ -89,10 +91,10 @@ void testCreateProjectTimeout() throws Exception {
8991
void testCreateProjectOpenAPIError() throws Exception {
9092
// Trigger API Exception which is not in RetryHttpErrorStatusCodes
9193
ApiException apiException = new ApiException(409, "");
92-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
94+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
9395

9496
AsyncActionHandler<GetProjectResponse> handler =
95-
ResourcemanagerWait.createProjectWaitHandler(apiClient, containerId);
97+
ResourcemanagerWait.createProjectWaitHandler(apiClient, CONTAINER_ID);
9698
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
9799
handler.setThrottle(10, TimeUnit.MILLISECONDS);
98100
handler.setTimeout(100, TimeUnit.MILLISECONDS);
@@ -110,45 +112,45 @@ void testCreateProjectOpenAPIError() throws Exception {
110112
void testUpdateProjectSuccess() throws Exception {
111113
// First call returns "CREATING", second call returns "ACTIVE"
112114
GetProjectResponse updateResponse = new GetProjectResponse();
113-
updateResponse.setContainerId(containerId);
115+
updateResponse.setContainerId(CONTAINER_ID);
114116
updateResponse.setLifecycleState(LifecycleState.CREATING);
115117

116118
GetProjectResponse activeResponse = new GetProjectResponse();
117-
activeResponse.setContainerId(containerId);
119+
activeResponse.setContainerId(CONTAINER_ID);
118120
activeResponse.setLifecycleState(LifecycleState.ACTIVE);
119121

120122
AtomicInteger callCount = new AtomicInteger(0);
121-
when(apiClient.getProject(containerId, false))
123+
when(apiClient.getProject(CONTAINER_ID, false))
122124
.thenAnswer(
123125
invocation -> {
124-
if (callCount.getAndIncrement() < 1) {
126+
if (callCount.getAndIncrement() < SECOND_CALL) {
125127
return updateResponse;
126128
}
127129
return activeResponse;
128130
});
129131

130132
AsyncActionHandler<GetProjectResponse> handler =
131-
ResourcemanagerWait.updateProjectWaitHandler(apiClient, containerId);
133+
ResourcemanagerWait.updateProjectWaitHandler(apiClient, CONTAINER_ID);
132134
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
133135
handler.setThrottle(10, TimeUnit.MILLISECONDS);
134136
handler.setTimeout(2, TimeUnit.SECONDS);
135137

136138
GetProjectResponse result = handler.waitWithContextAsync().get();
137139

138140
assertNotNull(result);
139-
verify(apiClient, times(2)).getProject(containerId, false);
141+
verify(apiClient, times(2)).getProject(CONTAINER_ID, false);
140142
}
141143

142144
@Test
143145
void testUpdateProjectTimeout() throws Exception {
144146
// Always return "CREATING" to trigger the timeout
145147
GetProjectResponse updateResponse = new GetProjectResponse();
146-
updateResponse.setContainerId(containerId);
148+
updateResponse.setContainerId(CONTAINER_ID);
147149
updateResponse.setLifecycleState(LifecycleState.CREATING);
148-
when(apiClient.getProject(containerId, false)).thenReturn(updateResponse);
150+
when(apiClient.getProject(CONTAINER_ID, false)).thenReturn(updateResponse);
149151

150152
AsyncActionHandler<GetProjectResponse> handler =
151-
ResourcemanagerWait.createProjectWaitHandler(apiClient, containerId);
153+
ResourcemanagerWait.createProjectWaitHandler(apiClient, CONTAINER_ID);
152154
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
153155
handler.setThrottle(10, TimeUnit.MILLISECONDS);
154156
handler.setTimeout(500, TimeUnit.MILLISECONDS);
@@ -163,10 +165,10 @@ void testUpdateProjectTimeout() throws Exception {
163165
void testOpenAPIErrorTimeoutBadGateway() throws Exception {
164166
// Trigger API Exception
165167
ApiException apiException = new ApiException(HttpURLConnection.HTTP_BAD_GATEWAY, "");
166-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
168+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
167169

168170
AsyncActionHandler<GetProjectResponse> handler =
169-
ResourcemanagerWait.createProjectWaitHandler(apiClient, containerId);
171+
ResourcemanagerWait.createProjectWaitHandler(apiClient, CONTAINER_ID);
170172
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
171173
handler.setThrottle(10, TimeUnit.MILLISECONDS);
172174
handler.setTimeout(100, TimeUnit.MILLISECONDS);
@@ -185,10 +187,10 @@ void testOpenAPIErrorTimeoutBadGateway() throws Exception {
185187
void testOpenAPIErrorTimeoutGatewayTimeout() throws Exception {
186188
// Trigger API Exception
187189
ApiException apiException = new ApiException(HttpURLConnection.HTTP_GATEWAY_TIMEOUT, "");
188-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
190+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
189191

190192
AsyncActionHandler<GetProjectResponse> handler =
191-
ResourcemanagerWait.createProjectWaitHandler(apiClient, containerId);
193+
ResourcemanagerWait.createProjectWaitHandler(apiClient, CONTAINER_ID);
192194
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
193195
handler.setThrottle(10, TimeUnit.MILLISECONDS);
194196
handler.setTimeout(100, TimeUnit.MILLISECONDS);
@@ -206,73 +208,73 @@ void testOpenAPIErrorTimeoutGatewayTimeout() throws Exception {
206208
void testDeleteProjectSuccessDeleting() throws Exception {
207209
// First call returns "ACTIVE", second call returns "DELETING"
208210
GetProjectResponse activeResponse = new GetProjectResponse();
209-
activeResponse.setContainerId(containerId);
211+
activeResponse.setContainerId(CONTAINER_ID);
210212
activeResponse.setLifecycleState(LifecycleState.ACTIVE);
211213

212214
GetProjectResponse deletingResponse = new GetProjectResponse();
213-
deletingResponse.setContainerId(containerId);
215+
deletingResponse.setContainerId(CONTAINER_ID);
214216
deletingResponse.setLifecycleState(LifecycleState.DELETING);
215217

216218
AtomicInteger callCount = new AtomicInteger(0);
217-
when(apiClient.getProject(containerId, false))
219+
when(apiClient.getProject(CONTAINER_ID, false))
218220
.thenAnswer(
219221
invocation -> {
220-
if (callCount.getAndIncrement() < 1) {
222+
if (callCount.getAndIncrement() < SECOND_CALL) {
221223
return activeResponse;
222224
}
223225
return deletingResponse;
224226
});
225227

226228
AsyncActionHandler<Void> handler =
227-
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, containerId);
229+
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, CONTAINER_ID);
228230
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
229231
handler.setThrottle(10, TimeUnit.MILLISECONDS);
230232
handler.setTimeout(2, TimeUnit.SECONDS);
231233

232234
handler.waitWithContextAsync().get();
233-
verify(apiClient, times(2)).getProject(containerId, false);
235+
verify(apiClient, times(2)).getProject(CONTAINER_ID, false);
234236
}
235237

236238
@Test
237239
void testDeleteProjectSuccessNotFoundExc() throws Exception {
238240
// Trigger API Exception
239241
ApiException apiException = new ApiException(HttpURLConnection.HTTP_NOT_FOUND, "");
240-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
242+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
241243

242244
AsyncActionHandler<Void> handler =
243-
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, containerId);
245+
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, CONTAINER_ID);
244246
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
245247
handler.setThrottle(10, TimeUnit.MILLISECONDS);
246248
handler.setTimeout(2, TimeUnit.SECONDS);
247249
handler.waitWithContextAsync().get();
248250
// Only one invocation since the project is gone (HTTP_NOT_FOUND)
249-
verify(apiClient, times(1)).getProject(containerId, false);
251+
verify(apiClient, times(1)).getProject(CONTAINER_ID, false);
250252
}
251253

252254
@Test
253255
void testDeleteProjectSuccessForbiddenExc() throws Exception {
254256
// Trigger API Exception
255257
ApiException apiException = new ApiException(HttpURLConnection.HTTP_FORBIDDEN, "");
256-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
258+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
257259

258260
AsyncActionHandler<Void> handler =
259-
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, containerId);
261+
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, CONTAINER_ID);
260262
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
261263
handler.setThrottle(10, TimeUnit.MILLISECONDS);
262264
handler.setTimeout(2, TimeUnit.SECONDS);
263265
handler.waitWithContextAsync().get();
264266
// Only one invocation since the project is gone (HTTP_FORBIDDEN)
265-
verify(apiClient, times(1)).getProject(containerId, false);
267+
verify(apiClient, times(1)).getProject(CONTAINER_ID, false);
266268
}
267269

268270
@Test
269271
void testDeleteProjectDifferentErrorCode() throws Exception {
270272
// Trigger API Exception
271273
ApiException apiException = new ApiException(HttpURLConnection.HTTP_ENTITY_TOO_LARGE, "");
272-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
274+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
273275

274276
AsyncActionHandler<Void> handler =
275-
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, containerId);
277+
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, CONTAINER_ID);
276278
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
277279
handler.setThrottle(10, TimeUnit.MILLISECONDS);
278280
handler.setTimeout(100, TimeUnit.MILLISECONDS);
@@ -289,10 +291,10 @@ void testDeleteProjectDifferentErrorCode() throws Exception {
289291
void testOpenAPIErrorGatewayTimeout() throws Exception {
290292
// Trigger API Exception
291293
ApiException apiException = new ApiException(HttpURLConnection.HTTP_GATEWAY_TIMEOUT, "");
292-
when(apiClient.getProject(containerId, false)).thenThrow(apiException);
294+
when(apiClient.getProject(CONTAINER_ID, false)).thenThrow(apiException);
293295

294296
AsyncActionHandler<Void> handler =
295-
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, containerId);
297+
ResourcemanagerWait.deleteProjectWaitHandler(apiClient, CONTAINER_ID);
296298
handler.setSleepBeforeWait(0, TimeUnit.SECONDS);
297299
handler.setThrottle(10, TimeUnit.MILLISECONDS);
298300
handler.setTimeout(100, TimeUnit.MILLISECONDS);

services/resourcemanager/src/test/java/cloud/stackit/sdk/resourcemanager/api/DefaultApiTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
* Do not edit the class manually.
1111
*/
1212

13-
package cloud.stackit.sdk.resourcemanager;
13+
package cloud.stackit.sdk.resourcemanager.api;
1414

1515
import cloud.stackit.sdk.core.KeyFlowAuthenticator;
1616
import cloud.stackit.sdk.core.auth.SetupAuth;
1717
import cloud.stackit.sdk.core.config.CoreConfiguration;
1818
import cloud.stackit.sdk.core.utils.TestUtils;
19+
import cloud.stackit.sdk.resourcemanager.ApiClient;
1920
import java.io.IOException;
2021
import okhttp3.Authenticator;
2122
import okhttp3.OkHttpClient;

0 commit comments

Comments
 (0)