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

OZG-7037 add hasPendingCommands to GrpcOzgCloudCommandService

parent e69428ee
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,10 @@ import de.ozgcloud.apilib.common.command.OzgCloudCommandId; ...@@ -9,8 +9,10 @@ import de.ozgcloud.apilib.common.command.OzgCloudCommandId;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService; import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.OzgCloudCommandStatus; import de.ozgcloud.apilib.common.command.OzgCloudCommandStatus;
import de.ozgcloud.apilib.common.command.OzgCloudCreateSubCommandsRequest; import de.ozgcloud.apilib.common.command.OzgCloudCreateSubCommandsRequest;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.vorgang.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub; import de.ozgcloud.vorgang.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcGetCommandRequest; import de.ozgcloud.vorgang.grpc.command.GrpcGetCommandRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.client.inject.GrpcClient; import net.devh.boot.grpc.client.inject.GrpcClient;
...@@ -74,7 +76,17 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { ...@@ -74,7 +76,17 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
return response.getCommandList().stream().map(mapper::fromGrpc).toList(); return response.getCommandList().stream().map(mapper::fromGrpc).toList();
} }
public boolean hasPendingCommands(OzgCloudVorgangId vorgangId) {
var response = getCommandServiceStub().existsPendingCommands(buildHasPendingCommandRequest(vorgangId));
return response.getExistsPendingCommands();
}
GrpcExistsPendingCommandsRequest buildHasPendingCommandRequest(OzgCloudVorgangId id) {
return GrpcExistsPendingCommandsRequest.newBuilder().setVorgangId(id.toString()).build();
}
CommandServiceBlockingStub getCommandServiceStub() { CommandServiceBlockingStub getCommandServiceStub() {
return commandServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider)); return commandServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider));
} }
} }
package de.ozgcloud.apilib.common.command.grpc;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangTestFactory;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsRequest.Builder;
public class GrpcExistsPendingCommandsRequestTestFactory {
public static final String VORGAND_ID = OzgCloudVorgangTestFactory.ID.toString();
public static GrpcExistsPendingCommandsRequest create() {
return createBuilder().build();
}
public static Builder createBuilder() {
return GrpcExistsPendingCommandsRequest.newBuilder()
.setVorgangId(VORGAND_ID);
}
}
...@@ -10,6 +10,8 @@ import java.util.List; ...@@ -10,6 +10,8 @@ import java.util.List;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
...@@ -17,11 +19,14 @@ import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider; ...@@ -17,11 +19,14 @@ import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider;
import de.ozgcloud.apilib.common.command.OzgCloudCommand; import de.ozgcloud.apilib.common.command.OzgCloudCommand;
import de.ozgcloud.apilib.common.command.OzgCloudCommandStatus; import de.ozgcloud.apilib.common.command.OzgCloudCommandStatus;
import de.ozgcloud.apilib.common.command.OzgCloudCreateSubCommandsRequestTestFactory; import de.ozgcloud.apilib.common.command.OzgCloudCreateSubCommandsRequestTestFactory;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangTestFactory;
import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.vorgang.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub; import de.ozgcloud.vorgang.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub;
import de.ozgcloud.vorgang.grpc.command.GrpcAddSubCommandsRequest; import de.ozgcloud.vorgang.grpc.command.GrpcAddSubCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcCommand; import de.ozgcloud.vorgang.grpc.command.GrpcCommand;
import de.ozgcloud.vorgang.grpc.command.GrpcCommandsResponse; import de.ozgcloud.vorgang.grpc.command.GrpcCommandsResponse;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse;
class GrpcOzgCloudCommandServiceTest { class GrpcOzgCloudCommandServiceTest {
...@@ -200,4 +205,68 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -200,4 +205,68 @@ class GrpcOzgCloudCommandServiceTest {
return service.addSubCommands(OzgCloudCreateSubCommandsRequestTestFactory.create()); return service.addSubCommands(OzgCloudCreateSubCommandsRequestTestFactory.create());
} }
} }
@Nested
class TestHasPendingCommands {
private final GrpcExistsPendingCommandsRequest request = GrpcExistsPendingCommandsRequestTestFactory.create();
@Mock
private CommandServiceBlockingStub serviceStubWithInterceptor;
@BeforeEach
void mock() {
doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub();
doReturn(request).when(service).buildHasPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
var response = GrpcExistsPendingCommandsResponse.newBuilder().setExistsPendingCommands(true).build();
when(serviceStubWithInterceptor.existsPendingCommands(any())).thenReturn(response);
}
@Test
void shouldCallBuildHasPendingCommandRequest() {
hasPendingCommands();
verify(service).buildHasPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
}
@Test
void shouldCallGetCommandServiceStub() {
hasPendingCommands();
verify(service).getCommandServiceStub();
}
@Test
void shouldCallServiceStubWithInterceptor() {
hasPendingCommands();
verify(serviceStubWithInterceptor).existsPendingCommands(request);
}
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldReturnIfCommandsArePending(boolean hasPendingCommands) {
var response = GrpcExistsPendingCommandsResponse.newBuilder().setExistsPendingCommands(hasPendingCommands).build();
when(serviceStubWithInterceptor.existsPendingCommands(any())).thenReturn(response);
var result = hasPendingCommands();
assertThat(result).isEqualTo(hasPendingCommands);
}
private boolean hasPendingCommands() {
return service.hasPendingCommands(OzgCloudVorgangTestFactory.ID);
}
}
@Nested
class TestBuildHasPendingCommandRequest {
@Test
void shouldReturnRequest() {
var request = service.buildHasPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
assertThat(request).isEqualTo(GrpcExistsPendingCommandsRequestTestFactory.create());
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment