diff --git a/goofy-server/src/main/java/de/itvsh/goofy/binary/BinaryController.java b/goofy-server/src/main/java/de/itvsh/goofy/binary/BinaryController.java new file mode 100644 index 0000000000000000000000000000000000000000..020451107b81fc19576c1f4085d4c54a2dedd630 --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/binary/BinaryController.java @@ -0,0 +1,19 @@ +package de.itvsh.goofy.binary; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(BinaryController.FILE_PATH) +public class BinaryController { + + public static final String FILE_PATH = "/api/binary"; // NOSONAR + + @GetMapping("/{fileId}") + public ResponseEntity<org.springframework.core.io.Resource> download(@PathVariable String fileId) { + return null; + } +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/attachment/AttachmentController.java b/goofy-server/src/main/java/de/itvsh/goofy/file/AttachmentController.java similarity index 71% rename from goofy-server/src/main/java/de/itvsh/goofy/attachment/AttachmentController.java rename to goofy-server/src/main/java/de/itvsh/goofy/file/AttachmentController.java index 61a21483744a68ba3eceda5aec301cc3127a02a2..5a74cdc0a5e6ccf5281b5709718a161531fd4aa6 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/attachment/AttachmentController.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/AttachmentController.java @@ -1,5 +1,6 @@ -package de.itvsh.goofy.attachment; +package de.itvsh.goofy.file; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.EntityModel; import org.springframework.web.bind.annotation.GetMapping; @@ -7,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import de.itvsh.goofy.file.File; - @RestController @RequestMapping(AttachmentController.ATTACHMENT_PATH) public class AttachmentController { @@ -17,8 +16,13 @@ public class AttachmentController { static final String PARAM_EINGANG_ID = "eingangId"; + @Autowired + private FileService fileService; + @Autowired + private FileModelAssembler modelAssembler; + @GetMapping(params = PARAM_EINGANG_ID) public CollectionModel<EntityModel<File>> getAllByEingang(@RequestParam String eingangId) { - return CollectionModel.empty(); + return modelAssembler.toCollectionModel(fileService.getAttachmentsByEingang(eingangId)); } } \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/file/File.java b/goofy-server/src/main/java/de/itvsh/goofy/file/File.java new file mode 100644 index 0000000000000000000000000000000000000000..cfc131318c7c46068995c531fb7bce2032a3d9e1 --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/File.java @@ -0,0 +1,19 @@ +package de.itvsh.goofy.file; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PACKAGE) +@Getter +public class File { + + private String id; + private String name; + private long size; + +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/file/FileController.java b/goofy-server/src/main/java/de/itvsh/goofy/file/FileController.java new file mode 100644 index 0000000000000000000000000000000000000000..4ddd1c29bc3d710e79dc7dbefbfbd40d833c8d50 --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/FileController.java @@ -0,0 +1,17 @@ +package de.itvsh.goofy.file; + +import org.springframework.hateoas.EntityModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +@RestController(FileController.FILE_PATH) +public class FileController { + + static final String FILE_PATH = "/api/files"; // NOSONAR + + @GetMapping("{fileId}") + public EntityModel<File> getFileData(@PathVariable String fileId) { + return null; + } +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/file/FileMapper.java b/goofy-server/src/main/java/de/itvsh/goofy/file/FileMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..8defdaddbce46aea1a625f6b5727dbc3c465b69b --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/FileMapper.java @@ -0,0 +1,11 @@ +package de.itvsh.goofy.file; + +import org.mapstruct.Mapper; + +import de.itvsh.ozg.pluto.grpc.file.GrpcFile; + +@Mapper +interface FileMapper { + + File toEingang(GrpcFile file); +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/file/FileModelAssembler.java b/goofy-server/src/main/java/de/itvsh/goofy/file/FileModelAssembler.java new file mode 100644 index 0000000000000000000000000000000000000000..d64b33869e910684915d00d543ac05fd02a377fa --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/FileModelAssembler.java @@ -0,0 +1,35 @@ +package de.itvsh.goofy.file; + +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.springframework.hateoas.CollectionModel; +import org.springframework.hateoas.EntityModel; +import org.springframework.hateoas.LinkRelation; +import org.springframework.hateoas.server.RepresentationModelAssembler; +import org.springframework.stereotype.Component; + +import de.itvsh.goofy.binary.BinaryController; +import de.itvsh.goofy.common.ResourceBuilder; + +@Component +class FileModelAssembler implements RepresentationModelAssembler<File, EntityModel<File>> { + + static final LinkRelation REL_DOWNLOAD = LinkRelation.of("download"); + + @Override + public EntityModel<File> toModel(File file) { + var selfLink = linkTo(FileController.class).slash(file.getId()); + + return ResourceBuilder.fromEntity(file).addLink(selfLink.withSelfRel()) + .addLink(linkTo(BinaryController.class).slash(file.getId()).withRel(REL_DOWNLOAD)) + .buildResource(); + } + + public CollectionModel<EntityModel<File>> toCollectionModel(Stream<File> entities) { + return CollectionModel.of(entities.map(this::toModel).collect(Collectors.toList()), + linkTo(FileController.class).withSelfRel()); + } +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/file/FileRemoteService.java b/goofy-server/src/main/java/de/itvsh/goofy/file/FileRemoteService.java new file mode 100644 index 0000000000000000000000000000000000000000..80eec073358e93526b6108f0a9480ad3cfe85160 --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/FileRemoteService.java @@ -0,0 +1,37 @@ +package de.itvsh.goofy.file; + +import java.util.UUID; +import java.util.stream.Stream; + +import org.springframework.stereotype.Service; + +import com.thedeanda.lorem.LoremIpsum; + +import de.itvsh.ozg.pluto.grpc.file.FileServiceGrpc.FileServiceBlockingStub; +import net.devh.boot.grpc.client.inject.GrpcClient; + +@Service +public class FileRemoteService { + + @GrpcClient("pluto") + private FileServiceBlockingStub fileServiceStub; +// @Autowired +// private ContextService contextService; +// @Autowired +// private FileMapper fileMapper; + + public Stream<File> getAttachmentsByEingang(String eingangId) { + // TODO an Pluto ankabeln +// GrpcGetAttachmentsResponse response = fileServiceStub.getAttachments(buildGrpcGetAttachmentsRequest(eingangId)); +// +// return response.getFileList().stream().map(fileMapper::toEingang); + return Stream.of(File.builder().id(UUID.randomUUID().toString()).name(LoremIpsum.getInstance().getName()).size(1024).build()); + } + +// private GrpcGetAttachmentsRequest buildGrpcGetAttachmentsRequest(String eingangId) { +// return GrpcGetAttachmentsRequest.newBuilder() +// .setContext(contextService.createCallContext()) +// .setEingangId(eingangId) +// .build(); +// } +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/file/FileService.java b/goofy-server/src/main/java/de/itvsh/goofy/file/FileService.java new file mode 100644 index 0000000000000000000000000000000000000000..7879b1b0bff87013ec786d98c219c7030642e7fd --- /dev/null +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/FileService.java @@ -0,0 +1,17 @@ +package de.itvsh.goofy.file; + +import java.util.stream.Stream; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class FileService { + + @Autowired + private FileRemoteService remoteService; + + public Stream<File> getAttachmentsByEingang(String eingangId) { + return remoteService.getAttachmentsByEingang(eingangId); + } +} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/representation/RepresentationController.java b/goofy-server/src/main/java/de/itvsh/goofy/file/RepresentationController.java similarity index 91% rename from goofy-server/src/main/java/de/itvsh/goofy/representation/RepresentationController.java rename to goofy-server/src/main/java/de/itvsh/goofy/file/RepresentationController.java index abd2f2a68b1158bc3997bec35843dffea2f59886..bccab7782b537768474cda60c76fedd29d130880 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/representation/RepresentationController.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/file/RepresentationController.java @@ -1,4 +1,4 @@ -package de.itvsh.goofy.representation; +package de.itvsh.goofy.file; import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.EntityModel; @@ -7,8 +7,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import de.itvsh.goofy.file.File; - @RestController @RequestMapping(RepresentationController.REPRESENTATIONS_PATH) public class RepresentationController { diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangModelAssembler.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangModelAssembler.java index 910d304d012dba315a5aca8b1bd0aaa923ecdf3d..1ab6c2b82c13699ea10ec18a0bd80a9afdb0d4bd 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangModelAssembler.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangModelAssembler.java @@ -13,10 +13,10 @@ import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.server.RepresentationModelAssembler; import org.springframework.stereotype.Component; -import de.itvsh.goofy.attachment.AttachmentController; import de.itvsh.goofy.common.ResourceBuilder; import de.itvsh.goofy.common.command.CommandController; -import de.itvsh.goofy.representation.RepresentationController; +import de.itvsh.goofy.file.AttachmentController; +import de.itvsh.goofy.file.RepresentationController; import de.itvsh.goofy.wiedervorlage.WiedervorlageCommandController.WiedervorlageCommandByVorgangController; import de.itvsh.goofy.wiedervorlage.WiedervorlageController.WiedervorlageByVorgangController; diff --git a/goofy-server/src/test/java/de/itvsh/goofy/attachment/AttachmentControllerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/binary/BinaryControllerTest.java similarity index 67% rename from goofy-server/src/test/java/de/itvsh/goofy/attachment/AttachmentControllerTest.java rename to goofy-server/src/test/java/de/itvsh/goofy/binary/BinaryControllerTest.java index fec2cbc008b92c9f1c8d9a9e2545e2f1fe2761b8..decfa6ffbdfcee86e95028354559795f632da7c1 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/attachment/AttachmentControllerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/binary/BinaryControllerTest.java @@ -1,4 +1,4 @@ -package de.itvsh.goofy.attachment; +package de.itvsh.goofy.binary; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -10,22 +10,24 @@ import org.mockito.InjectMocks; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -class AttachmentControllerTest { +import de.itvsh.goofy.file.FileTestFactory; - private final String PATH = AttachmentController.ATTACHMENT_PATH; +class BinaryControllerTest { + + private final String PATH = BinaryController.FILE_PATH + "/"; @InjectMocks - private AttachmentController controller; + private BinaryController controller; private MockMvc mockMvc; @BeforeEach - void initTest() { + void init() { mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); } @Nested - class TestGetAttachmentsByEingang { + class TestDownload { @Test void shouldCallEndpoint() throws Exception { @@ -33,7 +35,7 @@ class AttachmentControllerTest { } private void callEndpoint() throws Exception { - mockMvc.perform(get(PATH).param(AttachmentController.PARAM_EINGANG_ID, "1")).andExpect(status().isOk()); + mockMvc.perform(get(PATH + FileTestFactory.ID)).andExpect(status().isOk()); } } } \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/common/GrpcCallContextTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/common/GrpcCallContextTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..dceabe235dcb352c3eb7d862a8ee7de9cd171f2d --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/common/GrpcCallContextTestFactory.java @@ -0,0 +1,21 @@ +package de.itvsh.goofy.common; + +import de.itvsh.goofy.common.user.GrpcUserTestFactory; +import de.itvsh.ozg.pluto.grpc.command.GrpcCallContext; +import de.itvsh.ozg.pluto.grpc.command.GrpcUser; + +public class GrpcCallContextTestFactory { + + private static final GrpcUser USER = GrpcUserTestFactory.create(); + public static final String CLIENT = "testGoofyClient"; + + public static GrpcCallContext create() { + return createBuilder().build(); + } + + public static GrpcCallContext.Builder createBuilder() { + return GrpcCallContext.newBuilder() + .setUser(USER) + .setClient(CLIENT); + } +} diff --git a/goofy-server/src/test/java/de/itvsh/goofy/common/user/GrpcUserTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/common/user/GrpcUserTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..61a9749bf0b238b02af0005c9b039a878bcfd835 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/common/user/GrpcUserTestFactory.java @@ -0,0 +1,24 @@ +package de.itvsh.goofy.common.user; + +import java.util.Collections; +import java.util.UUID; + +import de.itvsh.ozg.pluto.grpc.command.GrpcUser; + +public class GrpcUserTestFactory { + + public static final String ID = UUID.randomUUID().toString(); + public static final String NAME = UserTestFactory.FULLNAME; + public static final String ROLE = UserTestFactory.ROLE; + + public static GrpcUser create() { + return createBuilder().build(); + } + + public static GrpcUser.Builder createBuilder() { + return GrpcUser.newBuilder() + .setId(ID) + .setName(NAME) + .addAllRoles(Collections.singleton(ROLE)); + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/AttachmentControllerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/file/AttachmentControllerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8e532b0b23f5d0575551a1c8056731edff307751 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/AttachmentControllerTest.java @@ -0,0 +1,68 @@ +package de.itvsh.goofy.file; + +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +class AttachmentControllerTest { + + private final String PATH = AttachmentController.ATTACHMENT_PATH; + + @InjectMocks + private AttachmentController controller; + @Mock + private FileModelAssembler modelAssembler; + @Mock + private FileService fileService; + + private MockMvc mockMvc; + + @BeforeEach + void initTest() { + mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); + } + + @Nested + class TestGetAttachmentsByEingang { + + @BeforeEach + void mockFileService() { + when(fileService.getAttachmentsByEingang(anyString())).thenReturn(Stream.of(FileTestFactory.create())); + } + + @Test + void shouldCallEndpoint() throws Exception { + callEndpoint(); + } + + @Test + void shoudlCallFileService() throws Exception { + callEndpoint(); + + verify(fileService).getAttachmentsByEingang(any()); + } + + @SuppressWarnings("unchecked") + @Test + void shouldCallModelAssembler() throws Exception { + callEndpoint(); + + verify(modelAssembler).toCollectionModel(any(Stream.class)); + } + + private void callEndpoint() throws Exception { + mockMvc.perform(get(PATH).param(AttachmentController.PARAM_EINGANG_ID, "1")).andExpect(status().isOk()); + } + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/FileModelAssemblerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/file/FileModelAssemblerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c75cd51a6da5037a7a7adb21d6d124b78c3aa032 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/FileModelAssemblerTest.java @@ -0,0 +1,32 @@ +package de.itvsh.goofy.file; + +import static org.assertj.core.api.Assertions.*; + +import java.util.Optional; + +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.hateoas.Link; +import org.springframework.hateoas.LinkRelation; +import org.springframework.hateoas.server.EntityLinks; + +class FileModelAssemblerTest { + + @InjectMocks + private FileModelAssembler modelAssembler; + @Mock + private EntityLinks entityLinks; + + @Test + void shouldHaveDownloadLink() throws Exception { + var link = getLinkFromModel(FileTestFactory.create(), FileModelAssembler.REL_DOWNLOAD); + + assertThat(link).isPresent(); + assertThat(link.get().getHref()).isEqualTo("/api/binary/" + FileTestFactory.ID); + } + + private Optional<Link> getLinkFromModel(File file, LinkRelation linkRel) { + return modelAssembler.toModel(file).getLink(linkRel); + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/FileRemoteServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/file/FileRemoteServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e0b756c40f2cd20e1b8a5766ee7e94d55ad5e449 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/FileRemoteServiceTest.java @@ -0,0 +1,77 @@ +package de.itvsh.goofy.file; + +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import de.itvsh.goofy.common.ContextService; +import de.itvsh.goofy.common.GrpcCallContextTestFactory; +import de.itvsh.goofy.vorgang.EingangTestFactory; +import de.itvsh.ozg.pluto.grpc.command.GrpcCallContext; +import de.itvsh.ozg.pluto.grpc.file.FileServiceGrpc.FileServiceBlockingStub; +import de.itvsh.ozg.pluto.grpc.file.GrpcGetAttachmentsResponse; + +class FileRemoteServiceTest { + + @InjectMocks + private FileRemoteService remoteService; + @Mock + private FileServiceBlockingStub serviceStub; + @Mock + private FileMapper mapper; + @Mock + private ContextService contextService; + + @Disabled("TODO Einkommentieren, wenn Pluto angekabelt ist") + @Nested + class TestGetAttachmentsByEingang { + + private final GrpcGetAttachmentsResponse response = GrpcGetAttachmentsResponseTestFactory.create(); + private GrpcCallContext callContext = GrpcCallContextTestFactory.create(); + + @BeforeEach + void mock() { + when(serviceStub.getAttachments(any())).thenReturn(response); + when(contextService.createCallContext()).thenReturn(callContext); + } + + @Test + void shouldCallContextService() { + doServiceCall(); + + verify(contextService).createCallContext(); + } + + @Test + void shouldCallFileStub() { + doServiceCall(); + + verify(serviceStub).getAttachments(any()); + } + + @Test + void shouldCallMapper() { + var fileStream = remoteService.getAttachmentsByEingang(EingangTestFactory.ID); + fileStream = forceActionsDone(fileStream); + + verify(mapper).toEingang(GrpcFileTestFactory.create()); + } + + private Stream<File> forceActionsDone(Stream<File> stream) { + return stream.collect(Collectors.toList()).stream(); + } + + private void doServiceCall() { + remoteService.getAttachmentsByEingang(EingangTestFactory.ID); + } + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/FileServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/file/FileServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..821f0104c8a8c610d956ee6dfc43d5fe08424955 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/FileServiceTest.java @@ -0,0 +1,29 @@ +package de.itvsh.goofy.file; + +import static org.mockito.Mockito.*; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import de.itvsh.goofy.vorgang.EingangTestFactory; + +class FileServiceTest { + + @InjectMocks + private FileService service; + @Mock + private FileRemoteService remoteService; + + @Nested + class TestGetAttachmentsByEingang { + + @Test + void shouldCallRemoteService() { + service.getAttachmentsByEingang(EingangTestFactory.ID); + + verify(remoteService).getAttachmentsByEingang(EingangTestFactory.ID); + } + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/FileTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/file/FileTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..2943b1bc1d054cad51e9123b7e24d6cedeeb8b0e --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/FileTestFactory.java @@ -0,0 +1,21 @@ +package de.itvsh.goofy.file; + +import java.util.UUID; + +import com.thedeanda.lorem.LoremIpsum; + +public class FileTestFactory { + + public static final String ID = UUID.randomUUID().toString(); + public static final String NAME = LoremIpsum.getInstance().getName(); + + public static File create() { + return createBuilder().build(); + } + + public static File.FileBuilder createBuilder() { + return File.builder() + .id(ID) + .name(NAME); + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/GrpcFileTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/file/GrpcFileTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..079dcec1954683c2aec5058ea7aa611408d84271 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/GrpcFileTestFactory.java @@ -0,0 +1,21 @@ +package de.itvsh.goofy.file; + +import java.util.UUID; + +import de.itvsh.ozg.pluto.grpc.file.GrpcFile; + +public class GrpcFileTestFactory { + + static final String ID = UUID.randomUUID().toString(); + static final String NAME = FileTestFactory.NAME; + + public static GrpcFile create() { + return createBuilder().build(); + } + + public static GrpcFile.Builder createBuilder() { + return GrpcFile.newBuilder() + .setId(ID) + .setName(NAME); + } +} diff --git a/goofy-server/src/test/java/de/itvsh/goofy/file/GrpcGetAttachmentsResponseTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/file/GrpcGetAttachmentsResponseTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..3662b4999bde5a48131947fa4dc79aef9e96abbd --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/GrpcGetAttachmentsResponseTestFactory.java @@ -0,0 +1,20 @@ +package de.itvsh.goofy.file; + +import java.util.Collections; + +import de.itvsh.ozg.pluto.grpc.file.GrpcFile; +import de.itvsh.ozg.pluto.grpc.file.GrpcGetAttachmentsResponse; + +public class GrpcGetAttachmentsResponseTestFactory { + + private static GrpcFile GRPC_FILE = GrpcFileTestFactory.create(); + + public static GrpcGetAttachmentsResponse create() { + return createBuilder().build(); + } + + public static GrpcGetAttachmentsResponse.Builder createBuilder() { + return GrpcGetAttachmentsResponse.newBuilder() + .addAllFile(Collections.singleton(GRPC_FILE)); + } +} \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/representation/RepresentationControllerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/file/RepresentationControllerTest.java similarity index 96% rename from goofy-server/src/test/java/de/itvsh/goofy/representation/RepresentationControllerTest.java rename to goofy-server/src/test/java/de/itvsh/goofy/file/RepresentationControllerTest.java index fd3761252df21ea66561e61a375ce3648053ca22..a3ffc25666f79b33fc92f484a5a6dab6986906a0 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/representation/RepresentationControllerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/file/RepresentationControllerTest.java @@ -1,4 +1,4 @@ -package de.itvsh.goofy.representation; +package de.itvsh.goofy.file; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;