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

OZG-7037 add getPendingCommands endpoint

parent b30c06a2
Branches
Tags
No related merge requests found
...@@ -2,6 +2,8 @@ package de.ozgcloud.apilib.common.command; ...@@ -2,6 +2,8 @@ package de.ozgcloud.apilib.common.command;
import java.util.List; import java.util.List;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
public interface OzgCloudCommandService { public interface OzgCloudCommandService {
OzgCloudCommand create(OzgCloudCommand commandToCreate); OzgCloudCommand create(OzgCloudCommand commandToCreate);
...@@ -9,4 +11,8 @@ public interface OzgCloudCommandService { ...@@ -9,4 +11,8 @@ public interface OzgCloudCommandService {
OzgCloudCommand createAndWaitUntilDone(OzgCloudCommand commandToCreate); OzgCloudCommand createAndWaitUntilDone(OzgCloudCommand commandToCreate);
List<OzgCloudCommand> addSubCommands(OzgCloudCreateSubCommandsRequest request); List<OzgCloudCommand> addSubCommands(OzgCloudCreateSubCommandsRequest request);
boolean existsPendingCommands(OzgCloudVorgangId vorgangId);
List<OzgCloudCommand> getPendingCommands(OzgCloudVorgangId vorgangId);
} }
...@@ -14,6 +14,7 @@ import de.ozgcloud.common.errorhandling.TechnicalException; ...@@ -14,6 +14,7 @@ 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.GrpcExistsPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcGetCommandRequest; import de.ozgcloud.vorgang.grpc.command.GrpcGetCommandRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.client.inject.GrpcClient; import net.devh.boot.grpc.client.inject.GrpcClient;
...@@ -77,14 +78,23 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { ...@@ -77,14 +78,23 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
} }
public boolean existsPendingCommands(OzgCloudVorgangId vorgangId) { public boolean existsPendingCommands(OzgCloudVorgangId vorgangId) {
var response = getCommandServiceStub().existsPendingCommands(buildHasPendingCommandRequest(vorgangId)); var response = getCommandServiceStub().existsPendingCommands(buildExistsPendingCommandRequest(vorgangId));
return response.getExistsPendingCommands(); return response.getExistsPendingCommands();
} }
GrpcExistsPendingCommandsRequest buildHasPendingCommandRequest(OzgCloudVorgangId vorgangId) { GrpcExistsPendingCommandsRequest buildExistsPendingCommandRequest(OzgCloudVorgangId vorgangId) {
return GrpcExistsPendingCommandsRequest.newBuilder().setVorgangId(vorgangId.toString()).build(); return GrpcExistsPendingCommandsRequest.newBuilder().setVorgangId(vorgangId.toString()).build();
} }
public List<OzgCloudCommand> getPendingCommands(OzgCloudVorgangId vorgangId) {
var response = getCommandServiceStub().getPendingCommands(buildGetPendingCommandRequest(vorgangId));
return response.getCommandList().stream().map(mapper::fromGrpc).toList();
}
GrpcGetPendingCommandsRequest buildGetPendingCommandRequest(OzgCloudVorgangId vorgangId) {
return GrpcGetPendingCommandsRequest.newBuilder().setVorgangId(vorgangId.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.GrpcGetPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsRequest.Builder;
public class GrpcGetPendingCommandsRequestTestFactory {
public static final String VORGAND_ID = OzgCloudVorgangTestFactory.ID.toString();
public static GrpcGetPendingCommandsRequest create() {
return createBuilder().build();
}
public static Builder createBuilder() {
return GrpcGetPendingCommandsRequest.newBuilder()
.setVorgangId(VORGAND_ID);
}
}
...@@ -27,6 +27,8 @@ import de.ozgcloud.vorgang.grpc.command.GrpcCommand; ...@@ -27,6 +27,8 @@ 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.GrpcExistsPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse; import de.ozgcloud.vorgang.grpc.command.GrpcExistsPendingCommandsResponse;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsRequest;
import de.ozgcloud.vorgang.grpc.command.GrpcGetPendingCommandsResponse;
class GrpcOzgCloudCommandServiceTest { class GrpcOzgCloudCommandServiceTest {
...@@ -217,16 +219,16 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -217,16 +219,16 @@ class GrpcOzgCloudCommandServiceTest {
@BeforeEach @BeforeEach
void mock() { void mock() {
doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub(); doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub();
doReturn(request).when(service).buildHasPendingCommandRequest(OzgCloudVorgangTestFactory.ID); doReturn(request).when(service).buildExistsPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
var response = GrpcExistsPendingCommandsResponse.newBuilder().setExistsPendingCommands(true).build(); var response = GrpcExistsPendingCommandsResponse.newBuilder().setExistsPendingCommands(true).build();
when(serviceStubWithInterceptor.existsPendingCommands(any())).thenReturn(response); when(serviceStubWithInterceptor.existsPendingCommands(any())).thenReturn(response);
} }
@Test @Test
void shouldCallBuildHasPendingCommandRequest() { void shouldCallBuildExistsPendingCommandRequest() {
existsPendingCommands(); existsPendingCommands();
verify(service).buildHasPendingCommandRequest(OzgCloudVorgangTestFactory.ID); verify(service).buildExistsPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
} }
@Test @Test
...@@ -260,13 +262,85 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -260,13 +262,85 @@ class GrpcOzgCloudCommandServiceTest {
} }
@Nested @Nested
class TestBuildHasPendingCommandRequest { class TestBuildExistsPendingCommandRequest {
@Test @Test
void shouldReturnRequest() { void shouldReturnRequest() {
var request = service.buildHasPendingCommandRequest(OzgCloudVorgangTestFactory.ID); var request = service.buildExistsPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
assertThat(request).isEqualTo(GrpcExistsPendingCommandsRequestTestFactory.create()); assertThat(request).isEqualTo(GrpcExistsPendingCommandsRequestTestFactory.create());
} }
} }
@Nested
class TestGetPendingCommands {
private final GrpcGetPendingCommandsRequest request = GrpcGetPendingCommandsRequestTestFactory.create();
@Mock
private CommandServiceBlockingStub serviceStubWithInterceptor;
private final GrpcCommand grpcCommand = GrpcCommandTestFactory.create();
private final OzgCloudCommand command = OzgCloudCommandTestFactory.create();
@BeforeEach
void mock() {
doReturn(serviceStubWithInterceptor).when(service).getCommandServiceStub();
doReturn(request).when(service).buildGetPendingCommandRequest(any());
var response = GrpcGetPendingCommandsResponse.newBuilder().addCommand(grpcCommand).build();
when(serviceStubWithInterceptor.getPendingCommands(any())).thenReturn(response);
}
@Test
void shouldCallBuildGetPendingCommandRequest() {
getPendingCommands();
verify(service).buildGetPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
}
@Test
void shouldCallGetCommandServiceStub() {
getPendingCommands();
verify(service).getCommandServiceStub();
}
@Test
void shouldCallServiceStubWithInterceptor() {
getPendingCommands();
verify(serviceStubWithInterceptor).getPendingCommands(request);
}
@Test
void shouldCallMapper() {
getPendingCommands();
verify(mapper).fromGrpc(grpcCommand);
}
@Test
void shouldReturnPendingCommands() {
when(mapper.fromGrpc(grpcCommand)).thenReturn(command);
var result = getPendingCommands();
assertThat(result).containsExactly(command);
}
private List<OzgCloudCommand> getPendingCommands() {
return service.getPendingCommands(OzgCloudVorgangTestFactory.ID);
}
}
@Nested
class TestBuildGetPendingCommandRequest {
@Test
void shouldReturnRequest() {
var request = service.buildGetPendingCommandRequest(OzgCloudVorgangTestFactory.ID);
assertThat(request).isEqualTo(GrpcGetPendingCommandsRequestTestFactory.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