From ca32667c0794390b75efc43cff3a179f3c3c3731 Mon Sep 17 00:00:00 2001 From: southeo Date: Thu, 26 Sep 2024 11:12:16 +0200 Subject: [PATCH] use agent instead of user id --- .../controller/DataMappingController.java | 12 +++---- .../MachineAnnotationServiceController.java | 12 +++---- .../controller/SourceSystemController.java | 12 +++---- .../backend/service/DataMappingService.java | 13 ++++---- .../MachineAnnotationServiceService.java | 14 ++++---- .../backend/service/SourceSystemService.java | 15 ++++----- .../backend/utils/ControllerUtils.java | 3 +- .../controller/DataMappingControllerTest.java | 4 +-- ...achineAnnotationServiceControllerTest.java | 32 +++++++++++++++++-- .../SourceSystemControllerTest.java | 4 +-- .../service/DataMappingServiceTest.java | 16 +++++----- .../MachineAnnotationServiceServiceTest.java | 27 ++++++++-------- .../service/SourceSystemServiceTest.java | 27 ++++++++-------- 13 files changed, 106 insertions(+), 85 deletions(-) diff --git a/src/main/java/eu/dissco/orchestration/backend/controller/DataMappingController.java b/src/main/java/eu/dissco/orchestration/backend/controller/DataMappingController.java index 8723a07..6692163 100644 --- a/src/main/java/eu/dissco/orchestration/backend/controller/DataMappingController.java +++ b/src/main/java/eu/dissco/orchestration/backend/controller/DataMappingController.java @@ -47,10 +47,10 @@ public ResponseEntity createDataMapping(Authentication authentic @RequestBody JsonApiRequestWrapper requestBody, HttpServletRequest servletRequest) throws JsonProcessingException, ProcessingFailedException, ForbiddenException { var dataMapping = getDataMappingRequestFromRequest(requestBody); - var userId = getAgent(authentication).getId(); - log.info("Received create request for data mapping: {} from user: {}", dataMapping, userId); + var user = getAgent(authentication); + log.info("Received create request for data mapping: {} from user: {}", dataMapping, user.getId()); String path = appProperties.getBaseUrl() + servletRequest.getRequestURI(); - var result = service.createDataMapping(dataMapping, userId, path); + var result = service.createDataMapping(dataMapping, user, path); return ResponseEntity.status(HttpStatus.CREATED).body(result); } @@ -61,10 +61,10 @@ public ResponseEntity updateDataMapping(Authentication authentic throws JsonProcessingException, NotFoundException, ProcessingFailedException, ForbiddenException { var dataMapping = getDataMappingRequestFromRequest(requestBody); var id = prefix + '/' + suffix; - var userId = getAgent(authentication).getId(); - log.info("Received update request for data mapping: {} from user: {}", dataMapping, userId); + var user = getAgent(authentication); + log.info("Received update request for data mapping: {} from user: {}", dataMapping, user.getId()); String path = appProperties.getBaseUrl() + servletRequest.getRequestURI(); - var result = service.updateDataMapping(id, dataMapping, userId, path); + var result = service.updateDataMapping(id, dataMapping, user, path); if (result == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } else { diff --git a/src/main/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceController.java b/src/main/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceController.java index 1e38115..f748c19 100644 --- a/src/main/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceController.java +++ b/src/main/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceController.java @@ -48,11 +48,11 @@ public ResponseEntity createMachineAnnotationService( @RequestBody JsonApiRequestWrapper requestBody, HttpServletRequest servletRequest) throws JsonProcessingException, ProcessingFailedException, ForbiddenException { var machineAnnotationService = getMachineAnnotation(requestBody); - var userId = getAgent(authentication).getId(); + var user = getAgent(authentication); log.info("Received create request for machine annotation service: {} from user: {}", - machineAnnotationService, userId); + machineAnnotationService, user.getId()); String path = appProperties.getBaseUrl() + servletRequest.getRequestURI(); - var result = service.createMachineAnnotationService(machineAnnotationService, userId, path); + var result = service.createMachineAnnotationService(machineAnnotationService, user, path); return ResponseEntity.status(HttpStatus.CREATED).body(result); } @@ -63,12 +63,12 @@ public ResponseEntity updateMachineAnnotationService( @RequestBody JsonApiRequestWrapper requestBody, HttpServletRequest servletRequest) throws JsonProcessingException, NotFoundException, ProcessingFailedException, ForbiddenException { var machineAnnotationService = getMachineAnnotation(requestBody); - var userId = getAgent(authentication).getId(); + var user = getAgent(authentication); var id = prefix + '/' + suffix; log.info("Received update request for machine annotation service: {} from user: {}", id, - userId); + user.getId()); String path = appProperties.getBaseUrl() + servletRequest.getRequestURI(); - var result = service.updateMachineAnnotationService(id, machineAnnotationService, userId, path); + var result = service.updateMachineAnnotationService(id, machineAnnotationService, user, path); if (result == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } else { diff --git a/src/main/java/eu/dissco/orchestration/backend/controller/SourceSystemController.java b/src/main/java/eu/dissco/orchestration/backend/controller/SourceSystemController.java index fc1e100..ab4fadf 100644 --- a/src/main/java/eu/dissco/orchestration/backend/controller/SourceSystemController.java +++ b/src/main/java/eu/dissco/orchestration/backend/controller/SourceSystemController.java @@ -49,10 +49,10 @@ public ResponseEntity createSourceSystem(Authentication authenti throws IOException, NotFoundException, ProcessingFailedException, ForbiddenException { var sourceSystemRequest = getSourceSystemFromRequest(requestBody); String path = appProperties.getBaseUrl() + servletRequest.getRequestURI(); - var userId = getAgent(authentication).getId(); + var user = getAgent(authentication); log.info("Received create request for source system: {} from user: {}", sourceSystemRequest, - userId); - var result = service.createSourceSystem(sourceSystemRequest, userId, path); + user.getId()); + var result = service.createSourceSystem(sourceSystemRequest, user, path); return ResponseEntity.status(HttpStatus.CREATED).body(result); } @@ -64,10 +64,10 @@ public ResponseEntity updateSourceSystem(Authentication authenti throws IOException, NotFoundException, ProcessingFailedException, ForbiddenException { var sourceSystemRequest = getSourceSystemFromRequest(requestBody); var id = prefix + '/' + suffix; - var userId = getAgent(authentication).getId(); - log.info("Received update request for source system: {} from user: {}", id, userId); + var user = getAgent(authentication); + log.info("Received update request for source system: {} from user: {}", id, user.getId()); String path = appProperties.getBaseUrl() + servletRequest.getRequestURI(); - var result = service.updateSourceSystem(id, sourceSystemRequest, userId, path, trigger); + var result = service.updateSourceSystem(id, sourceSystemRequest, user, path, trigger); if (result == null) { return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } else { diff --git a/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java b/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java index 538736e..b587fa4 100644 --- a/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java +++ b/src/main/java/eu/dissco/orchestration/backend/service/DataMappingService.java @@ -17,7 +17,6 @@ import eu.dissco.orchestration.backend.properties.FdoProperties; import eu.dissco.orchestration.backend.repository.DataMappingRepository; import eu.dissco.orchestration.backend.schema.Agent; -import eu.dissco.orchestration.backend.schema.Agent.Type; import eu.dissco.orchestration.backend.schema.DataMapping; import eu.dissco.orchestration.backend.schema.DataMapping.OdsMappingDataStandard; import eu.dissco.orchestration.backend.schema.DataMapping.OdsStatus; @@ -87,7 +86,7 @@ private static List buildFieldMapping( return mappedList; } - public JsonApiWrapper createDataMapping(DataMappingRequest mappingRequest, String userId, + public JsonApiWrapper createDataMapping(DataMappingRequest mappingRequest, Agent user, String path) throws ProcessingFailedException { var requestBody = fdoRecordService.buildCreateRequest(mappingRequest, ObjectType.DATA_MAPPING); @@ -97,7 +96,7 @@ public JsonApiWrapper createDataMapping(DataMappingRequest mappingRequest, Strin } catch (PidException e) { throw new ProcessingFailedException(e.getMessage(), e); } - var dataMapping = buildDataMapping(mappingRequest, 1, userId, handle, + var dataMapping = buildDataMapping(mappingRequest, 1, user, handle, Date.from(Instant.now())); repository.createDataMapping(dataMapping); publishCreateEvent(dataMapping); @@ -105,7 +104,7 @@ public JsonApiWrapper createDataMapping(DataMappingRequest mappingRequest, Strin } private DataMapping buildDataMapping(DataMappingRequest dataMappingRequest, int version, - String userId, String handle, Date created) { + Agent user, String handle, Date created) { var id = HANDLE_PROXY + handle; return new DataMapping() .withId(id) @@ -118,7 +117,7 @@ private DataMapping buildDataMapping(DataMappingRequest dataMappingRequest, int .withSchemaDescription(dataMappingRequest.getSchemaDescription()) .withSchemaDateCreated(created) .withSchemaDateModified(Date.from(Instant.now())) - .withSchemaCreator(new Agent().withId(userId).withType(Type.SCHEMA_PERSON)) + .withSchemaCreator(user) .withOdsDefaultMapping(buildDefaultMapping(dataMappingRequest)) .withOdsFieldMapping(buildFieldMapping(dataMappingRequest)) .withOdsMappingDataStandard(OdsMappingDataStandard.fromValue( @@ -149,7 +148,7 @@ private void rollbackMappingCreation(DataMapping dataMapping) { } public JsonApiWrapper updateDataMapping(String id, DataMappingRequest dataMappingRequest, - String userId, String path) throws NotFoundException, ProcessingFailedException { + Agent user, String path) throws NotFoundException, ProcessingFailedException { var currentDataMappingOptional = repository.getActiveDataMapping(id); if (currentDataMappingOptional.isEmpty()) { throw new NotFoundException("Requested data mapping does not exist"); @@ -157,7 +156,7 @@ public JsonApiWrapper updateDataMapping(String id, DataMappingRequest dataMappin var currentDataMapping = currentDataMappingOptional.get(); var dataMapping = buildDataMapping(dataMappingRequest, currentDataMapping.getSchemaVersion() + 1, - userId, id, currentDataMapping.getSchemaDateCreated()); + user, id, currentDataMapping.getSchemaDateCreated()); if (isEqual(dataMapping, currentDataMapping)) { return null; } else { diff --git a/src/main/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceService.java b/src/main/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceService.java index b5af34e..589d3bf 100644 --- a/src/main/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceService.java +++ b/src/main/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceService.java @@ -24,7 +24,6 @@ import eu.dissco.orchestration.backend.properties.MachineAnnotationServiceProperties; import eu.dissco.orchestration.backend.repository.MachineAnnotationServiceRepository; import eu.dissco.orchestration.backend.schema.Agent; -import eu.dissco.orchestration.backend.schema.Agent.Type; import eu.dissco.orchestration.backend.schema.MachineAnnotationService; import eu.dissco.orchestration.backend.schema.MachineAnnotationService.OdsStatus; import eu.dissco.orchestration.backend.schema.MachineAnnotationServiceRequest; @@ -95,13 +94,12 @@ private static SchemaContactPoint__1 buildContactPoint(SchemaContactPoint schema public JsonApiWrapper createMachineAnnotationService( MachineAnnotationServiceRequest masRequest, - String userId, - String path) throws ProcessingFailedException { + Agent user, String path) throws ProcessingFailedException { var requestBody = fdoRecordService.buildCreateRequest(masRequest, ObjectType.MAS); try { var handle = handleComponent.postHandle(requestBody); setDefaultMas(masRequest, handle); - var mas = buildMachineAnnotationService(masRequest, 1, userId, handle, + var mas = buildMachineAnnotationService(masRequest, 1, user, handle, Instant.now()); repository.createMachineAnnotationService(mas); createDeployment(mas); @@ -113,7 +111,7 @@ public JsonApiWrapper createMachineAnnotationService( } private MachineAnnotationService buildMachineAnnotationService( - MachineAnnotationServiceRequest mas, int version, String userId, String handle, + MachineAnnotationServiceRequest mas, int version, Agent user, String handle, Instant created) { var id = HANDLE_PROXY + handle; return new MachineAnnotationService() @@ -127,7 +125,7 @@ private MachineAnnotationService buildMachineAnnotationService( .withSchemaDescription(mas.getSchemaDescription()) .withSchemaDateCreated(Date.from(created)) .withSchemaDateModified(Date.from(Instant.now())) - .withSchemaCreator(new Agent().withId(userId).withType(Type.SCHEMA_PERSON)) + .withSchemaCreator(user) .withOdsContainerTag(mas.getOdsContainerTag()) .withOdsContainerImage(mas.getOdsContainerImage()) .withOdsTargetDigitalObjectFilter(buildTargetFilters(mas.getOdsTargetDigitalObjectFilter())) @@ -356,14 +354,14 @@ private void rollbackMasCreation(MachineAnnotationService mas, } public JsonApiWrapper updateMachineAnnotationService(String id, - MachineAnnotationServiceRequest masRequest, String userId, String path) + MachineAnnotationServiceRequest masRequest, Agent user, String path) throws NotFoundException, ProcessingFailedException { var currentMasOptional = repository.getActiveMachineAnnotationService(id); if (currentMasOptional.isPresent()) { var currentMas = currentMasOptional.get(); setDefaultMas(masRequest, id); var machineAnnotationService = buildMachineAnnotationService(masRequest, - currentMas.getSchemaVersion() + 1, userId, id, Instant.now()); + currentMas.getSchemaVersion() + 1, user, id, Instant.now()); if (isEqual(machineAnnotationService, currentMas)) { log.debug("No changes found for MAS"); return null; diff --git a/src/main/java/eu/dissco/orchestration/backend/service/SourceSystemService.java b/src/main/java/eu/dissco/orchestration/backend/service/SourceSystemService.java index 4d7e3f5..8efc9f2 100644 --- a/src/main/java/eu/dissco/orchestration/backend/service/SourceSystemService.java +++ b/src/main/java/eu/dissco/orchestration/backend/service/SourceSystemService.java @@ -20,7 +20,6 @@ import eu.dissco.orchestration.backend.properties.TranslatorJobProperties; import eu.dissco.orchestration.backend.repository.SourceSystemRepository; import eu.dissco.orchestration.backend.schema.Agent; -import eu.dissco.orchestration.backend.schema.Agent.Type; import eu.dissco.orchestration.backend.schema.SourceSystem; import eu.dissco.orchestration.backend.schema.SourceSystem.OdsStatus; import eu.dissco.orchestration.backend.schema.SourceSystem.OdsTranslatorType; @@ -137,7 +136,7 @@ private void updateCronsToImageTag() throws ApiException { } private SourceSystem buildSourceSystem( - SourceSystemRequest sourceSystemRequest, int version, String userId, String handle, + SourceSystemRequest sourceSystemRequest, int version, Agent user, String handle, Date created) { var id = HANDLE_PROXY + handle; return new SourceSystem() @@ -151,9 +150,7 @@ private SourceSystem buildSourceSystem( .withSchemaDescription(sourceSystemRequest.getSchemaDescription()) .withSchemaDateCreated(created) .withSchemaDateModified(Date.from(Instant.now())) - .withSchemaCreator(new Agent() - .withType(Type.SCHEMA_PERSON) - .withId(userId)) + .withSchemaCreator(user) .withSchemaUrl(sourceSystemRequest.getSchemaUrl()) .withOdsDataMappingID(sourceSystemRequest.getOdsDataMappingID()) .withOdsTranslatorType( @@ -162,12 +159,12 @@ private SourceSystem buildSourceSystem( .withLtcCollectionManagementSystem(sourceSystemRequest.getLtcCollectionManagementSystem()); } - public JsonApiWrapper createSourceSystem(SourceSystemRequest sourceSystemRequest, String userId, + public JsonApiWrapper createSourceSystem(SourceSystemRequest sourceSystemRequest, Agent user, String path) throws NotFoundException, ProcessingFailedException { validateMappingExists(sourceSystemRequest.getOdsDataMappingID()); String handle = createHandle(sourceSystemRequest); - var sourceSystem = buildSourceSystem(sourceSystemRequest, 1, userId, handle, + var sourceSystem = buildSourceSystem(sourceSystemRequest, 1, user, handle, Date.from(Instant.now())); repository.createSourceSystem(sourceSystem); createCronJob(sourceSystem); @@ -270,7 +267,7 @@ private void validateMappingExists(String mappingId) throws NotFoundException { } public JsonApiWrapper updateSourceSystem(String id, SourceSystemRequest sourceSystemRequest, - String userId, String path, boolean trigger) + Agent user, String path, boolean trigger) throws NotFoundException, ProcessingFailedException { var currentSourceSystemOptional = repository.getActiveSourceSystem(id); if (currentSourceSystemOptional.isEmpty()) { @@ -279,7 +276,7 @@ public JsonApiWrapper updateSourceSystem(String id, SourceSystemRequest sourceSy } var currentSourceSystem = currentSourceSystemOptional.get(); var sourceSystem = buildSourceSystem(sourceSystemRequest, - currentSourceSystem.getSchemaVersion() + 1, userId, id, + currentSourceSystem.getSchemaVersion() + 1, user, id, currentSourceSystem.getSchemaDateCreated()); if (isEquals(sourceSystem, currentSourceSystem)) { log.info( diff --git a/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java b/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java index 4a9a1e1..5f28c39 100644 --- a/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java +++ b/src/main/java/eu/dissco/orchestration/backend/utils/ControllerUtils.java @@ -24,9 +24,10 @@ public static Agent getAgent(Authentication authentication) throws ForbiddenExce } fullName.append(claims.get("family_name")); } + var nameString = fullName.toString().isEmpty() ? null : fullName.toString(); return new Agent() .withType(Type.SCHEMA_PERSON) - .withSchemaName(fullName.toString()) + .withSchemaName(nameString) .withId((String) claims.get("orcid")); } else { log.error("Missing ORCID in token"); diff --git a/src/test/java/eu/dissco/orchestration/backend/controller/DataMappingControllerTest.java b/src/test/java/eu/dissco/orchestration/backend/controller/DataMappingControllerTest.java index 55a8495..fd39298 100644 --- a/src/test/java/eu/dissco/orchestration/backend/controller/DataMappingControllerTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/controller/DataMappingControllerTest.java @@ -5,9 +5,9 @@ import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPER; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPING_PATH; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPING_URI; -import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR; import static eu.dissco.orchestration.backend.testutils.TestUtils.PREFIX; import static eu.dissco.orchestration.backend.testutils.TestUtils.SUFFIX; +import static eu.dissco.orchestration.backend.testutils.TestUtils.givenAgent; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenClaims; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenDataMapping; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenDataMappingRequest; @@ -83,7 +83,7 @@ void testUpdateDataMapping() throws Exception { // Given givenAuthentication(); var requestBody = givenDataMappingRequestJson(); - given(service.updateDataMapping(BARE_HANDLE, givenDataMappingRequest(), OBJECT_CREATOR, + given(service.updateDataMapping(BARE_HANDLE, givenDataMappingRequest(), givenAgent(), "null/data-mapping")).willReturn( givenDataMappingSingleJsonApiWrapper()); diff --git a/src/test/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceControllerTest.java b/src/test/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceControllerTest.java index 149ec56..7c4d721 100644 --- a/src/test/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceControllerTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/controller/MachineAnnotationServiceControllerTest.java @@ -6,6 +6,7 @@ import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR; import static eu.dissco.orchestration.backend.testutils.TestUtils.PREFIX; import static eu.dissco.orchestration.backend.testutils.TestUtils.SUFFIX; +import static eu.dissco.orchestration.backend.testutils.TestUtils.givenAgent; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenClaims; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasRequest; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenMasRequestJson; @@ -13,11 +14,16 @@ import static eu.dissco.orchestration.backend.testutils.TestUtils.givenSourceSystemRequestJson; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertThrowsExactly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import eu.dissco.orchestration.backend.properties.ApplicationProperties; import eu.dissco.orchestration.backend.service.MachineAnnotationServiceService; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -30,6 +36,7 @@ @ExtendWith(MockitoExtension.class) class MachineAnnotationServiceControllerTest { + @Mock private Authentication authentication; MockHttpServletRequest mockRequest = new MockHttpServletRequest(); @@ -75,7 +82,7 @@ void testUpdateMas() throws Exception { givenAuthentication(); var mas = givenMasRequestJson(); var masResponse = givenMasSingleJsonApiWrapper(); - given(service.updateMachineAnnotationService(BARE_HANDLE, givenMasRequest(), OBJECT_CREATOR, + given(service.updateMachineAnnotationService(BARE_HANDLE, givenMasRequest(), givenAgent(), "null/mas")).willReturn( masResponse); @@ -87,12 +94,33 @@ void testUpdateMas() throws Exception { assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); } + @Test + void testUpdateMasTokenHasName() throws Exception { + // Given + var principal = mock(Jwt.class); + given(authentication.getPrincipal()).willReturn(principal); + given(principal.getClaims()).willReturn(Map.of( + "orcid", OBJECT_CREATOR, + "given_name", "Carl" + )); + var expectedAgent = givenAgent() + .withSchemaName("Carl"); + + // When + controller.updateMachineAnnotationService(authentication, PREFIX, SUFFIX, + givenMasRequestJson(), mockRequest); + + // Then + then(service).should() + .updateMachineAnnotationService(anyString(), any(), eq(expectedAgent), anyString()); + } + @Test void testUpdateMasNoChange() throws Exception { // Given givenAuthentication(); var mas = givenMasRequestJson(); - given(service.updateMachineAnnotationService(BARE_HANDLE, givenMasRequest(), OBJECT_CREATOR, + given(service.updateMachineAnnotationService(BARE_HANDLE, givenMasRequest(), givenAgent(), "null/mas")).willReturn( null); diff --git a/src/test/java/eu/dissco/orchestration/backend/controller/SourceSystemControllerTest.java b/src/test/java/eu/dissco/orchestration/backend/controller/SourceSystemControllerTest.java index 0685195..9d87308 100644 --- a/src/test/java/eu/dissco/orchestration/backend/controller/SourceSystemControllerTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/controller/SourceSystemControllerTest.java @@ -2,12 +2,12 @@ import static eu.dissco.orchestration.backend.testutils.TestUtils.BARE_HANDLE; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPER; -import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR; import static eu.dissco.orchestration.backend.testutils.TestUtils.PREFIX; import static eu.dissco.orchestration.backend.testutils.TestUtils.SANDBOX_URI; import static eu.dissco.orchestration.backend.testutils.TestUtils.SUFFIX; import static eu.dissco.orchestration.backend.testutils.TestUtils.SYSTEM_PATH; import static eu.dissco.orchestration.backend.testutils.TestUtils.SYSTEM_URI; +import static eu.dissco.orchestration.backend.testutils.TestUtils.givenAgent; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenClaims; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenDataMappingRequestJson; import static eu.dissco.orchestration.backend.testutils.TestUtils.givenSourceSystem; @@ -84,7 +84,7 @@ void testUpdateSourceSystem() throws Exception { // Given var sourceSystem = givenSourceSystemRequestJson(); givenAuthentication(); - given(service.updateSourceSystem(BARE_HANDLE, givenSourceSystemRequest(), OBJECT_CREATOR, + given(service.updateSourceSystem(BARE_HANDLE, givenSourceSystemRequest(), givenAgent(), "null/source-system", true)).willReturn( givenSourceSystemSingleJsonApiWrapper()); diff --git a/src/test/java/eu/dissco/orchestration/backend/service/DataMappingServiceTest.java b/src/test/java/eu/dissco/orchestration/backend/service/DataMappingServiceTest.java index abe2a6a..935fecf 100644 --- a/src/test/java/eu/dissco/orchestration/backend/service/DataMappingServiceTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/service/DataMappingServiceTest.java @@ -95,7 +95,7 @@ void testCreateDataMapping() throws Exception { given(handleComponent.postHandle(any())).willReturn(BARE_HANDLE); // When - var result = service.createDataMapping(dataMapping, OBJECT_CREATOR, MAPPING_PATH); + var result = service.createDataMapping(dataMapping, givenAgent(), MAPPING_PATH); // Then assertThat(result).isEqualTo(expected); @@ -116,7 +116,7 @@ void testCreateDataMappingKafkaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createDataMapping(dataMapping, OBJECT_CREATOR, MAPPING_PATH)); + () -> service.createDataMapping(dataMapping, givenAgent(), MAPPING_PATH)); // Then then(fdoRecordService).should().buildCreateRequest(dataMapping, ObjectType.DATA_MAPPING); @@ -134,7 +134,7 @@ void testCreateMasHandleFails() throws Exception { // Then assertThrowsExactly(ProcessingFailedException.class, () -> - service.createDataMapping(dataMapping, OBJECT_CREATOR, MAPPING_PATH)); + service.createDataMapping(dataMapping, givenAgent(), MAPPING_PATH)); } @Test @@ -149,7 +149,7 @@ void testCreateDataMappingKafkaAndRollbackFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createDataMapping(dataMapping, OBJECT_CREATOR, MAPPING_PATH)); + () -> service.createDataMapping(dataMapping, givenAgent(), MAPPING_PATH)); // Then then(fdoRecordService).should().buildCreateRequest(dataMapping, ObjectType.DATA_MAPPING); @@ -170,7 +170,7 @@ void testUpdateDataMapping() throws Exception { given(repository.getActiveDataMapping(BARE_HANDLE)).willReturn(Optional.of(prevDataMapping)); // When - var result = service.updateDataMapping(BARE_HANDLE, dataMapping, OBJECT_CREATOR, MAPPING_PATH); + var result = service.updateDataMapping(BARE_HANDLE, dataMapping, givenAgent(), MAPPING_PATH); // Then assertThat(result).isEqualTo(expected); @@ -193,7 +193,7 @@ void testUpdateDataMappingKafkaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateDataMapping(BARE_HANDLE, dataMapping, OBJECT_CREATOR, MAPPING_PATH)); + () -> service.updateDataMapping(BARE_HANDLE, dataMapping, givenAgent(), MAPPING_PATH)); // Then then(repository).should().updateDataMapping(givenDataMapping(HANDLE, 2)); @@ -209,7 +209,7 @@ void testUpdateDataMappingNoChanges() throws Exception { given(repository.getActiveDataMapping(BARE_HANDLE)).willReturn(prevMapping); // When - var result = service.updateDataMapping(BARE_HANDLE, dataMapping, OBJECT_CREATOR, MAPPING_PATH); + var result = service.updateDataMapping(BARE_HANDLE, dataMapping, givenAgent(), MAPPING_PATH); // Then assertThat(result).isNull(); @@ -222,7 +222,7 @@ void testUpdateDataMappingNotFound() { // Then assertThrows(NotFoundException.class, - () -> service.updateDataMapping(BARE_HANDLE, givenDataMappingRequest(), OBJECT_CREATOR, + () -> service.updateDataMapping(BARE_HANDLE, givenDataMappingRequest(), givenAgent(), OBJECT_CREATOR)); } diff --git a/src/test/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceServiceTest.java b/src/test/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceServiceTest.java index 3bf2008..f0e4eb7 100644 --- a/src/test/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceServiceTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/service/MachineAnnotationServiceServiceTest.java @@ -6,7 +6,6 @@ import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPER; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAS_PATH; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAS_TYPE_DOI; -import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR; import static eu.dissco.orchestration.backend.testutils.TestUtils.SUFFIX; import static eu.dissco.orchestration.backend.testutils.TestUtils.TTL; import static eu.dissco.orchestration.backend.testutils.TestUtils.UPDATED; @@ -160,7 +159,7 @@ void testCreateMas(List masEnv, anyString(), any(Object.class))).willReturn(createCustom); // When - var result = service.createMachineAnnotationService(masRequest, OBJECT_CREATOR, MAS_PATH); + var result = service.createMachineAnnotationService(masRequest, givenAgent(), MAS_PATH); // Then assertThat(result).isEqualTo(expected); @@ -208,7 +207,7 @@ void testCreateMasMinimum(Integer maxReplicas) throws Exception { anyString(), any(Object.class))).willReturn(createCustom); // When - var result = service.createMachineAnnotationService(masRequest, OBJECT_CREATOR, MAS_PATH); + var result = service.createMachineAnnotationService(masRequest, givenAgent(), MAS_PATH); // Then assertThat(result).isEqualTo(expected); @@ -231,7 +230,7 @@ void testCreateMasHandleFails() throws Exception { // Then assertThrowsExactly(ProcessingFailedException.class, () -> - service.createMachineAnnotationService(mas, OBJECT_CREATOR, MAS_PATH)); + service.createMachineAnnotationService(mas, givenAgent(), MAS_PATH)); } @Test @@ -250,7 +249,7 @@ void testCreateMasDeployFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createMachineAnnotationService(mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.createMachineAnnotationService(mas, givenAgent(), MAS_PATH)); // Then then(repository).should().createMachineAnnotationService(givenMas()); @@ -281,7 +280,7 @@ void testCreateKedaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createMachineAnnotationService(mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.createMachineAnnotationService(mas, givenAgent(), MAS_PATH)); // Then then(repository).should().createMachineAnnotationService(givenMas()); @@ -319,7 +318,7 @@ void testCreateMasKafkaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createMachineAnnotationService(mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.createMachineAnnotationService(mas, givenAgent(), MAS_PATH)); // Then then(fdoRecordService).should().buildCreateRequest(mas, ObjectType.MAS); @@ -369,7 +368,7 @@ void testCreateMasKafkaAndPidFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createMachineAnnotationService(mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.createMachineAnnotationService(mas, givenAgent(), MAS_PATH)); // Then then(fdoRecordService).should().buildCreateRequest(mas, ObjectType.MAS); @@ -415,7 +414,7 @@ void testUpdateMas() throws Exception { anyString(), any(Object.class))).willReturn(createCustom); // When - var result = service.updateMachineAnnotationService(BARE_HANDLE, mas, OBJECT_CREATOR, MAS_PATH); + var result = service.updateMachineAnnotationService(BARE_HANDLE, mas, givenAgent(), MAS_PATH); // Then assertThat(result).isEqualTo(expected); @@ -456,7 +455,7 @@ void testUpdateMasDeployFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateMachineAnnotationService(BARE_HANDLE, mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.updateMachineAnnotationService(BARE_HANDLE, mas, givenAgent(), MAS_PATH)); // Then then(repository).should().updateMachineAnnotationService(givenMas(2)); @@ -490,7 +489,7 @@ void testUpdateKedaFails() throws ApiException { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateMachineAnnotationService(BARE_HANDLE, mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.updateMachineAnnotationService(BARE_HANDLE, mas, givenAgent(), MAS_PATH)); // Then then(repository).should().updateMachineAnnotationService(givenMas(2)); @@ -526,7 +525,7 @@ void testUpdateMasKafkaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateMachineAnnotationService(BARE_HANDLE, mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.updateMachineAnnotationService(BARE_HANDLE, mas, givenAgent(), MAS_PATH)); // Then then(repository).should().updateMachineAnnotationService(givenMas(2)); @@ -550,7 +549,7 @@ void testUpdateMasEqual() throws Exception { Optional.of(givenMas())); // When - var result = service.updateMachineAnnotationService(HANDLE, mas, OBJECT_CREATOR, MAS_PATH); + var result = service.updateMachineAnnotationService(HANDLE, mas, givenAgent(), MAS_PATH); // Then assertThat(result).isNull(); @@ -564,7 +563,7 @@ void testUpdateMasNotFound() { // When/Then assertThrowsExactly(NotFoundException.class, - () -> service.updateMachineAnnotationService(HANDLE, mas, OBJECT_CREATOR, MAS_PATH)); + () -> service.updateMachineAnnotationService(HANDLE, mas, givenAgent(), MAS_PATH)); } @Test diff --git a/src/test/java/eu/dissco/orchestration/backend/service/SourceSystemServiceTest.java b/src/test/java/eu/dissco/orchestration/backend/service/SourceSystemServiceTest.java index 220f05c..6042799 100644 --- a/src/test/java/eu/dissco/orchestration/backend/service/SourceSystemServiceTest.java +++ b/src/test/java/eu/dissco/orchestration/backend/service/SourceSystemServiceTest.java @@ -5,7 +5,6 @@ import static eu.dissco.orchestration.backend.testutils.TestUtils.HANDLE; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPER; import static eu.dissco.orchestration.backend.testutils.TestUtils.MAPPING_PATH; -import static eu.dissco.orchestration.backend.testutils.TestUtils.OBJECT_CREATOR; import static eu.dissco.orchestration.backend.testutils.TestUtils.SANDBOX_URI; import static eu.dissco.orchestration.backend.testutils.TestUtils.SOURCE_SYSTEM_TYPE_DOI; import static eu.dissco.orchestration.backend.testutils.TestUtils.SYSTEM_PATH; @@ -176,7 +175,7 @@ void testCreateSourceSystem() throws Exception { batchV1Api.createNamespacedJob(eq(NAMESPACE), any(V1Job.class))).willReturn(createJob); // When - var result = service.createSourceSystem(sourceSystem, OBJECT_CREATOR, SYSTEM_PATH); + var result = service.createSourceSystem(sourceSystem, givenAgent(), SYSTEM_PATH); // Then assertThat(result).isEqualTo(expected); @@ -193,7 +192,7 @@ void testCreateSourceSystemMappingNotFound() { Optional.empty()); assertThrowsExactly(NotFoundException.class, - () -> service.createSourceSystem(sourceSystem, OBJECT_CREATOR, SYSTEM_PATH)); + () -> service.createSourceSystem(sourceSystem, givenAgent(), SYSTEM_PATH)); } @Test @@ -211,7 +210,7 @@ void testCreateSourceSystemCronFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createSourceSystem(sourceSystem, OBJECT_CREATOR, SYSTEM_PATH)); + () -> service.createSourceSystem(sourceSystem, givenAgent(), SYSTEM_PATH)); // Then then(repository).should().createSourceSystem(givenSourceSystem()); @@ -240,7 +239,7 @@ void testCreateSourceSystemTranslatorJobFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createSourceSystem(sourceSystem, OBJECT_CREATOR, SYSTEM_PATH)); + () -> service.createSourceSystem(sourceSystem, givenAgent(), SYSTEM_PATH)); // Then then(repository).should().createSourceSystem(givenSourceSystem()); @@ -270,7 +269,7 @@ void testCreateSourceSystemKafkaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createSourceSystem(sourceSystem, OBJECT_CREATOR, SYSTEM_PATH)); + () -> service.createSourceSystem(sourceSystem, givenAgent(), SYSTEM_PATH)); // Then then(repository).should().createSourceSystem(givenSourceSystem()); @@ -289,7 +288,7 @@ void testCreateMasHandleFails() throws Exception { // When / Then assertThrowsExactly(ProcessingFailedException.class, () -> - service.createSourceSystem(sourceSystem, OBJECT_CREATOR, MAPPING_PATH)); + service.createSourceSystem(sourceSystem, givenAgent(), MAPPING_PATH)); } @Test @@ -314,7 +313,7 @@ void testCreateSourceSystemKafkaAndRollbackFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.createSourceSystem(sourceSystem, OBJECT_CREATOR, SYSTEM_PATH)); + () -> service.createSourceSystem(sourceSystem, givenAgent(), SYSTEM_PATH)); // Then then(repository).should().createSourceSystem(givenSourceSystem(OdsTranslatorType.DWCA)); @@ -354,7 +353,7 @@ void testUpdateSourceSystem(boolean triggerTranslator) throws Exception { } // When - var result = service.updateSourceSystem(BARE_HANDLE, sourceSystem, OBJECT_CREATOR, SYSTEM_PATH, + var result = service.updateSourceSystem(BARE_HANDLE, sourceSystem, givenAgent(), SYSTEM_PATH, triggerTranslator); // Then @@ -383,7 +382,7 @@ void testUpdateSourceSystemCronJobFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateSourceSystem(BARE_HANDLE, sourceSystem, OBJECT_CREATOR, SYSTEM_PATH, + () -> service.updateSourceSystem(BARE_HANDLE, sourceSystem, givenAgent(), SYSTEM_PATH, false)); // Then @@ -406,7 +405,7 @@ void testUpdateSourceSystemKafkaFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateSourceSystem(BARE_HANDLE, sourceSystem, OBJECT_CREATOR, SYSTEM_PATH, + () -> service.updateSourceSystem(BARE_HANDLE, sourceSystem, givenAgent(), SYSTEM_PATH, false)); // Then @@ -430,7 +429,7 @@ void testUpdateSourceSystemTriggerTranslatorFails() throws Exception { // When assertThrowsExactly(ProcessingFailedException.class, - () -> service.updateSourceSystem(BARE_HANDLE, sourceSystem, OBJECT_CREATOR, SYSTEM_PATH, + () -> service.updateSourceSystem(BARE_HANDLE, sourceSystem, givenAgent(), SYSTEM_PATH, true)); // Then @@ -448,7 +447,7 @@ void testUpdateSourceSystemNotFound() { // Then assertThrowsExactly(NotFoundException.class, - () -> service.updateSourceSystem(HANDLE, sourceSystem, OBJECT_CREATOR, SYSTEM_PATH, true)); + () -> service.updateSourceSystem(HANDLE, sourceSystem, givenAgent(), SYSTEM_PATH, true)); } @Test @@ -459,7 +458,7 @@ void testUpdateSourceSystemNoChanges() throws Exception { Optional.of(givenSourceSystem())); // When - var result = service.updateSourceSystem(BARE_HANDLE, sourceSystem, OBJECT_CREATOR, SYSTEM_PATH, + var result = service.updateSourceSystem(BARE_HANDLE, sourceSystem, givenAgent(), SYSTEM_PATH, false); // Then