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

OZG-5323 implement comments from code review

parent 32e7012f
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ import de.ozgcloud.vorgang.common.grpc.GrpcObjectMapper;
import de.ozgcloud.vorgang.vorgangAttachedItem.GrpcVorgangAttachedItem;
@Mapper(uses = { GrpcObjectMapper.class})
public interface AttachedItemMapper {
interface AttachedItemMapper {
AttachedItem mapFromVorgangAttachedItem(GrpcVorgangAttachedItem item);
......
......@@ -20,6 +20,7 @@ import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEventTestFactory;
import de.ozgcloud.command.CommandTestFactory;
import de.ozgcloud.common.test.ITCase;
import de.ozgcloud.vorgang.vorgangAttachedItem.VorgangAttachedItemServiceGrpc.VorgangAttachedItemServiceBlockingStub;
@ITCase
class BescheidEventListenerITCase {
......@@ -37,6 +38,8 @@ class BescheidEventListenerITCase {
private CommandMapper commandMapper;
@MockBean
private AttachedItemService attachedItemService;
@MockBean
private VorgangAttachedItemServiceBlockingStub serviceStub;
@Mock
private UserProfile userProfile;
......
......@@ -727,4 +727,25 @@ class AttachedItemServiceTest {
}
}
@Nested
class TestGetItem {
@Test
void shouldCallRemoteService() {
service.getItem(BescheidItemTestFactory.ID);
verify(service).getItem(BescheidItemTestFactory.ID);
}
@Test
void shouldReturnValue() {
var expectedItem = AttachedItemTestFactory.createDocument();
doReturn(expectedItem).when(remoteService).getItem(any());
var result = service.getItem(BescheidItemTestFactory.ID);
assertThat(result).isEqualTo(expectedItem);
}
}
}
\ No newline at end of file
......@@ -67,6 +67,8 @@ class VorgangAttachedItemRemoteServiceTest {
private ClientInterceptor bescheidCallContextInterceptor;
@Mock
private BescheidItemMapper bescheidItemMapper;
@Mock
private AttachedItemMapper attachedItemMapper;
@Nested
class TestFindBescheidDraft {
......@@ -320,6 +322,82 @@ class VorgangAttachedItemRemoteServiceTest {
}
}
@Nested
class TestGetItem {
@Mock
private GrpcVorgangAttachedItemRequest grpcVorgangAttachedItemRequest;
@Mock
private GrpcVorgangAttachedItemResponse grpcVorgangAttachedItemResponse;
@Mock
private GrpcVorgangAttachedItem grpcVorgangAttachedItem;
@BeforeEach
void init() {
when(serviceStub.getById(any())).thenReturn(grpcVorgangAttachedItemResponse);
doReturn(serviceStub).when(service).getServiceStub();
}
@Test
void shouldCallGetServiceStab() {
when(grpcVorgangAttachedItemResponse.getVorgangAttachedItem()).thenReturn(grpcVorgangAttachedItem);
getItem();
verify(service).getServiceStub();
}
@Test
void shouldCallBuildRequest() {
when(grpcVorgangAttachedItemResponse.getVorgangAttachedItem()).thenReturn(grpcVorgangAttachedItem);
getItem();
verify(service).buildGetByIdRequest(AttachedItemTestFactory.ID);
}
@Test
void shouldCallGetById() {
when(grpcVorgangAttachedItemResponse.getVorgangAttachedItem()).thenReturn(grpcVorgangAttachedItem);
doReturn(grpcVorgangAttachedItemRequest).when(service).buildGetByIdRequest(any());
getItem();
verify(serviceStub).getById(grpcVorgangAttachedItemRequest);
}
@Test
void shouldCallMapper() {
when(grpcVorgangAttachedItemResponse.getVorgangAttachedItem()).thenReturn(grpcVorgangAttachedItem);
getItem();
verify(attachedItemMapper).mapFromVorgangAttachedItem(grpcVorgangAttachedItem);
}
@Test
void shouldReturnFoundBescheid() {
var expectedItem = AttachedItemTestFactory.createDocument();
when(attachedItemMapper.mapFromVorgangAttachedItem(any())).thenReturn(expectedItem);
when(grpcVorgangAttachedItemResponse.getVorgangAttachedItem()).thenReturn(grpcVorgangAttachedItem);
var result = getItem();
assertThat(result).isEqualTo(expectedItem);
}
@Test
void shouldThrowExceptionIfNotFound() {
when(serviceStub.getById(any())).thenThrow(StatusRuntimeException.class);
assertThrows(StatusRuntimeException.class, this::getItem);
}
private AttachedItem getItem() {
return service.getItem(BescheidItemTestFactory.ID);
}
}
@Nested
class TestBuildGetByIdRequest {
......
......@@ -13,6 +13,7 @@ import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.grpc.CommandMapper;
import de.ozgcloud.bescheid.BescheidTestFactory;
import de.ozgcloud.common.test.ITCase;
import de.ozgcloud.vorgang.vorgangAttachedItem.VorgangAttachedItemServiceGrpc.VorgangAttachedItemServiceBlockingStub;
@ITCase
class NachrichtServiceITCase {
......@@ -23,6 +24,8 @@ class NachrichtServiceITCase {
private OzgCloudCommandService commandService;
@MockBean
private CommandMapper commandMapper;
@MockBean
private VorgangAttachedItemServiceBlockingStub serviceStub;
@Nested
class TestBuildMessage {
......
......@@ -44,6 +44,7 @@ import de.ozgcloud.apilib.common.datatypes.GenericId;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor;
import de.ozgcloud.bescheid.attacheditem.AttachedItemService;
import de.ozgcloud.bescheid.attacheditem.AttachedItemTestFactory;
import de.ozgcloud.bescheid.attacheditem.BescheidItem;
import de.ozgcloud.bescheid.attacheditem.BescheidItemTestFactory;
import de.ozgcloud.command.Command;
......@@ -65,6 +66,8 @@ class DocumentServiceTest {
private CommandMapper commandMapper;
@Mock
private AttachedItemService attachedItemService;
@Mock
private DocumentMapper documentMapper;
private Command command = CommandTestFactory.createBuilder()
.relationId(RELATION_ID)
......@@ -293,4 +296,34 @@ class DocumentServiceTest {
}
}
@Nested
class TestGetDocument {
@Test
void shouldCallAttachedItemService() {
service.getDocument(AttachedItemTestFactory.ID);
verify(attachedItemService).getItem(AttachedItemTestFactory.ID);
}
@Test
void shouldCallDocumentMapper() {
var expectedItem = AttachedItemTestFactory.createDocument();
when(attachedItemService.getItem(any())).thenReturn(expectedItem);
service.getDocument(AttachedItemTestFactory.ID);
verify(documentMapper).fromAttacheItem(expectedItem);
}
@Test
void shouldReturnDocument() {
var expectedDocument = DocumentTestFactory.create();
when(documentMapper.fromAttacheItem(any())).thenReturn(expectedDocument);
Document document = service.getDocument(AttachedItemTestFactory.ID);
assertThat(document).isEqualTo(expectedDocument);
}
}
}
\ 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