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