Skip to content
Snippets Groups Projects
Commit a5301275 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4392 [refactor] outsource command verification

parent fdbc71dc
No related branches found
No related tags found
No related merge requests found
...@@ -50,9 +50,7 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { ...@@ -50,9 +50,7 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
} }
} }
} }
if (hasErrorStatus(command)) { verifyCommand(command);
throw new TechnicalException("Command (id=%s) failed: %s".formatted(command.getId(), command.getErrorMessage()));
}
return command; return command;
} }
...@@ -65,7 +63,9 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { ...@@ -65,7 +63,9 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
return commandServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider)); return commandServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider));
} }
boolean hasErrorStatus(OzgCloudCommand command) { void verifyCommand(OzgCloudCommand command) {
return command.getStatus() == OzgCloudCommandStatus.ERROR; if (command.getStatus() == OzgCloudCommandStatus.ERROR) {
throw new TechnicalException("Command (id=%s) failed: %s".formatted(command.getId(), command.getErrorMessage()));
}
} }
} }
package de.ozgcloud.apilib.common.command.grpc; package de.ozgcloud.apilib.common.command.grpc;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -68,10 +69,10 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -68,10 +69,10 @@ class GrpcOzgCloudCommandServiceTest {
} }
@Test @Test
void shouldThrowException() { void shouldCallVerifyCommand() {
var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build(); service.waitUntilDone(command);
Assertions.assertThrows(TechnicalException.class, () -> service.waitUntilDone(command)); verify(service).verifyCommand(command);
} }
@Nested @Nested
...@@ -123,12 +124,10 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -123,12 +124,10 @@ class GrpcOzgCloudCommandServiceTest {
class TestStatus { class TestStatus {
@Test @Test
void shouldReturnTrueByError() { void shouldThrowException() {
var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build(); var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build();
var result = service.hasErrorStatus(command); assertThrows(TechnicalException.class, () -> service.verifyCommand(command));
assertThat(result).isTrue();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment