From f374e7e28f01c1c48adec5abb36631c322e97e1c Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Wed, 26 Mar 2025 14:13:22 +0100 Subject: [PATCH] WIP Signed-off-by: Martin Weise <martin.weise@tuwien.ac.at> --- .../ifs/dbrepo/config/RabbitConfig.java | 2 +- .../endpoints/AccessEndpointUnitTest.java | 102 ++--- .../endpoints/ConceptEndpointUnitTest.java | 2 +- .../endpoints/ContainerEndpointUnitTest.java | 57 ++- .../endpoints/DatabaseEndpointUnitTest.java | 261 ++++++------- .../endpoints/IdentifierEndpointUnitTest.java | 354 +++++++++--------- .../endpoints/ImageEndpointUnitTest.java | 99 ++--- .../endpoints/MessageEndpointUnitTest.java | 22 +- .../endpoints/MetadataEndpointUnitTest.java | 22 +- .../endpoints/OntologyEndpointUnitTest.java | 32 +- .../endpoints/TableEndpointUnitTest.java | 256 ++++++------- .../endpoints/UnitEndpointUnitTest.java | 2 +- .../endpoints/UserEndpointUnitTest.java | 34 +- .../endpoints/ViewEndpointUnitTest.java | 130 +++---- .../gateway/BrokerServiceGatewayUnitTest.java | 34 +- .../gateway/DataServiceGatewayUnitTest.java | 146 ++++---- .../KeycloakGatewayIntegrationTest.java | 20 +- .../gateway/SearchServiceGatewayUnitTest.java | 12 +- .../dbrepo/mapper/MetadataMapperUnitTest.java | 2 +- ...nticationPrivilegedIntegrationMvcTest.java | 38 +- .../dbrepo/mvc/MetadataEndpointMvcTest.java | 6 +- .../dbrepo/mvc/PrometheusEndpointMvcTest.java | 98 ++--- .../dbrepo/service/AccessServiceUnitTest.java | 10 +- .../AuthenticationServiceIntegrationTest.java | 8 +- .../service/BrokerServiceIntegrationTest.java | 44 +-- .../service/ContainerServiceUnitTest.java | 26 +- ...aCiteIdentifierServicePersistenceTest.java | 20 +- .../DatabaseServicePersistenceTest.java | 2 +- .../service/DatabaseServiceUnitTest.java | 38 +- .../IdentifierServicePersistenceTest.java | 50 +-- .../service/ImageServicePersistenceTest.java | 40 +- .../dbrepo/service/ImageServiceUnitTest.java | 44 +-- .../service/MetadataServiceUnitTest.java | 4 +- .../service/TableServicePersistenceTest.java | 14 +- .../dbrepo/service/TableServiceUnitTest.java | 52 +-- .../service/UserServiceIntegrationTest.java | 6 +- .../service/UserServicePersistenceTest.java | 16 +- .../dbrepo/service/UserServiceUnitTest.java | 26 +- .../service/ViewServicePersistenceTest.java | 2 +- .../dbrepo/service/ViewServiceUnitTest.java | 14 +- .../ac/tuwien/ifs/dbrepo/utils/AmqpUtils.java | 4 +- .../validator/EndpointValidatorUnitTest.java | 14 +- .../dbrepo/core/mapper/MetadataMapper.java | 10 +- .../tuwien/ifs/dbrepo/core/test/BaseTest.java | 58 +-- .../database-1-user-1-read-access.json | 12 - .../database-1-user-2-write-own-access.json | 12 - .../database-1-user-3-write-all-access.json | 11 - .../src/main/resources/database-1.json | 34 +- .../database-2-user-2-write-all-access.json | 12 - .../database-2-user-3-read-access.json | 11 - .../src/main/resources/database-2.json | 23 +- .../database-3-user-1-write-all-access.json | 12 - .../src/main/resources/database-3.json | 13 +- .../database-4-user-1-read-access.json | 3 - .../database-4-user-2-write-own-access.json | 3 - .../database-4-user-3-write-all-access.json | 3 - 56 files changed, 1202 insertions(+), 1180 deletions(-) delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-1-user-1-read-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-1-user-2-write-own-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-1-user-3-write-all-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-2-user-2-write-all-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-2-user-3-read-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-3-user-1-write-all-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-4-user-1-read-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-4-user-2-write-own-access.json delete mode 100644 lib/java/dbrepo-core/src/main/resources/database-4-user-3-write-all-access.json diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/config/RabbitConfig.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/config/RabbitConfig.java index 3dddb8cf33..8f7c32a6e8 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/config/RabbitConfig.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/config/RabbitConfig.java @@ -36,7 +36,7 @@ public class RabbitConfig extends BaseTest { final RestTemplate restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(brokerEndpoint)); restTemplate.getInterceptors() - .add(new BasicAuthenticationInterceptor(USER_1_USERNAME, USER_1_PASSWORD)); + .add(new BasicAuthenticationInterceptor("junit1", USER_1_PASSWORD)); return restTemplate; } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/AccessEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/AccessEndpointUnitTest.java index 9a37afb0b3..9efc6c4e82 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/AccessEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/AccessEndpointUnitTest.java @@ -2,10 +2,12 @@ package at.ac.tuwien.ifs.dbrepo.endpoints; import at.ac.tuwien.ifs.dbrepo.core.api.database.AccessTypeDto; import at.ac.tuwien.ifs.dbrepo.core.api.database.DatabaseAccessDto; +import at.ac.tuwien.ifs.dbrepo.core.api.grafana.CreateDashboardResponseDto; import at.ac.tuwien.ifs.dbrepo.core.entity.database.Database; import at.ac.tuwien.ifs.dbrepo.core.entity.database.DatabaseAccess; import at.ac.tuwien.ifs.dbrepo.core.entity.user.User; import at.ac.tuwien.ifs.dbrepo.core.exception.*; +import at.ac.tuwien.ifs.dbrepo.core.mapper.MetadataMapper; import at.ac.tuwien.ifs.dbrepo.core.test.BaseTest; import at.ac.tuwien.ifs.dbrepo.service.AccessService; import at.ac.tuwien.ifs.dbrepo.service.DashboardService; @@ -67,90 +69,90 @@ public class AccessEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRoleNoAccess_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_create(USER_2_PRINCIPAL, USER_2, USER_4_ID, USER_4, null); + generic_create(USER_2_PRINCIPAL, USER_2, USER_4.getId(), USER_4, null); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_create(USER_2_PRINCIPAL, USER_2, USER_4_ID, USER_4, null); + generic_create(USER_2_PRINCIPAL, USER_2, USER_4.getId(), USER_4, null); }); } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {"create-database-access"}) + @WithMockUser(username = "junit4", authorities = {"create-database-access"}) public void create_notOwner_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(USER_2_PRINCIPAL, USER_2, USER_4_ID, USER_4, null); + generic_create(USER_2_PRINCIPAL, USER_2, USER_4.getId(), USER_4, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database-access"}) + @WithMockUser(username = "junit1", authorities = {"create-database-access"}) public void create_alreadyAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(USER_1_PRINCIPAL, USER_1, USER_2_ID, USER_2, DATABASE_1_USER_2_READ_ACCESS); + generic_create(USER_1_PRINCIPAL, USER_1, USER_2.getId(), USER_2, DATABASE_1.getAccesses().get(1)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database-access"}) + @WithMockUser(username = "junit1", authorities = {"create-database-access"}) public void create_succeeds() throws DataServiceException, DataServiceConnectionException, NotAllowedException, DatabaseNotFoundException, UserNotFoundException, AccessNotFoundException, SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { /* mock */ when(accessService.create(eq(DATABASE_1), eq(USER_2), any(AccessTypeDto.class))) - .thenReturn(DATABASE_1_USER_1_READ_ACCESS); + .thenReturn(DATABASE_1.getAccesses().get(0)); /* test */ - generic_create(USER_1_PRINCIPAL, USER_1, USER_2_ID, USER_2, null); + generic_create(USER_1_PRINCIPAL, USER_1, USER_2.getId(), USER_2, null); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"check-database-access"}) + @WithMockUser(username = "junit1", authorities = {"check-database-access"}) public void find_hasRoleNoAccess_fails() { /* test */ assertThrows(AccessNotFoundException.class, () -> { - generic_find(DATABASE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2, USER_2_ID, USER_2); + generic_find(DATABASE_1.getId(), DATABASE_1, null, USER_2_PRINCIPAL, USER_2, USER_2.getId(), USER_2); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"check-database-access"}) + @WithMockUser(username = "junit1", authorities = {"check-database-access"}) public void find_hasRoleHasAccess_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, NotAllowedException { /* test */ - generic_find(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, USER_1_PRINCIPAL, USER_1, USER_1_ID, USER_1); + generic_find(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), USER_1_PRINCIPAL, USER_1, USER_1.getId(), USER_1); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"check-database-access"}) + @WithMockUser(username = "junit1", authorities = {"check-database-access"}) public void find_hasRoleHasAccessForeign_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_find(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, USER_1_PRINCIPAL, USER_1, USER_2_ID, USER_2); + generic_find(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), USER_1_PRINCIPAL, USER_1, USER_2.getId(), USER_2); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"check-database-access", "check-foreign-database-access"}) + @WithMockUser(username = "junit1", authorities = {"check-database-access", "check-foreign-database-access"}) public void find_hasRoleHasAccessForeign_succeeds() throws UserNotFoundException, NotAllowedException, DatabaseNotFoundException, AccessNotFoundException { final Principal principal = new UsernamePasswordAuthenticationToken(USER_1_DETAILS, USER_1_PASSWORD, List.of( @@ -158,7 +160,7 @@ public class AccessEndpointUnitTest extends BaseTest { new SimpleGrantedAuthority("check-foreign-database-access"))); /* test */ - generic_find(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_2_READ_ACCESS, principal, USER_1, USER_2_ID, USER_2); + generic_find(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(1), principal, USER_1, USER_2.getId(), USER_2); } @Test @@ -172,37 +174,37 @@ public class AccessEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"update-database-access"}) + @WithMockUser(username = "junit1", authorities = {"update-database-access"}) public void update_hasRoleNoAccess_fails() { /* test */ assertThrows(AccessNotFoundException.class, () -> { - generic_update(USER_1_PRINCIPAL, USER_1, USER_4_ID, USER_4, null); + generic_update(USER_1_PRINCIPAL, USER_1, USER_4.getId(), USER_4, null); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void update_noRoleNoAccess_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_update(USER_4_PRINCIPAL, USER_4, USER_1_ID, USER_1, null); + generic_update(USER_4_PRINCIPAL, USER_4, USER_1.getId(), USER_1, null); }); } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {"update-database-access"}) + @WithMockUser(username = "junit4", authorities = {"update-database-access"}) public void update_notOwner_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_update(USER_4_PRINCIPAL, USER_4, USER_1_ID, USER_1, null); + generic_update(USER_4_PRINCIPAL, USER_4, USER_1.getId(), USER_1, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"update-database-access"}) + @WithMockUser(username = "junit1", authorities = {"update-database-access"}) public void update_succeeds() throws NotAllowedException, DataServiceException, DataServiceConnectionException, AccessNotFoundException, DatabaseNotFoundException, UserNotFoundException, SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { @@ -213,21 +215,21 @@ public class AccessEndpointUnitTest extends BaseTest { .update(eq(DATABASE_1), eq(USER_2), any(AccessTypeDto.class)); /* test */ - generic_update(USER_1_PRINCIPAL, USER_1, USER_2_ID, USER_2, DATABASE_1_USER_2_WRITE_OWN_ACCESS); + generic_update(USER_1_PRINCIPAL, USER_1, USER_2.getId(), USER_2, DATABASE_1.getAccesses().get(0)); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"update-database-access"}) + @WithMockUser(username = "junit1", authorities = {"update-database-access"}) public void update_ownerNoAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_update(USER_1_PRINCIPAL, USER_1, USER_1_ID, null, null); + generic_update(USER_1_PRINCIPAL, USER_1, USER_1.getId(), null, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"update-database-access"}) + @WithMockUser(username = "junit1", authorities = {"update-database-access"}) public void update_ownerNoWriteAllAccess_fails() { /* test */ @@ -242,42 +244,42 @@ public class AccessEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_revoke(null, null, USER_1_ID, USER_1); + generic_revoke(null, null, USER_1.getId(), USER_1); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void revoke_noRoleNoAccess_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_revoke(USER_4_PRINCIPAL, USER_4, USER_1_ID, USER_1); + generic_revoke(USER_4_PRINCIPAL, USER_4, USER_1.getId(), USER_1); }); } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {"delete-database-access"}) + @WithMockUser(username = "junit4", authorities = {"delete-database-access"}) public void revoke_notOwner_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_revoke(USER_4_PRINCIPAL, USER_4, USER_1_ID, USER_1); + generic_revoke(USER_4_PRINCIPAL, USER_4, USER_1.getId(), USER_1); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"delete-database-access"}) + @WithMockUser(username = "junit1", authorities = {"delete-database-access"}) public void revoke_ownerNoAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_revoke(USER_1_PRINCIPAL, USER_1, USER_1_ID, null); + generic_revoke(USER_1_PRINCIPAL, USER_1, USER_1.getId(), null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"delete-database-access"}) + @WithMockUser(username = "junit1", authorities = {"delete-database-access"}) public void revoke_ownerNoWriteAllAccess_fails() { /* test */ @@ -287,7 +289,7 @@ public class AccessEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"delete-database-access"}) + @WithMockUser(username = "junit1", authorities = {"delete-database-access"}) public void revoke_succeeds() throws NotAllowedException, DataServiceException, DataServiceConnectionException, UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { @@ -298,7 +300,7 @@ public class AccessEndpointUnitTest extends BaseTest { .delete(DATABASE_1, USER_2); /* test */ - generic_revoke(USER_1_PRINCIPAL, USER_1, USER_2_ID, USER_2); + generic_revoke(USER_1_PRINCIPAL, USER_1, USER_2.getId(), USER_2); } /* ################################################################################################### */ @@ -311,7 +313,7 @@ public class AccessEndpointUnitTest extends BaseTest { SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); if (access != null) { when(accessService.find(DATABASE_1, user)) @@ -338,10 +340,12 @@ public class AccessEndpointUnitTest extends BaseTest { .findById(any(UUID.class)); } when(dashboardService.create(DATABASE_1)) - .thenReturn(DATABASE_1_CREATE_DASHBOARD_RESPONSE_DTO); + .thenReturn(CreateDashboardResponseDto.builder() + .uid(DATABASE_1.getDashboardUid()) + .build()); /* test */ - final ResponseEntity<?> response = accessEndpoint.create(DATABASE_1_ID, userId, UPDATE_DATABASE_ACCESS_READ_DTO, principal); + final ResponseEntity<?> response = accessEndpoint.create(DATABASE_1.getId(), userId, UPDATE_DATABASE_ACCESS_READ_DTO, principal); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertNull(response.getBody()); } @@ -386,14 +390,14 @@ public class AccessEndpointUnitTest extends BaseTest { SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); if (access != null) { - log.trace("mock access {} for user with id {} for database with id {}", access.getType(), userId, DATABASE_1_ID); + log.trace("mock access {} for user with id {} for database with id {}", access.getType(), userId, DATABASE_1.getId()); when(accessService.find(DATABASE_1, user)) .thenReturn(access); } else { - log.trace("mock no access for user with id {} for database with id {}", userId, DATABASE_1_ID); + log.trace("mock no access for user with id {} for database with id {}", userId, DATABASE_1.getId()); doThrow(AccessNotFoundException.class) .when(accessService) .find(DATABASE_1, user); @@ -419,7 +423,7 @@ public class AccessEndpointUnitTest extends BaseTest { .updateAccess(DATABASE_1, user, AccessTypeDto.READ); /* test */ - final ResponseEntity<?> response = accessEndpoint.update(DATABASE_1_ID, userId, UPDATE_DATABASE_ACCESS_READ_DTO, principal); + final ResponseEntity<?> response = accessEndpoint.update(DATABASE_1.getId(), userId, UPDATE_DATABASE_ACCESS_READ_DTO, principal); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertNull(response.getBody()); } @@ -430,7 +434,7 @@ public class AccessEndpointUnitTest extends BaseTest { SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); if (principal != null) { when(userService.findByUsername(principal.getName())) @@ -443,7 +447,7 @@ public class AccessEndpointUnitTest extends BaseTest { .updateAccess(DATABASE_1, user, null); /* test */ - final ResponseEntity<?> response = accessEndpoint.revoke(DATABASE_1_ID, userId, principal); + final ResponseEntity<?> response = accessEndpoint.revoke(DATABASE_1.getId(), userId, principal); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertNull(response.getBody()); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ConceptEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ConceptEndpointUnitTest.java index dc3fa63cd6..d1c991fd56 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ConceptEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ConceptEndpointUnitTest.java @@ -42,7 +42,7 @@ public class ConceptEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {}) + @WithMockUser(username = "junit4", authorities = {}) public void findAllConcepts_noRole_succeeds() { /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ContainerEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ContainerEndpointUnitTest.java index 93849d1aea..c330984deb 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ContainerEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ContainerEndpointUnitTest.java @@ -22,7 +22,6 @@ import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.junit.jupiter.SpringExtension; -import java.io.IOException; import java.security.Principal; import java.util.List; import java.util.UUID; @@ -47,15 +46,15 @@ public class ContainerEndpointUnitTest extends BaseTest { public void findById_anonymous_succeeds() throws ContainerNotFoundException { /* test */ - findById_generic(CONTAINER_1_ID, CONTAINER_1, null); + findById_generic(CONTAINER_1.getId(), CONTAINER_1, null); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findById_succeeds() throws ContainerNotFoundException { /* test */ - findById_generic(CONTAINER_1_ID, CONTAINER_1, USER_1_PRINCIPAL); + findById_generic(CONTAINER_1.getId(), CONTAINER_1, USER_1_PRINCIPAL); } @Test @@ -63,13 +62,13 @@ public class ContainerEndpointUnitTest extends BaseTest { public void findById_system_succeeds() throws ContainerNotFoundException { /* test */ - final ResponseEntity<ContainerDto> response = findById_generic(CONTAINER_1_ID, CONTAINER_1, USER_LOCAL_ADMIN_PRINCIPAL); + final ResponseEntity<ContainerDto> response = findById_generic(CONTAINER_1.getId(), CONTAINER_1, USER_LOCAL_ADMIN_PRINCIPAL); final HttpHeaders headers = response.getHeaders(); - assertEquals(List.of(CONTAINER_1_HOST), headers.get("X-Host")); - assertEquals(List.of("" + CONTAINER_1_PORT), headers.get("X-Port")); + assertEquals(List.of(CONTAINER_1.getHost()), headers.get("X-Host")); + assertEquals(List.of("" + CONTAINER_1.getPort()), headers.get("X-Port")); assertEquals(List.of(CONTAINER_1_PRIVILEGED_USERNAME), headers.get("X-Username")); assertEquals(List.of(CONTAINER_1_PRIVILEGED_PASSWORD), headers.get("X-Password")); - assertEquals(List.of(IMAGE_1_JDBC), headers.get("X-Jdbc-Method")); + assertEquals(List.of(IMAGE_1.getJdbcMethod()), headers.get("X-Jdbc-Method")); assertEquals(List.of("X-Username X-Password X-Jdbc-Method X-Host X-Port"), headers.get("Access-Control-Expose-Headers")); } @@ -79,26 +78,26 @@ public class ContainerEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - delete_generic(CONTAINER_1_ID, CONTAINER_1); + delete_generic(CONTAINER_1.getId(), CONTAINER_1); }); } @Test - @WithMockUser(username = USER_3_USERNAME) + @WithMockUser(username = "junit3") public void delete_noRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - delete_generic(CONTAINER_1_ID, CONTAINER_1); + delete_generic(CONTAINER_1.getId(), CONTAINER_1); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-container"}) + @WithMockUser(username = "junit2", authorities = {"delete-container"}) public void delete_hasRole_succeeds() throws ContainerNotFoundException { /* test */ - delete_generic(CONTAINER_1_ID, CONTAINER_1); + delete_generic(CONTAINER_1.getId(), CONTAINER_1); } @Test @@ -110,7 +109,7 @@ public class ContainerEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-containers"}) + @WithMockUser(username = "junit1", authorities = {"find-containers"}) public void findAll_hasRole_succeeds() { /* test */ @@ -118,7 +117,7 @@ public class ContainerEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void findAll_noRole_succeeds() { /* test */ @@ -129,8 +128,8 @@ public class ContainerEndpointUnitTest extends BaseTest { @WithAnonymousUser public void create_anonymous_fails() { final CreateContainerDto request = CreateContainerDto.builder() - .name(CONTAINER_1_NAME) - .imageId(IMAGE_1_ID) + .name(CONTAINER_1.getName()) + .imageId(CONTAINER_1.getId()) .build(); /* test */ @@ -140,11 +139,11 @@ public class ContainerEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-container"}) + @WithMockUser(username = "junit1", authorities = {"create-container"}) public void create_hasRole_succeeds() throws ContainerAlreadyExistsException, ImageNotFoundException { final CreateContainerDto request = CreateContainerDto.builder() - .name(CONTAINER_1_NAME) - .imageId(IMAGE_1_ID) + .name(CONTAINER_1.getName()) + .imageId(CONTAINER_1.getId()) .build(); /* test */ @@ -152,11 +151,11 @@ public class ContainerEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRole_fails() { final CreateContainerDto request = CreateContainerDto.builder() - .name(CONTAINER_1_NAME) - .imageId(IMAGE_1_ID) + .name(CONTAINER_1.getName()) + .imageId(CONTAINER_1.getId()) .build(); /* test */ @@ -219,13 +218,13 @@ public class ContainerEndpointUnitTest extends BaseTest { final List<ContainerBriefDto> body = response.getBody(); assertEquals(2, body.size()); final ContainerBriefDto container1 = body.get(0); - assertEquals(CONTAINER_1_ID, container1.getId()); - assertEquals(CONTAINER_1_NAME, container1.getName()); - assertEquals(CONTAINER_1_INTERNALNAME, container1.getInternalName()); + assertEquals(CONTAINER_1.getId(), container1.getId()); + assertEquals(CONTAINER_1.getName(), container1.getName()); + assertEquals(CONTAINER_1.getInternalName(), container1.getInternalName()); final ContainerBriefDto container2 = body.get(1); - assertEquals(CONTAINER_2_ID, container2.getId()); - assertEquals(CONTAINER_2_NAME, container2.getName()); - assertEquals(CONTAINER_2_INTERNALNAME, container2.getInternalName()); + assertEquals(CONTAINER_2.getId(), container2.getId()); + assertEquals(CONTAINER_2.getName(), container2.getName()); + assertEquals(CONTAINER_2.getInternalName(), container2.getInternalName()); } public void create_generic(CreateContainerDto data) throws ContainerAlreadyExistsException, ImageNotFoundException { diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/DatabaseEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/DatabaseEndpointUnitTest.java index bf6bd79352..50ac867557 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/DatabaseEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/DatabaseEndpointUnitTest.java @@ -1,12 +1,13 @@ package at.ac.tuwien.ifs.dbrepo.endpoints; import at.ac.tuwien.ifs.dbrepo.core.api.database.*; +import at.ac.tuwien.ifs.dbrepo.core.api.grafana.CreateDashboardResponseDto; import at.ac.tuwien.ifs.dbrepo.core.entity.database.Database; import at.ac.tuwien.ifs.dbrepo.core.entity.user.User; import at.ac.tuwien.ifs.dbrepo.core.exception.*; +import at.ac.tuwien.ifs.dbrepo.core.test.BaseTest; import at.ac.tuwien.ifs.dbrepo.service.*; import at.ac.tuwien.ifs.dbrepo.service.impl.DatabaseServiceImpl; -import at.ac.tuwien.ifs.dbrepo.core.test.BaseTest; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -63,9 +64,10 @@ public class DatabaseEndpointUnitTest extends BaseTest { @WithAnonymousUser public void create_anonymous_fails() { final CreateDatabaseDto request = CreateDatabaseDto.builder() - .cid(CONTAINER_1_ID) - .name(DATABASE_1_NAME) - .isPublic(DATABASE_1_PUBLIC) + .cid(CONTAINER_1.getId()) + .name(DATABASE_1.getName()) + .isPublic(DATABASE_1.getIsPublic()) + .isSchemaPublic(DATABASE_1.getIsSchemaPublic()) .build(); /* test */ @@ -75,12 +77,13 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRole_fails() { final CreateDatabaseDto request = CreateDatabaseDto.builder() - .cid(CONTAINER_3_ID) - .name(DATABASE_3_NAME) - .isPublic(DATABASE_3_PUBLIC) + .cid(CONTAINER_1.getId()) + .name(DATABASE_3.getName()) + .isPublic(DATABASE_3.getIsPublic()) + .isSchemaPublic(DATABASE_3.getIsSchemaPublic()) .build(); /* test */ @@ -90,22 +93,22 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database"}) + @WithMockUser(username = "junit1", authorities = {"create-database"}) public void create_succeeds() throws DataServiceException, DataServiceConnectionException, UserNotFoundException, DatabaseNotFoundException, ContainerNotFoundException, SearchServiceException, SearchServiceConnectionException, AuthServiceException, AuthServiceConnectionException, BrokerServiceException, BrokerServiceConnectionException, ContainerQuotaException, DashboardServiceException, DashboardServiceConnectionException { final CreateDatabaseDto request = CreateDatabaseDto.builder() - .cid(CONTAINER_1_ID) - .name(DATABASE_1_NAME) - .isPublic(DATABASE_1_PUBLIC) + .cid(CONTAINER_1.getId()) + .name(DATABASE_1.getName()) + .isPublic(DATABASE_1.getIsPublic()) .build(); /* mock */ - when(containerService.find(CONTAINER_1_ID)) + when(containerService.find(CONTAINER_1.getId())) .thenReturn(CONTAINER_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); when(userService.findAllInternalUsers()) .thenReturn(List.of(USER_LOCAL)); @@ -117,18 +120,18 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database"}) + @WithMockUser(username = "junit1", authorities = {"create-database"}) public void create_quotaExceeded_fails() throws UserNotFoundException, ContainerNotFoundException { final CreateDatabaseDto request = CreateDatabaseDto.builder() - .cid(CONTAINER_4_ID) - .name(DATABASE_1_NAME) - .isPublic(DATABASE_1_PUBLIC) + .cid(CONTAINER_4.getId()) + .name(DATABASE_1.getName()) + .isPublic(DATABASE_1.getIsPublic()) .build(); /* mock */ - when(containerService.find(CONTAINER_4_ID)) + when(containerService.find(CONTAINER_4.getId())) .thenReturn(CONTAINER_4); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); /* test */ @@ -143,110 +146,110 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - databaseEndpoint.refreshTableMetadata(DATABASE_1_ID, null); + databaseEndpoint.refreshTableMetadata(DATABASE_1.getId(), null); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void refreshTableMetadata_noRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - databaseEndpoint.refreshTableMetadata(DATABASE_1_ID, USER_1_PRINCIPAL); + databaseEndpoint.refreshTableMetadata(DATABASE_1.getId(), USER_1_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"find-database"}) + @WithMockUser(username = "junit2", authorities = {"find-database"}) public void refreshTableMetadata_notOwner_fails() throws UserNotFoundException, TableNotFoundException, SearchServiceException, MalformedException, DataServiceException, DatabaseNotFoundException, SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_2_ID)) + when(userService.findById(USER_2.getId())) .thenReturn(USER_2); when(databaseService.updateTableMetadata(any(Database.class))) .thenReturn(DATABASE_1); /* test */ assertThrows(NotAllowedException.class, () -> { - databaseEndpoint.refreshTableMetadata(DATABASE_1_ID, USER_2_PRINCIPAL); + databaseEndpoint.refreshTableMetadata(DATABASE_1.getId(), USER_2_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-database"}) + @WithMockUser(username = "junit1", authorities = {"find-database"}) public void refreshTableMetadata_succeeds() throws UserNotFoundException, TableNotFoundException, SearchServiceException, MalformedException, DataServiceException, DatabaseNotFoundException, SearchServiceConnectionException, DataServiceConnectionException, NotAllowedException, QueryNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); when(databaseService.updateTableMetadata(any(Database.class))) .thenReturn(DATABASE_1); /* test */ - final ResponseEntity<DatabaseBriefDto> response = databaseEndpoint.refreshTableMetadata(DATABASE_1_ID, USER_1_PRINCIPAL); + final ResponseEntity<DatabaseBriefDto> response = databaseEndpoint.refreshTableMetadata(DATABASE_1.getId(), USER_1_PRINCIPAL); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-database"}) + @WithMockUser(username = "junit1", authorities = {"find-database"}) public void refreshViewMetadata_succeeds() throws UserNotFoundException, SearchServiceException, NotAllowedException, DataServiceException, QueryNotFoundException, DatabaseNotFoundException, SearchServiceConnectionException, DataServiceConnectionException, ViewNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); when(databaseService.updateViewMetadata(any(Database.class))) .thenReturn(DATABASE_1); /* test */ - final ResponseEntity<DatabaseBriefDto> response = databaseEndpoint.refreshViewMetadata(DATABASE_1_ID, USER_1_PRINCIPAL); + final ResponseEntity<DatabaseBriefDto> response = databaseEndpoint.refreshViewMetadata(DATABASE_1.getId(), USER_1_PRINCIPAL); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"find-database"}) + @WithMockUser(username = "junit2", authorities = {"find-database"}) public void refreshViewMetadata_notOwner_fails() throws UserNotFoundException, DatabaseNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_2_ID)) + when(userService.findById(USER_2.getId())) .thenReturn(USER_2); /* test */ assertThrows(NotAllowedException.class, () -> { - databaseEndpoint.refreshViewMetadata(DATABASE_1_ID, USER_2_PRINCIPAL); + databaseEndpoint.refreshViewMetadata(DATABASE_1.getId(), USER_2_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void refreshViewMetadata_noRole_fails() throws UserNotFoundException, DatabaseNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); /* test */ assertThrows(AccessDeniedException.class, () -> { - databaseEndpoint.refreshViewMetadata(DATABASE_1_ID, USER_1_PRINCIPAL); + databaseEndpoint.refreshViewMetadata(DATABASE_1.getId(), USER_1_PRINCIPAL); }); } @@ -255,14 +258,14 @@ public class DatabaseEndpointUnitTest extends BaseTest { public void refreshViewMetadata_anonymous_fails() throws UserNotFoundException, DatabaseNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); /* test */ assertThrows(AccessDeniedException.class, () -> { - databaseEndpoint.refreshViewMetadata(DATABASE_1_ID, null); + databaseEndpoint.refreshViewMetadata(DATABASE_1.getId(), null); }); } @@ -279,11 +282,11 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"list-databases"}) + @WithMockUser(username = "junit1", authorities = {"list-databases"}) public void list_hasRole_succeeds() { /* pre-condition */ - assertTrue(DATABASE_3_PUBLIC); + assertTrue(DATABASE_3.getIsPublic()); /* mock */ when(databaseService.findAllPublicOrSchemaPublicOrReadAccess(any(UUID.class))) @@ -294,14 +297,14 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"list-databases"}) + @WithMockUser(username = "junit1", authorities = {"list-databases"}) public void list_hasRoleForeign_succeeds() { /* pre-condition */ - assertTrue(DATABASE_3_PUBLIC); + assertTrue(DATABASE_3.getIsPublic()); /* mock */ - when(databaseService.findAllPublicOrSchemaPublicOrReadAccess(USER_1_ID)) + when(databaseService.findAllPublicOrSchemaPublicOrReadAccess(USER_1.getId())) .thenReturn(List.of(DATABASE_3)); /* test */ @@ -309,23 +312,23 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"list-databases"}) + @WithMockUser(username = "junit1", authorities = {"list-databases"}) public void list_hasRoleFilter_succeeds() { /* mock */ - when(databaseService.findAllPublicOrSchemaPublicOrReadAccessByInternalName(USER_1_ID, DATABASE_3_INTERNALNAME)) + when(databaseService.findAllPublicOrSchemaPublicOrReadAccessByInternalName(USER_1.getId(), DATABASE_3.getInternalName())) .thenReturn(List.of(DATABASE_3)); /* test */ - list_generic(DATABASE_3_INTERNALNAME, USER_1_PRINCIPAL, 1); + list_generic(DATABASE_3.getInternalName(), USER_1_PRINCIPAL, 1); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"list-databases"}) + @WithMockUser(username = "junit1", authorities = {"list-databases"}) public void list_hasRoleFilterNoResult_succeeds() { /* mock */ - when(databaseService.findAllPublicOrSchemaPublicOrReadAccessByInternalName(USER_1_ID, "i_do_not_exist")) + when(databaseService.findAllPublicOrSchemaPublicOrReadAccessByInternalName(USER_1.getId(), "i_do_not_exist")) .thenReturn(List.of()); /* test */ @@ -349,11 +352,11 @@ public class DatabaseEndpointUnitTest extends BaseTest { public void list_hasSystemRoleFilterByName_succeeds() { /* mock */ - when(databaseService.findByInternalName(DATABASE_1_INTERNALNAME)) + when(databaseService.findByInternalName(DATABASE_1.getInternalName())) .thenReturn(List.of(DATABASE_1)); /* test */ - list_generic(DATABASE_1_INTERNALNAME, USER_LOCAL_ADMIN_PRINCIPAL, 1); + list_generic(DATABASE_1.getInternalName(), USER_LOCAL_ADMIN_PRINCIPAL, 1); } @Test @@ -377,12 +380,12 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - visibility_generic(DATABASE_1_ID, DATABASE_1, request, null); + visibility_generic(DATABASE_1.getId(), DATABASE_1, request, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-database-visibility"}) + @WithMockUser(username = "junit1", authorities = {"modify-database-visibility"}) public void visibility_hasRole_succeeds() throws NotAllowedException, UserNotFoundException, DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { @@ -391,15 +394,15 @@ public class DatabaseEndpointUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); /* test */ - visibility_generic(DATABASE_1_ID, DATABASE_1, request, USER_1_PRINCIPAL); + visibility_generic(DATABASE_1.getId(), DATABASE_1, request, USER_1_PRINCIPAL); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void visibility_noRole_fails() { final DatabaseModifyVisibilityDto request = DatabaseModifyVisibilityDto.builder() .isPublic(true) @@ -407,29 +410,29 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - visibility_generic(DATABASE_1_ID, DATABASE_1, request, USER_4_PRINCIPAL); + visibility_generic(DATABASE_1.getId(), DATABASE_1, request, USER_4_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-database-visibility"}) + @WithMockUser(username = "junit2", authorities = {"modify-database-visibility"}) public void visibility_hasRoleForeign_fails() throws UserNotFoundException { final DatabaseModifyVisibilityDto request = DatabaseModifyVisibilityDto.builder() .isPublic(true) .build(); /* mock */ - when(userService.findById(USER_2_ID)) + when(userService.findById(USER_2.getId())) .thenReturn(USER_2); /* test */ assertThrows(NotAllowedException.class, () -> { - visibility_generic(DATABASE_1_ID, DATABASE_1, request, USER_2_PRINCIPAL); + visibility_generic(DATABASE_1.getId(), DATABASE_1, request, USER_2_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_3_USERNAME) + @WithMockUser(username = "junit3") public void modifyImage_noRole_fails() { final DatabaseModifyImageDto request = DatabaseModifyImageDto.builder() .key("s3key_here") @@ -437,31 +440,31 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - databaseEndpoint.modifyImage(DATABASE_3_ID, request, USER_3_PRINCIPAL); + databaseEndpoint.modifyImage(DATABASE_3.getId(), request, USER_3_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-database-image"}) + @WithMockUser(username = "junit2", authorities = {"modify-database-image"}) public void modifyImage_notOwner_fails() throws DatabaseNotFoundException, UserNotFoundException { final DatabaseModifyImageDto request = DatabaseModifyImageDto.builder() .key("s3key_here") .build(); /* mock */ - when(databaseService.findById(DATABASE_3_ID)) + when(databaseService.findById(DATABASE_3.getId())) .thenReturn(DATABASE_3); - when(userService.findById(USER_2_ID)) + when(userService.findById(USER_2.getId())) .thenReturn(USER_2); /* test */ assertThrows(NotAllowedException.class, () -> { - databaseEndpoint.modifyImage(DATABASE_3_ID, request, USER_2_PRINCIPAL); + databaseEndpoint.modifyImage(DATABASE_3.getId(), request, USER_2_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-database-image"}) + @WithMockUser(username = "junit1", authorities = {"modify-database-image"}) public void modifyImage_succeeds() throws NotAllowedException, UserNotFoundException, DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException, StorageUnavailableException, StorageNotFoundException { @@ -470,19 +473,19 @@ public class DatabaseEndpointUnitTest extends BaseTest { .build(); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); when(storageService.getBytes(request.getKey())) .thenReturn(new byte[]{1, 2, 3, 4, 5}); /* test */ - databaseEndpoint.modifyImage(DATABASE_1_ID, request, USER_1_PRINCIPAL); + databaseEndpoint.modifyImage(DATABASE_1.getId(), request, USER_1_PRINCIPAL); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-database-image"}) + @WithMockUser(username = "junit1", authorities = {"modify-database-image"}) public void modifyImage_empty_succeeds() throws NotAllowedException, UserNotFoundException, DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException, StorageUnavailableException, StorageNotFoundException { @@ -491,79 +494,79 @@ public class DatabaseEndpointUnitTest extends BaseTest { .build(); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); /* test */ - databaseEndpoint.modifyImage(DATABASE_1_ID, request, USER_1_PRINCIPAL); + databaseEndpoint.modifyImage(DATABASE_1.getId(), request, USER_1_PRINCIPAL); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void transfer_noRole_fails() { final DatabaseTransferDto request = DatabaseTransferDto.builder() - .id(USER_4_ID) + .id(USER_4.getId()) .build(); /* test */ assertThrows(AccessDeniedException.class, () -> { - databaseEndpoint.transfer(DATABASE_3_ID, request, USER_4_PRINCIPAL); + databaseEndpoint.transfer(DATABASE_3.getId(), request, USER_4_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-database-owner"}) + @WithMockUser(username = "junit2", authorities = {"modify-database-owner"}) public void transfer_hasRoleForeign_fails() throws DatabaseNotFoundException, UserNotFoundException { final DatabaseTransferDto request = DatabaseTransferDto.builder() - .id(USER_4_ID) + .id(USER_4.getId()) .build(); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_2_ID)) + when(userService.findById(USER_2.getId())) .thenReturn(USER_2); - when(userService.findById(USER_4_ID)) + when(userService.findById(USER_4.getId())) .thenReturn(USER_4); /* test */ assertThrows(NotAllowedException.class, () -> { - databaseEndpoint.transfer(DATABASE_1_ID, request, USER_2_PRINCIPAL); + databaseEndpoint.transfer(DATABASE_1.getId(), request, USER_2_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-database-owner"}) + @WithMockUser(username = "junit1", authorities = {"modify-database-owner"}) public void transfer_hasRole_succeeds() throws DataServiceConnectionException, DataServiceException, NotAllowedException, UserNotFoundException, DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException { final DatabaseTransferDto request = DatabaseTransferDto.builder() - .id(USER_4_ID) + .id(USER_4.getId()) .build(); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); - when(userService.findById(USER_4_ID)) + when(userService.findById(USER_4.getId())) .thenReturn(USER_4); /* test */ - databaseEndpoint.transfer(DATABASE_1_ID, request, USER_1_PRINCIPAL); + databaseEndpoint.transfer(DATABASE_1.getId(), request, USER_1_PRINCIPAL); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-database-owner"}) + @WithMockUser(username = "junit1", authorities = {"modify-database-owner"}) public void transfer_hasRoleUserNotExists_succeeds() throws DatabaseNotFoundException, UserNotFoundException { final DatabaseTransferDto request = DatabaseTransferDto.builder() .id(UUID.randomUUID()) .build(); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); doThrow(UserNotFoundException.class) .when(userService) @@ -571,7 +574,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - databaseEndpoint.transfer(DATABASE_1_ID, request, USER_1_PRINCIPAL); + databaseEndpoint.transfer(DATABASE_1.getId(), request, USER_1_PRINCIPAL); }); } @@ -581,7 +584,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - findById_generic(DATABASE_1_ID, DATABASE_1, null); + findById_generic(DATABASE_1.getId(), DATABASE_1, null); }); } @@ -591,7 +594,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { DatabaseNotFoundException { /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_2_ID, DATABASE_2, null); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_2.getId(), DATABASE_2, null); final DatabaseDto database = response.getBody(); assertNotNull(database); assertEquals(3, database.getTables().size()); @@ -605,7 +608,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { DatabaseNotFoundException { /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_3_ID, DATABASE_3, USER_LOCAL_ADMIN_PRINCIPAL); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_3.getId(), DATABASE_3, USER_LOCAL_ADMIN_PRINCIPAL); final DatabaseDto database = response.getBody(); assertNotNull(database); assertEquals(1, database.getTables().size()); @@ -619,7 +622,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { DatabaseNotFoundException { /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1_ID, DATABASE_1, USER_LOCAL_ADMIN_PRINCIPAL); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1.getId(), DATABASE_1, USER_LOCAL_ADMIN_PRINCIPAL); final DatabaseDto database = response.getBody(); assertNotNull(database); assertEquals(4, database.getTables().size()); @@ -633,7 +636,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - findById_generic(DATABASE_1_ID, DATABASE_1, null); + findById_generic(DATABASE_1.getId(), DATABASE_1, null); }); } @@ -643,20 +646,20 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - findById_generic(DATABASE_1_ID, null, null); + findById_generic(DATABASE_1.getId(), null, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findById_ownerSeesAccessRights_succeeds() throws DatabaseNotFoundException, NotAllowedException { /* mock */ when(accessService.list(DATABASE_1)) - .thenReturn(List.of(DATABASE_1_USER_1_WRITE_ALL_ACCESS, DATABASE_1_USER_2_READ_ACCESS)); + .thenReturn(List.of(DATABASE_1.getAccesses().get(0), DATABASE_1.getAccesses().get(1))); /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1_ID, DATABASE_1, USER_1_PRINCIPAL); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1.getId(), DATABASE_1, USER_1_PRINCIPAL); final DatabaseDto database = response.getBody(); assertNotNull(database); assertEquals(4, database.getTables().size()); @@ -665,15 +668,15 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username = "junit2") public void findById_hiddenAccessRights_succeeds() throws DatabaseNotFoundException, NotAllowedException { /* mock */ when(accessService.list(DATABASE_1)) - .thenReturn(List.of(DATABASE_1_USER_1_WRITE_ALL_ACCESS, DATABASE_1_USER_2_READ_ACCESS)); + .thenReturn(List.of(DATABASE_1.getAccesses().get(0), DATABASE_1.getAccesses().get(1))); /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL); final DatabaseDto database = response.getBody(); assertNotNull(database); assertEquals(4, database.getTables().size()); @@ -682,15 +685,15 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findById_hiddenAccessRightsSeesOwn_succeeds() throws DatabaseNotFoundException, NotAllowedException { /* mock */ when(accessService.list(DATABASE_1)) - .thenReturn(List.of(DATABASE_1_USER_1_WRITE_ALL_ACCESS, DATABASE_1_USER_2_READ_ACCESS)); + .thenReturn(List.of(DATABASE_1.getAccesses().get(0), DATABASE_1.getAccesses().get(1))); /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1_ID, DATABASE_1, USER_1_PRINCIPAL); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1.getId(), DATABASE_1, USER_1_PRINCIPAL); final DatabaseDto database = response.getBody(); assertNotNull(database); assertEquals(4, database.getTables().size()); @@ -699,22 +702,22 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findById_privateDataPrivateSchemaNoAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - findById_generic(DATABASE_1_ID, DATABASE_1, USER_4_PRINCIPAL); + findById_generic(DATABASE_1.getId(), DATABASE_1, USER_4_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findById_anonymousPrivateDataPrivateSchema_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - findById_generic(DATABASE_1_ID, DATABASE_1, null); + findById_generic(DATABASE_1.getId(), DATABASE_1, null); }); } @@ -723,13 +726,13 @@ public class DatabaseEndpointUnitTest extends BaseTest { public void findById_system_succeeds() throws NotAllowedException, DatabaseNotFoundException { /* test */ - final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1_ID, DATABASE_1, USER_LOCAL_ADMIN_PRINCIPAL); + final ResponseEntity<DatabaseDto> response = findById_generic(DATABASE_1.getId(), DATABASE_1, USER_LOCAL_ADMIN_PRINCIPAL); final HttpHeaders headers = response.getHeaders(); - assertEquals(List.of(CONTAINER_1_HOST), headers.get("X-Host")); - assertEquals(List.of("" + CONTAINER_1_PORT), headers.get("X-Port")); + assertEquals(List.of(CONTAINER_1.getHost()), headers.get("X-Host")); + assertEquals(List.of("" + CONTAINER_1.getPort()), headers.get("X-Port")); assertEquals(List.of(CONTAINER_1_PRIVILEGED_USERNAME), headers.get("X-Username")); assertEquals(List.of(CONTAINER_1_PRIVILEGED_PASSWORD), headers.get("X-Password")); - assertEquals(List.of(IMAGE_1_JDBC), headers.get("X-Jdbc-Method")); + assertEquals(List.of(IMAGE_1.getJdbcMethod()), headers.get("X-Jdbc-Method")); assertEquals(List.of("X-Username X-Password X-Jdbc-Method X-Host X-Port"), headers.get("Access-Control-Expose-Headers")); } @@ -738,7 +741,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { public void findPreviewImage_anonymous_succeeds() throws DatabaseNotFoundException { /* test */ - final ResponseEntity<byte[]> response = findPreviewImage_generic(DATABASE_1_ID, DATABASE_1); + final ResponseEntity<byte[]> response = findPreviewImage_generic(DATABASE_1.getId(), DATABASE_1); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(MediaType.parseMediaType("image/webp"), response.getHeaders().getContentType()); final byte[] body = response.getBody(); @@ -746,11 +749,11 @@ public class DatabaseEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findPreviewImage_noRoles_succeeds() throws DatabaseNotFoundException { /* test */ - final ResponseEntity<byte[]> response = findPreviewImage_generic(DATABASE_1_ID, DATABASE_1); + final ResponseEntity<byte[]> response = findPreviewImage_generic(DATABASE_1.getId(), DATABASE_1); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(MediaType.parseMediaType("image/webp"), response.getHeaders().getContentType()); final byte[] body = response.getBody(); @@ -762,7 +765,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { public void findPreviewImage_noImage_succeeds() throws DatabaseNotFoundException { /* test */ - final ResponseEntity<byte[]> response = findPreviewImage_generic(DATABASE_2_ID, DATABASE_2); + final ResponseEntity<byte[]> response = findPreviewImage_generic(DATABASE_2.getId(), DATABASE_2); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(MediaType.parseMediaType("image/webp"), response.getHeaders().getContentType()); final byte[] body = response.getBody(); @@ -775,7 +778,7 @@ public class DatabaseEndpointUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - findPreviewImage_generic(DATABASE_1_ID, null); + findPreviewImage_generic(DATABASE_1.getId(), null); }); } @@ -806,7 +809,9 @@ public class DatabaseEndpointUnitTest extends BaseTest { when(databaseService.findById(any(UUID.class))) .thenReturn(DATABASE_1); when(dashboardService.create(DATABASE_1)) - .thenReturn(DATABASE_1_CREATE_DASHBOARD_RESPONSE_DTO); + .thenReturn(CreateDashboardResponseDto.builder() + .uid(DATABASE_1.getDashboardUid()) + .build()); /* test */ final ResponseEntity<DatabaseBriefDto> response = databaseEndpoint.create(data, principal); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/IdentifierEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/IdentifierEndpointUnitTest.java index 00cd00277a..a36b1737d1 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/IdentifierEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/IdentifierEndpointUnitTest.java @@ -9,6 +9,7 @@ import at.ac.tuwien.ifs.dbrepo.core.entity.identifier.Identifier; import at.ac.tuwien.ifs.dbrepo.core.entity.identifier.IdentifierType; import at.ac.tuwien.ifs.dbrepo.core.entity.user.User; import at.ac.tuwien.ifs.dbrepo.core.exception.*; +import at.ac.tuwien.ifs.dbrepo.core.mapper.MetadataMapper; import at.ac.tuwien.ifs.dbrepo.gateway.DataServiceGateway; import at.ac.tuwien.ifs.dbrepo.service.*; import at.ac.tuwien.ifs.dbrepo.core.test.BaseTest; @@ -76,15 +77,18 @@ public class IdentifierEndpointUnitTest extends BaseTest { @Autowired private ObjectMapper objectMapper; + @Autowired + private MetadataMapper metadataMapper; + @Autowired private EndpointConfig endpointConfig; public static Stream<Arguments> save_parameters() { return Stream.of( - Arguments.arguments("foreign_subset", DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_5, IDENTIFIER_5_SAVE_DTO, USER_1_PRINCIPAL, USER_1), - Arguments.arguments("foreign_database", DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1, IDENTIFIER_1_SAVE_DTO, USER_1_PRINCIPAL, USER_1), - Arguments.arguments("foreign_view", DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_3, IDENTIFIER_3_SAVE_DTO, USER_1_PRINCIPAL, USER_1), - Arguments.arguments("foreign_table", DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_4, IDENTIFIER_4_SAVE_DTO, USER_1_PRINCIPAL, USER_1) + Arguments.arguments("foreign_subset", DATABASE_2.getId(), DATABASE_2, null, IDENTIFIER_5, USER_1_PRINCIPAL, USER_1), + Arguments.arguments("foreign_database", DATABASE_1.getId(), DATABASE_1, null, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1), + Arguments.arguments("foreign_view", DATABASE_1.getId(), DATABASE_1, null, IDENTIFIER_3, USER_1_PRINCIPAL, USER_1), + Arguments.arguments("foreign_table", DATABASE_1.getId(), DATABASE_1, null, IDENTIFIER_4, USER_1_PRINCIPAL, USER_1) ); } @@ -122,56 +126,56 @@ public class IdentifierEndpointUnitTest extends BaseTest { public static Stream<Arguments> findAll_anonymousFilterDatabase_parameters() { return Stream.of( - Arguments.arguments("dbid", DATABASE_1_ID, null, null, null, null, 1), - Arguments.arguments("qid", DATABASE_1_ID, QUERY_1_ID, null, null, null, 1), - Arguments.arguments("vid", DATABASE_1_ID, null, VIEW_1_ID, null, null, 0), - Arguments.arguments("tid", DATABASE_1_ID, null, null, TABLE_1_ID, null, 0), - Arguments.arguments("status_published", DATABASE_1_ID, null, null, null, "PUBLISHED", 1), - Arguments.arguments("status_draft", DATABASE_1_ID, null, null, null, "DRAFT", 0) + Arguments.arguments("dbid", DATABASE_1.getId(), null, null, null, null, 1), + Arguments.arguments("qid", DATABASE_1.getId(), QUERY_1_ID, null, null, null, 1), + Arguments.arguments("vid", DATABASE_1.getId(), null, VIEW_1_ID, null, null, 0), + Arguments.arguments("tid", DATABASE_1.getId(), null, null, TABLE_1_ID, null, 0), + Arguments.arguments("status_published", DATABASE_1.getId(), null, null, null, "PUBLISHED", 1), + Arguments.arguments("status_draft", DATABASE_1.getId(), null, null, null, "DRAFT", 0) ); } public static Stream<Arguments> findAll_filterSubset_parameters() { return Stream.of( - Arguments.arguments("status_published", DATABASE_2_ID, null, null, null, "PUBLISHED", 0), - Arguments.arguments("status_draft", DATABASE_2_ID, null, null, null, "DRAFT", 1) + Arguments.arguments("status_published", DATABASE_2.getId(), null, null, null, "PUBLISHED", 0), + Arguments.arguments("status_draft", DATABASE_2.getId(), null, null, null, "DRAFT", 1) ); } public static Stream<Arguments> findAll_filterDatabase_parameters() { return Stream.of( - Arguments.arguments("database_dbid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, null, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("database_qid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, QUERY_1_ID, null, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("database_vid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, VIEW_1_ID, null, 0, USER_1_PRINCIPAL), - Arguments.arguments("database_tid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, null, TABLE_1_ID, 0, USER_1_PRINCIPAL), - Arguments.arguments("subset_dbid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, null, null, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("subset_qid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, QUERY_1_ID, null, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("subset_vid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, null, VIEW_1_ID, null, 0, USER_1_PRINCIPAL), - Arguments.arguments("subset_tid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, null, null, TABLE_1_ID, 0, USER_1_PRINCIPAL), - Arguments.arguments("view_dbid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, null, null, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("view_qid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, QUERY_1_ID, null, null, 0, USER_1_PRINCIPAL), - Arguments.arguments("view_vid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, null, VIEW_1_ID, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("view_tid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, null, null, TABLE_1_ID, 0, USER_1_PRINCIPAL), - Arguments.arguments("table_dbid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, null, null, null, 1, USER_1_PRINCIPAL), - Arguments.arguments("table_qid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, QUERY_1_ID, null, null, 0, USER_1_PRINCIPAL), - Arguments.arguments("table_vid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, null, VIEW_1_ID, null, 0, USER_1_PRINCIPAL), - Arguments.arguments("table_tid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, null, null, TABLE_1_ID, 1, USER_1_PRINCIPAL), - Arguments.arguments("anon_database_dbid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, null, null, 1, null), - Arguments.arguments("anon_database_qid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, QUERY_1_ID, null, null, 1, null), - Arguments.arguments("anon_database_vid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, VIEW_1_ID, null, 0, null), - Arguments.arguments("anon_database_tid", IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, null, TABLE_1_ID, 0, null), - Arguments.arguments("anon_subset_dbid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, null, null, null, 1, null), - Arguments.arguments("anon_subset_qid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, QUERY_1_ID, null, null, 1, null), - Arguments.arguments("anon_subset_vid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, null, VIEW_1_ID, null, 0, null), - Arguments.arguments("anon_subset_tid", IdentifierTypeDto.SUBSET, null, DATABASE_1_ID, null, null, TABLE_1_ID, 0, null), - Arguments.arguments("anon_view_dbid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, null, null, null, 1, null), - Arguments.arguments("anon_view_qid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, QUERY_1_ID, null, null, 0, null), - Arguments.arguments("anon_view_vid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, null, VIEW_1_ID, null, 1, null), - Arguments.arguments("anon_view_tid", IdentifierTypeDto.VIEW, null, DATABASE_1_ID, null, null, TABLE_1_ID, 0, null), - Arguments.arguments("anon_table_dbid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, null, null, null, 1, null), - Arguments.arguments("anon_table_qid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, QUERY_1_ID, null, null, 0, null), - Arguments.arguments("anon_table_vid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, null, VIEW_1_ID, null, 0, null), - Arguments.arguments("anon_table_tid", IdentifierTypeDto.TABLE, null, DATABASE_1_ID, null, null, TABLE_1_ID, 1, null) + Arguments.arguments("database_dbid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, null, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("database_qid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("database_vid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 0, USER_1_PRINCIPAL), + Arguments.arguments("database_tid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 0, USER_1_PRINCIPAL), + Arguments.arguments("subset_dbid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), null, null, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("subset_qid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("subset_vid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 0, USER_1_PRINCIPAL), + Arguments.arguments("subset_tid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 0, USER_1_PRINCIPAL), + Arguments.arguments("view_dbid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), null, null, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("view_qid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 0, USER_1_PRINCIPAL), + Arguments.arguments("view_vid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("view_tid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 0, USER_1_PRINCIPAL), + Arguments.arguments("table_dbid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), null, null, null, 1, USER_1_PRINCIPAL), + Arguments.arguments("table_qid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 0, USER_1_PRINCIPAL), + Arguments.arguments("table_vid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 0, USER_1_PRINCIPAL), + Arguments.arguments("table_tid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 1, USER_1_PRINCIPAL), + Arguments.arguments("anon_database_dbid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, null, null, 1, null), + Arguments.arguments("anon_database_qid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 1, null), + Arguments.arguments("anon_database_vid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 0, null), + Arguments.arguments("anon_database_tid", IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 0, null), + Arguments.arguments("anon_subset_dbid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), null, null, null, 1, null), + Arguments.arguments("anon_subset_qid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 1, null), + Arguments.arguments("anon_subset_vid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 0, null), + Arguments.arguments("anon_subset_tid", IdentifierTypeDto.SUBSET, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 0, null), + Arguments.arguments("anon_view_dbid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), null, null, null, 1, null), + Arguments.arguments("anon_view_qid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 0, null), + Arguments.arguments("anon_view_vid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 1, null), + Arguments.arguments("anon_view_tid", IdentifierTypeDto.VIEW, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 0, null), + Arguments.arguments("anon_table_dbid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), null, null, null, 1, null), + Arguments.arguments("anon_table_qid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), QUERY_1_ID, null, null, 0, null), + Arguments.arguments("anon_table_vid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), null, VIEW_1_ID, null, 0, null), + Arguments.arguments("anon_table_tid", IdentifierTypeDto.TABLE, null, DATABASE_1.getId(), null, null, TABLE_1_ID, 1, null) ); } @@ -231,7 +235,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { @ParameterizedTest @MethodSource("findAll_filterSubset_parameters") - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username = "junit2") public void findAll_filterSubset_succeeds(String name, UUID databaseId, UUID queryId, UUID viewId, UUID tableId, IdentifierStatusTypeDto status, Integer expectedSize) { @@ -372,7 +376,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void find_draftNotOwner_fails() throws IdentifierNotFoundException { /* mock */ @@ -386,7 +390,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username = "junit2") public void find_draft_succeeds() throws IdentifierNotFoundException, MalformedException, NotAllowedException, DataServiceException, QueryNotFoundException, DataServiceConnectionException, FormatNotAvailableException, TableNotFoundException, ViewNotFoundException { @@ -406,15 +410,15 @@ public class IdentifierEndpointUnitTest extends BaseTest { FormatNotAvailableException, TableNotFoundException, ViewNotFoundException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - identifierEndpoint.find(IDENTIFIER_1_ID, "text/html", null); + identifierEndpoint.find(IDENTIFIER_1.getId(), "text/html", null); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void find_json0_succeeds() throws IOException, MalformedException, DataServiceException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -422,11 +426,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { final IdentifierDto compare = objectMapper.readValue(FileUtils.readFileToString(new File("src/test/resources/json/metadata0.json"), StandardCharsets.UTF_8), IdentifierDto.class); /* mock */ - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7_ID, accept, USER_4_PRINCIPAL); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7.getId(), accept, USER_4_PRINCIPAL); assertEquals(HttpStatus.OK, response.getStatusCode()); final IdentifierDto body = (IdentifierDto) response.getBody(); assertNotNull(body); @@ -452,11 +456,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { final IdentifierDto compare = objectMapper.readValue(FileUtils.readFileToString(new File("src/test/resources/json/metadata1.json"), StandardCharsets.UTF_8), IdentifierDto.class); /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final IdentifierDto body = (IdentifierDto) response.getBody(); assertNotNull(body); @@ -505,11 +509,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_1, BibliographyTypeDto.APA)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -527,17 +531,17 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_7, BibliographyTypeDto.APA)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); /* test */ assertThrows(NotAllowedException.class, () -> { - identifierEndpoint.find(IDENTIFIER_7_ID, accept, null); + identifierEndpoint.find(IDENTIFIER_7.getId(), accept, null); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void find_bibliographyApa0_succeeds() throws IOException, MalformedException, DataServiceException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -548,11 +552,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_7, BibliographyTypeDto.APA)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7_ID, accept, USER_4_PRINCIPAL); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7.getId(), accept, USER_4_PRINCIPAL); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -571,11 +575,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_1, BibliographyTypeDto.APA)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -583,7 +587,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username = "junit2") public void find_draftBibliographyApa2_succeeds() throws IOException, MalformedException, DataServiceException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -640,11 +644,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(any(Identifier.class), eq(BibliographyTypeDto.APA))) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1_WITH_DOI); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -652,7 +656,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void find_bibliographyIeee0_succeeds() throws IOException, MalformedException, DataServiceException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -663,11 +667,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_7, BibliographyTypeDto.IEEE)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7_ID, accept, USER_4_PRINCIPAL); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7.getId(), accept, USER_4_PRINCIPAL); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -686,11 +690,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_1, BibliographyTypeDto.IEEE)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -698,7 +702,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username = "junit2") public void find_bibliographyIeee2_succeeds() throws IOException, MalformedException, DataServiceException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -732,11 +736,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(any(Identifier.class), eq(BibliographyTypeDto.IEEE))) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1_WITH_DOI); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -744,7 +748,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void find_bibliographyBibtex0_succeeds() throws IOException, MalformedException, DataServiceException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -755,11 +759,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_7, BibliographyTypeDto.BIBTEX)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7_ID, accept, USER_4_PRINCIPAL); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_7.getId(), accept, USER_4_PRINCIPAL); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -778,11 +782,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(IDENTIFIER_1, BibliographyTypeDto.BIBTEX)) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -790,7 +794,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username = "junit2") public void find_bibliographyBibtex2_succeeds() throws MalformedException, DataServiceException, IOException, DataServiceConnectionException, QueryNotFoundException, IdentifierNotFoundException, FormatNotAvailableException, NotAllowedException, TableNotFoundException, ViewNotFoundException { @@ -824,11 +828,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* mock */ when(identifierService.exportBibliography(any(Identifier.class), eq(BibliographyTypeDto.BIBTEX))) .thenReturn(compare); - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1_WITH_DOI); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final String body = (String) response.getBody(); assertNotNull(body); @@ -843,11 +847,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { final String accept = "application/ld+json"; /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final LdDatasetDto body = (LdDatasetDto) response.getBody(); assertNotNull(body); @@ -859,12 +863,12 @@ public class IdentifierEndpointUnitTest extends BaseTest { final String accept = "text/csv"; /* mock */ - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); /* test */ assertThrows(NotAllowedException.class, () -> { - identifierEndpoint.find(IDENTIFIER_7_ID, accept, null); + identifierEndpoint.find(IDENTIFIER_7.getId(), accept, null); }); } @@ -875,11 +879,11 @@ public class IdentifierEndpointUnitTest extends BaseTest { TableNotFoundException, ViewNotFoundException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, null, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), null, null); assertEquals(HttpStatus.MOVED_PERMANENTLY, response.getStatusCode()); } @@ -892,7 +896,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {}) + @WithMockUser(username = "junit1", authorities = {}) public void delete_noRole_fails() { /* test */ @@ -900,7 +904,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-identifier"}) + @WithMockUser(username = "junit2", authorities = {"delete-identifier"}) public void delete_hasRole_succeeds() throws NotAllowedException, DataServiceException, DataServiceConnectionException, DatabaseNotFoundException, IdentifierNotFoundException, SearchServiceException, SearchServiceConnectionException { @@ -910,13 +914,13 @@ public class IdentifierEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-identifier"}) + @WithMockUser(username = "junit2", authorities = {"delete-identifier"}) public void delete_alreadyPublished_fails() throws DataServiceException, DataServiceConnectionException, DatabaseNotFoundException, IdentifierNotFoundException, SearchServiceException, SearchServiceConnectionException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); doNothing() .when(identifierService) @@ -924,7 +928,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - identifierEndpoint.delete(IDENTIFIER_1_ID); + identifierEndpoint.delete(IDENTIFIER_1.getId()); }); } @@ -934,47 +938,47 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - identifierEndpoint.publish(IDENTIFIER_1_ID); + identifierEndpoint.publish(IDENTIFIER_1.getId()); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void publish_noRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - identifierEndpoint.publish(IDENTIFIER_1_ID); + identifierEndpoint.publish(IDENTIFIER_1.getId()); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"publish-identifier"}) + @WithMockUser(username = "junit1", authorities = {"publish-identifier"}) public void publish_succeeds() throws IdentifierNotFoundException, SearchServiceException, MalformedException, DatabaseNotFoundException, ExternalServiceException, SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); when(identifierService.publish(IDENTIFIER_1)) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<IdentifierDto> response = identifierEndpoint.publish(IDENTIFIER_1_ID); + final ResponseEntity<IdentifierDto> response = identifierEndpoint.publish(IDENTIFIER_1.getId()); assertEquals(HttpStatus.CREATED, response.getStatusCode()); final IdentifierDto body = response.getBody(); assertNotNull(body); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"publish-identifier"}) + @WithMockUser(username = "junit1", authorities = {"publish-identifier"}) public void publish_searchService_fails() throws IdentifierNotFoundException, SearchServiceException, MalformedException, DatabaseNotFoundException, ExternalServiceException, SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); doThrow(SearchServiceException.class) .when(identifierService) @@ -982,18 +986,18 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(SearchServiceException.class, () -> { - identifierEndpoint.publish(IDENTIFIER_1_ID); + identifierEndpoint.publish(IDENTIFIER_1.getId()); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"publish-identifier"}) + @WithMockUser(username = "junit1", authorities = {"publish-identifier"}) public void publish_searchServiceConnection_fails() throws IdentifierNotFoundException, SearchServiceException, MalformedException, DatabaseNotFoundException, ExternalServiceException, SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); doThrow(SearchServiceConnectionException.class) .when(identifierService) @@ -1001,22 +1005,22 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(SearchServiceConnectionException.class, () -> { - identifierEndpoint.publish(IDENTIFIER_1_ID); + identifierEndpoint.publish(IDENTIFIER_1.getId()); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"publish-identifier"}) + @WithMockUser(username = "junit1", authorities = {"publish-identifier"}) public void publish_notFound_fails() throws IdentifierNotFoundException { /* mock */ doThrow(IdentifierNotFoundException.class) .when(identifierService) - .find(IDENTIFIER_1_ID); + .find(IDENTIFIER_1.getId()); /* test */ assertThrows(IdentifierNotFoundException.class, () -> { - identifierEndpoint.publish(IDENTIFIER_1_ID); + identifierEndpoint.publish(IDENTIFIER_1.getId()); }); } @@ -1028,24 +1032,24 @@ public class IdentifierEndpointUnitTest extends BaseTest { final String accept = "application/json"; /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + final ResponseEntity<?> response = identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final IdentifierDto body = (IdentifierDto) response.getBody(); assertNotNull(body); final List<IdentifierTitleDto> titles = body.getTitles(); assertEquals(2, titles.size()); final IdentifierTitleDto title0 = titles.get(0); - assertEquals(IDENTIFIER_1_TITLE_1_TITLE, title0.getTitle()); - assertEquals(IDENTIFIER_1_TITLE_1_LANG_DTO, title0.getLanguage()); + assertEquals(IDENTIFIER_1.getTitles().get(0).getTitle(), title0.getTitle()); + assertEquals(IDENTIFIER_1.getTitles().get(0).getLanguage(), metadataMapper.languageTypeDtoToLanguageType(title0.getLanguage())); final List<IdentifierDescriptionDto> descriptions = body.getDescriptions(); assertEquals(1, descriptions.size()); final IdentifierDescriptionDto description0 = descriptions.get(0); - assertEquals(IDENTIFIER_1_DESCRIPTION_1_DESCRIPTION, description0.getDescription()); - assertEquals(IDENTIFIER_1_DESCRIPTION_1_LANG_DTO, description0.getLanguage()); + assertEquals(IDENTIFIER_1.getDescriptions().get(0).getDescription(), description0.getDescription()); + assertEquals(IDENTIFIER_1.getDescriptions().get(0).getLanguage(), metadataMapper.languageTypeDtoToLanguageType(description0.getLanguage())); } @Test @@ -1075,55 +1079,55 @@ public class IdentifierEndpointUnitTest extends BaseTest { final ResponseEntity<?> response = generic_find(null, null); assertEquals(HttpStatus.MOVED_PERMANENTLY, response.getStatusCode()); assertNotNull(response.getHeaders().get("Location")); - assertEquals(endpointConfig.getWebsiteUrl() + "/database/" + DATABASE_1_ID + "/info?pid=" + IDENTIFIER_1_ID, + assertEquals(endpointConfig.getWebsiteUrl() + "/database/" + DATABASE_1.getId() + "/info?pid=" + IDENTIFIER_1.getId(), response.getHeaders().getFirst("Location")); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_succeeds() throws MalformedException, NotAllowedException, DataServiceException, DataServiceConnectionException, UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, QueryNotFoundException, IdentifierNotFoundException, ViewNotFoundException, SearchServiceException, SearchServiceConnectionException, TableNotFoundException, ExternalServiceException { /* test */ - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, IDENTIFIER_1_SAVE_DTO, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1), USER_1_PRINCIPAL, USER_1); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_noAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1, IDENTIFIER_1_SAVE_DTO, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, null, IDENTIFIER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1), USER_1_PRINCIPAL, USER_1); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit2", authorities = {"create-identifier"}) public void save_readAccessQuery_succeeds() throws MalformedException, NotAllowedException, DataServiceException, DataServiceConnectionException, UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, QueryNotFoundException, IdentifierNotFoundException, ViewNotFoundException, SearchServiceException, SearchServiceConnectionException, TableNotFoundException, ExternalServiceException { /* mock */ - when(dataServiceGateway.findQuery(DATABASE_2_ID, QUERY_2_ID)) + when(dataServiceGateway.findQuery(DATABASE_2.getId(), QUERY_2_DTO.getId())) .thenReturn(QUERY_2_DTO); /* test */ - generic_save(DATABASE_2_ID, DATABASE_2, DATABASE_2_USER_1_READ_ACCESS, IDENTIFIER_5, IDENTIFIER_5_SAVE_DTO, USER_2_PRINCIPAL, USER_2); + generic_save(DATABASE_2.getId(), DATABASE_2, DATABASE_2.getAccesses().get(0), IDENTIFIER_5, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_5), USER_2_PRINCIPAL, USER_2); } @ParameterizedTest @MethodSource("malformedSubset_parameters") - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_malformedSubset_fails(String name, UUID queryId, UUID viewId, UUID tableId) { final IdentifierSaveDto request = IdentifierSaveDto.builder() .queryId(queryId) .viewId(viewId) .tableId(tableId) - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of()) @@ -1136,19 +1140,19 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @ParameterizedTest @MethodSource("malformedView_parameters") - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_malformedView_fails(String name, UUID queryId, UUID viewId, UUID tableId) { final IdentifierSaveDto request = IdentifierSaveDto.builder() .queryId(queryId) .viewId(viewId) .tableId(tableId) - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of()) @@ -1161,19 +1165,19 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @ParameterizedTest @MethodSource("malformedTable_parameters") - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_malformedTable_fails(String name, UUID queryId, UUID viewId, UUID tableId) { final IdentifierSaveDto request = IdentifierSaveDto.builder() .queryId(queryId) .viewId(viewId) .tableId(tableId) - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of()) @@ -1186,19 +1190,19 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @ParameterizedTest @MethodSource("malformedDatabase_parameters") - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_malformedDatabase_fails(String name, UUID queryId, UUID viewId, UUID tableId) { final IdentifierSaveDto request = IdentifierSaveDto.builder() .queryId(queryId) .viewId(viewId) .tableId(tableId) - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of()) @@ -1211,15 +1215,15 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_invalidDateDay_fails() { final IdentifierSaveDto request = IdentifierSaveDto.builder() - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of(IDENTIFIER_1_RELATED_IDENTIFIER_5_CREATE_DTO)) @@ -1233,15 +1237,15 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_invalidDateMonth_fails() { final IdentifierSaveDto request = IdentifierSaveDto.builder() - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of(IDENTIFIER_1_RELATED_IDENTIFIER_5_CREATE_DTO)) @@ -1255,32 +1259,32 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @ParameterizedTest @MethodSource("save_foreign_parameters") - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_foreign_fails(String name, Identifier identifier, IdentifierSaveDto data) throws UserNotFoundException { /* mock */ - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); /* test */ assertThrows(NotAllowedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, null, identifier, data, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, null, identifier, data, USER_1_PRINCIPAL, USER_1); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_invalidTable_fails() { final IdentifierSaveDto request = IdentifierSaveDto.builder() .viewId(UUID.randomUUID()) // <-- - .databaseId(DATABASE_1_ID) + .databaseId(DATABASE_1.getId()) .descriptions(List.of(IDENTIFIER_1_DESCRIPTION_1_CREATE_DTO)) .titles(List.of(IDENTIFIER_1_TITLE_1_CREATE_DTO)) .relatedIdentifiers(List.of(IDENTIFIER_1_RELATED_IDENTIFIER_5_CREATE_DTO)) @@ -1294,19 +1298,20 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_save(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); + generic_save(DATABASE_1.getId(), DATABASE_1, DATABASE_1.getAccesses().get(0), IDENTIFIER_1, request, USER_1_PRINCIPAL, USER_1); }); } @ParameterizedTest @MethodSource("save_parameters") - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void save_noForeign_fails(String name, UUID databaseId, Database database, DatabaseAccess access, - Identifier identifier, IdentifierSaveDto data, Principal principal, User user) { + Identifier identifier, Principal principal, User user) { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_save(databaseId, database, access, identifier, data, principal, user); + generic_save(databaseId, database, access, identifier, + metadataMapper.identifierToIdentifierSaveDto(identifier), principal, user); }); } @@ -1316,53 +1321,54 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, USER_1_PRINCIPAL); + identifierEndpoint.create(metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), USER_1_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void create_noRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, USER_1_PRINCIPAL); + identifierEndpoint.create(metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), USER_1_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void create_succeeds() throws DatabaseNotFoundException, UserNotFoundException, AccessNotFoundException, SearchServiceException, MalformedException, DataServiceException, QueryNotFoundException, ExternalServiceException, SearchServiceConnectionException, DataServiceConnectionException, IdentifierNotFoundException, ViewNotFoundException, NotAllowedException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); when(accessService.find(DATABASE_1, USER_1)) - .thenReturn(DATABASE_1_USER_1_READ_ACCESS); - when(identifierService.create(DATABASE_1, USER_1, IDENTIFIER_1_CREATE_DTO)) + .thenReturn(DATABASE_1.getAccesses().get(0)); + when(identifierService.create(DATABASE_1, USER_1, metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1))) .thenReturn(IDENTIFIER_1); /* test */ - final ResponseEntity<IdentifierDto> response = identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, USER_1_PRINCIPAL); + final ResponseEntity<IdentifierDto> response = identifierEndpoint.create( + metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), USER_1_PRINCIPAL); assertEquals(HttpStatus.CREATED, response.getStatusCode()); final IdentifierDto body = response.getBody(); assertNotNull(body); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void create_noAccess_fails() throws DatabaseNotFoundException, UserNotFoundException, AccessNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_1_ID)) + when(userService.findById(USER_1.getId())) .thenReturn(USER_1); doThrow(AccessNotFoundException.class) .when(accessService) @@ -1370,12 +1376,12 @@ public class IdentifierEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, USER_1_PRINCIPAL); + identifierEndpoint.create(metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), USER_1_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-foreign-identifier"}) + @WithMockUser(username = "junit2", authorities = {"create-foreign-identifier"}) public void create_hasForeign_succeeds() throws DatabaseNotFoundException, UserNotFoundException, AccessNotFoundException, SearchServiceException, MalformedException, NotAllowedException, DataServiceException, QueryNotFoundException, ExternalServiceException, SearchServiceConnectionException, @@ -1384,30 +1390,30 @@ public class IdentifierEndpointUnitTest extends BaseTest { new SimpleGrantedAuthority("create-foreign-identifier"))); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); - when(userService.findById(USER_2_ID)) + when(userService.findById(USER_2.getId())) .thenReturn(USER_2); doThrow(AccessNotFoundException.class) .when(accessService) .find(DATABASE_1, USER_2); /* test */ - identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, principal); + identifierEndpoint.create(metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), principal); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier"}) public void create_databaseNotFound_fails() throws DatabaseNotFoundException { /* mock */ doThrow(DatabaseNotFoundException.class) .when(databaseService) - .findById(DATABASE_1_ID); + .findById(DATABASE_1.getId()); /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, USER_1_PRINCIPAL); + identifierEndpoint.create(metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), USER_1_PRINCIPAL); }); } @@ -1442,7 +1448,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { .find(database, user); } if (identifier.getType().equals(IdentifierType.SUBSET)) { - when(dataServiceGateway.findQuery(databaseId, QUERY_2_ID)) + when(dataServiceGateway.findQuery(databaseId, QUERY_2_DTO.getId())) .thenReturn(QUERY_2_DTO); } when(identifierService.find(identifier.getId())) @@ -1472,7 +1478,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { ViewNotFoundException { /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); if (resource != null) { when(identifierService.exportMetadata(IDENTIFIER_1)) @@ -1480,7 +1486,7 @@ public class IdentifierEndpointUnitTest extends BaseTest { } /* test */ - return identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); + return identifierEndpoint.find(IDENTIFIER_1.getId(), accept, null); } protected void generic_delete() throws NotAllowedException, DataServiceException, DataServiceConnectionException, @@ -1488,14 +1494,14 @@ public class IdentifierEndpointUnitTest extends BaseTest { SearchServiceConnectionException { /* mock */ - when(identifierService.find(IDENTIFIER_7_ID)) + when(identifierService.find(IDENTIFIER_7.getId())) .thenReturn(IDENTIFIER_7); doNothing() .when(identifierService) .delete(IDENTIFIER_7); /* test */ - final ResponseEntity<?> response = identifierEndpoint.delete(IDENTIFIER_7_ID); + final ResponseEntity<?> response = identifierEndpoint.delete(IDENTIFIER_7.getId()); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertNull(response.getBody()); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ImageEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ImageEndpointUnitTest.java index 3a8edc222b..3b5081582b 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ImageEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ImageEndpointUnitTest.java @@ -8,6 +8,7 @@ import at.ac.tuwien.ifs.dbrepo.core.entity.container.image.ContainerImage; import at.ac.tuwien.ifs.dbrepo.core.exception.ImageAlreadyExistsException; import at.ac.tuwien.ifs.dbrepo.core.exception.ImageInvalidException; import at.ac.tuwien.ifs.dbrepo.core.exception.ImageNotFoundException; +import at.ac.tuwien.ifs.dbrepo.core.mapper.MetadataMapper; import at.ac.tuwien.ifs.dbrepo.core.test.BaseTest; import at.ac.tuwien.ifs.dbrepo.service.impl.ImageServiceImpl; import lombok.extern.log4j.Log4j2; @@ -22,7 +23,6 @@ import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.junit.jupiter.SpringExtension; -import java.io.IOException; import java.security.Principal; import java.util.List; import java.util.UUID; @@ -41,6 +41,9 @@ public class ImageEndpointUnitTest extends BaseTest { @Autowired private ImageEndpoint imageEndpoint; + @Autowired + private MetadataMapper metadataMapper; + @Test @WithAnonymousUser public void findAll_anonymous_succeeds() { @@ -50,7 +53,7 @@ public class ImageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-image"}) + @WithMockUser(username = "junit1", authorities = {"find-image"}) public void findAll_hasRole_succeeds() { /* test */ @@ -58,7 +61,7 @@ public class ImageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void findAll_noRole_succeeds() { /* test */ @@ -69,11 +72,11 @@ public class ImageEndpointUnitTest extends BaseTest { @WithAnonymousUser public void create_anonymous_fails() { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) - .version(IMAGE_1_VERSION) - .defaultPort(IMAGE_1_PORT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) + .name(IMAGE_1.getName()) + .version(IMAGE_1.getVersion()) + .defaultPort(IMAGE_1.getDefaultPort()) + .dialect(IMAGE_1.getDialect()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) .build(); /* test */ @@ -83,14 +86,14 @@ public class ImageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"create-image"}) + @WithMockUser(username = "junit1", roles = {"create-image"}) public void create_hasRole_fails() { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) - .version(IMAGE_1_VERSION) - .defaultPort(IMAGE_1_PORT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) + .name(IMAGE_1.getName()) + .version(IMAGE_1.getVersion()) + .defaultPort(IMAGE_1.getDefaultPort()) + .dialect(IMAGE_1.getDialect()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) .build(); /* test */ @@ -100,14 +103,14 @@ public class ImageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRole_fails() { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) - .version(IMAGE_1_VERSION) - .defaultPort(IMAGE_1_PORT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) + .name(IMAGE_1.getName()) + .version(IMAGE_1.getVersion()) + .defaultPort(IMAGE_1.getDefaultPort()) + .dialect(IMAGE_1.getDialect()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) .build(); /* test */ @@ -117,18 +120,18 @@ public class ImageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-image"}) + @WithMockUser(username = "junit1", authorities = {"create-image"}) public void create_succeeds() throws ImageAlreadyExistsException, ImageInvalidException { /* test */ - create_generic(IMAGE_1_CREATE_DTO, USER_1_PRINCIPAL); + create_generic(metadataMapper.containerImageToImageCreateDto(IMAGE_1), USER_1_PRINCIPAL); } @Test public void findById_anonymous_succeeds() throws ImageNotFoundException { /* test */ - findById_generic(IMAGE_1_ID, IMAGE_1); + findById_generic(CONTAINER_1.getId(), IMAGE_1); } @Test @@ -137,11 +140,11 @@ public class ImageEndpointUnitTest extends BaseTest { /* mock */ doThrow(ImageNotFoundException.class) .when(imageService) - .find(CONTAINER_1_ID); + .find(CONTAINER_1.getId()); /* test */ assertThrows(ImageNotFoundException.class, () -> { - imageEndpoint.findById(CONTAINER_1_ID); + imageEndpoint.findById(CONTAINER_1.getId()); }); } @@ -151,22 +154,22 @@ public class ImageEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - delete_generic(IMAGE_1_ID, IMAGE_1); + delete_generic(CONTAINER_1.getId(), IMAGE_1); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void delete_noRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - delete_generic(IMAGE_1_ID, IMAGE_1); + delete_generic(CONTAINER_1.getId(), IMAGE_1); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-image"}) + @WithMockUser(username = "junit2", authorities = {"delete-image"}) public void delete_hasRole_succeeds() throws ImageNotFoundException { /* mock */ @@ -175,54 +178,54 @@ public class ImageEndpointUnitTest extends BaseTest { .delete(IMAGE_1); /* test */ - delete_generic(IMAGE_1_ID, IMAGE_1); + delete_generic(CONTAINER_1.getId(), IMAGE_1); } @Test @WithAnonymousUser public void modify_anonymous_fails() { final ImageChangeDto request = ImageChangeDto.builder() - .defaultPort(IMAGE_1_PORT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) - .driverClass(IMAGE_1_DRIVER) + .defaultPort(IMAGE_1.getDefaultPort()) + .dialect(IMAGE_1.getDialect()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) + .driverClass(IMAGE_1.getDriverClass()) .build(); /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - modify_generic(IMAGE_1_ID, IMAGE_1, request); + modify_generic(CONTAINER_1.getId(), IMAGE_1, request); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void modify_noRole_fails() { final ImageChangeDto request = ImageChangeDto.builder() - .defaultPort(IMAGE_1_PORT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) - .driverClass(IMAGE_1_DRIVER) + .defaultPort(IMAGE_1.getDefaultPort()) + .dialect(IMAGE_1.getDialect()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) + .driverClass(IMAGE_1.getDriverClass()) .build(); /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - modify_generic(IMAGE_1_ID, IMAGE_1, request); + modify_generic(CONTAINER_1.getId(), IMAGE_1, request); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-image"}) + @WithMockUser(username = "junit2", authorities = {"modify-image"}) public void modify_hasRole_succeeds() throws ImageNotFoundException { final ImageChangeDto request = ImageChangeDto.builder() - .registry(IMAGE_1_REGISTRY) - .defaultPort(IMAGE_1_PORT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) - .driverClass(IMAGE_1_DRIVER) + .registry(IMAGE_1.getRegistry()) + .defaultPort(IMAGE_1.getDefaultPort()) + .dialect(IMAGE_1.getDialect()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) + .driverClass(IMAGE_1.getDriverClass()) .build(); /* test */ - modify_generic(IMAGE_1_ID, IMAGE_1, request); + modify_generic(CONTAINER_1.getId(), IMAGE_1, request); } /* ################################################################################################### */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MessageEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MessageEndpointUnitTest.java index e3ce1f25f9..fa2aec75d0 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MessageEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MessageEndpointUnitTest.java @@ -45,7 +45,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void list_noRole_succeeds() { /* test */ @@ -75,7 +75,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void find_noRole_succeeds() throws MessageNotFoundException { /* test */ @@ -83,7 +83,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-maintenance-message"}) + @WithMockUser(username = "junit1", authorities = {"find-maintenance-message"}) public void find_hasRole_succeeds() throws MessageNotFoundException { /* test */ @@ -91,7 +91,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-maintenance-message"}) + @WithMockUser(username = "junit1", authorities = {"find-maintenance-message"}) public void find_hasRoleNotFound_fails() { /* test */ @@ -111,7 +111,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRole_fails() { /* test */ @@ -121,7 +121,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-maintenance-message"}) + @WithMockUser(username ="junit2", authorities = {"create-maintenance-message"}) public void create_hasRole_succeeds() { /* test */ @@ -139,7 +139,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void update_noRole_fails() { /* test */ @@ -149,7 +149,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"update-maintenance-message"}) + @WithMockUser(username ="junit2", authorities = {"update-maintenance-message"}) public void update_hasRole_succeeds() throws MessageNotFoundException { /* test */ @@ -167,7 +167,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void delete_noRole_fails() { /* test */ @@ -177,7 +177,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-maintenance-message"}) + @WithMockUser(username ="junit2", authorities = {"delete-maintenance-message"}) public void delete_hasRole_succeeds() throws MessageNotFoundException { /* test */ @@ -185,7 +185,7 @@ public class MessageEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-maintenance-message"}) + @WithMockUser(username ="junit2", authorities = {"delete-maintenance-message"}) public void delete_hasRoleNotFound_fails() { /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MetadataEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MetadataEndpointUnitTest.java index 012ca1f1c0..c0649b93c6 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MetadataEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/MetadataEndpointUnitTest.java @@ -89,7 +89,7 @@ public class MetadataEndpointUnitTest extends BaseTest { final OaiRecordParameters parameters = new OaiRecordParameters(); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -106,7 +106,7 @@ public class MetadataEndpointUnitTest extends BaseTest { parameters.setMetadataPrefix("oai_marc"); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -123,7 +123,7 @@ public class MetadataEndpointUnitTest extends BaseTest { parameters.setMetadataPrefix("oai_dc"); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -138,10 +138,10 @@ public class MetadataEndpointUnitTest extends BaseTest { public void getRecord_dc_succeeds() { final OaiRecordParameters parameters = new OaiRecordParameters(); parameters.setMetadataPrefix("oai_dc"); - parameters.setIdentifier("oai:" + IDENTIFIER_1_ID); + parameters.setIdentifier("oai:" + IDENTIFIER_1.getId()); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -158,10 +158,10 @@ public class MetadataEndpointUnitTest extends BaseTest { public void getRecord_datacite_succeeds() { final OaiRecordParameters parameters = new OaiRecordParameters(); parameters.setMetadataPrefix("oai_datacite"); - parameters.setIdentifier("oai:" + IDENTIFIER_1_ID); + parameters.setIdentifier("oai:" + IDENTIFIER_1.getId()); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -178,10 +178,10 @@ public class MetadataEndpointUnitTest extends BaseTest { public void getRecord_invalidIdentifierPrefix_succeeds() { final OaiRecordParameters parameters = new OaiRecordParameters(); parameters.setMetadataPrefix("oai_datacite"); - parameters.setIdentifier("ark:" + IDENTIFIER_1_ID); + parameters.setIdentifier("ark:" + IDENTIFIER_1.getId()); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -199,7 +199,7 @@ public class MetadataEndpointUnitTest extends BaseTest { parameters.setIdentifier("oai:" + UUID.randomUUID()); /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ @@ -214,7 +214,7 @@ public class MetadataEndpointUnitTest extends BaseTest { public void listMetadataFormats_succeeds() { /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/OntologyEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/OntologyEndpointUnitTest.java index 5cce9f9550..34a0c2dcbd 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/OntologyEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/OntologyEndpointUnitTest.java @@ -61,7 +61,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void findAll_noRole_succeeds() { /* test */ @@ -77,7 +77,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"execute-semantic-query"}) + @WithMockUser(username = "junit1", authorities = {"execute-semantic-query"}) public void find_noSparql_fails() throws OntologyNotFoundException { final UUID id = UUID.randomUUID(); final Ontology mock = Ontology.builder() @@ -108,7 +108,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void find_noRole_succeeds() throws OntologyNotFoundException { /* test */ @@ -126,21 +126,21 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void create_noRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - create_generic(ONTOLOGY_1_CREATE_DTO, USER_4_PRINCIPAL, USER_4_USERNAME, USER_4, ONTOLOGY_1); + create_generic(ONTOLOGY_1_CREATE_DTO, USER_4_PRINCIPAL, "junit4", USER_4, ONTOLOGY_1); }); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-ontology"}) + @WithMockUser(username ="junit3", authorities = {"create-ontology"}) public void create_hasRole_succeeds() throws UserNotFoundException { /* test */ - create_generic(ONTOLOGY_1_CREATE_DTO, USER_3_PRINCIPAL, USER_3_USERNAME, USER_3, ONTOLOGY_1); + create_generic(ONTOLOGY_1_CREATE_DTO, USER_3_PRINCIPAL, USER_3.getUsername(), USER_3, ONTOLOGY_1); } @Test @@ -154,7 +154,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void update_noRole_fails() { /* test */ @@ -164,7 +164,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"update-ontology"}) + @WithMockUser(username ="junit3", authorities = {"update-ontology"}) public void update_hasRole_succeeds() throws OntologyNotFoundException { /* test */ @@ -182,7 +182,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void delete_noRole_fails() { /* test */ @@ -192,7 +192,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"delete-ontology"}) + @WithMockUser(username ="junit3", authorities = {"delete-ontology"}) public void delete_hasRole_succeeds() throws OntologyNotFoundException { /* test */ @@ -210,7 +210,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {}) + @WithMockUser(username = "junit4", authorities = {}) public void find_noRole_fails() { /* test */ @@ -220,7 +220,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"execute-semantic-query"}) + @WithMockUser(username = "junit1", authorities = {"execute-semantic-query"}) public void find_hasRoleInvalidParams_succeeds() { /* test */ @@ -230,7 +230,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"execute-semantic-query"}) + @WithMockUser(username = "junit1", authorities = {"execute-semantic-query"}) public void find_hasRoleNotOntologyUri_succeeds() { /* test */ @@ -240,7 +240,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"execute-semantic-query"}) + @WithMockUser(username = "junit1", authorities = {"execute-semantic-query"}) public void find_hasRoleLabel_succeeds() throws MalformedException, UriMalformedException, OntologyNotFoundException, FilterBadRequestException { final EntityDto entityDto = EntityDto.builder() @@ -256,7 +256,7 @@ public class OntologyEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"execute-semantic-query"}) + @WithMockUser(username = "junit1", authorities = {"execute-semantic-query"}) public void find_hasRoleUri_succeeds() throws MalformedException, UriMalformedException, OntologyNotFoundException, FilterBadRequestException { final EntityDto entityDto = EntityDto.builder() diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/TableEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/TableEndpointUnitTest.java index 97dd2f16e9..197a3ebf45 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/TableEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/TableEndpointUnitTest.java @@ -100,7 +100,7 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_list(DATABASE_3_ID, DATABASE_3, null, null, null); + generic_list(DATABASE_3.getId(), DATABASE_3, null, null, null); }); } @@ -114,34 +114,34 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void list_publicHasRoleDatabaseNotFound_fails() { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - generic_list(DATABASE_3_ID, null, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_READ_ACCESS); + generic_list(DATABASE_3.getId(), null, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_READ_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void list_publicHasRole_succeeds() throws NotAllowedException, UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - final ResponseEntity<List<TableBriefDto>> response = generic_list(DATABASE_3_ID, DATABASE_3, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + final ResponseEntity<List<TableBriefDto>> response = generic_list(DATABASE_3.getId(), DATABASE_3, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); assertEquals(HttpStatus.OK, response.getStatusCode()); final List<TableBriefDto> body = response.getBody(); assertNotNull(body); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void list_publicDataPrivateSchemaNoRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_list(DATABASE_3_ID, DATABASE_3, USER_4_PRINCIPAL, USER_4, null); + generic_list(DATABASE_3.getId(), DATABASE_3, USER_4_PRINCIPAL, USER_4, null); }); } @@ -151,52 +151,52 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, TABLE_5_CREATE_DTO, null, null, null); + generic_create(DATABASE_3.getId(), DATABASE_3, TABLE_5_CREATE_DTO, null, null, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table"}) + @WithMockUser(username = "junit1", authorities = {"create-table"}) public void create_publicHasRoleDatabaseNotFound_fails() { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - generic_create(DATABASE_3_ID, null, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), null, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table"}) + @WithMockUser(username = "junit1", authorities = {"create-table"}) public void create_publicHasRoleNoAccess_fails() { /* test */ assertThrows(AccessNotFoundException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, null); + generic_create(DATABASE_3.getId(), DATABASE_3, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void create_publicNoRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table"}) + @WithMockUser(username = "junit1", authorities = {"create-table"}) public void create_publicHasRoleOnlyReadAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_READ_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_READ_ACCESS); }); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicDecimalColumnSizeTooSmall_fails() { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -212,12 +212,12 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicDecimalColumnDTooSmall_fails() { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -233,13 +233,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @ParameterizedTest @MethodSource("canHaveSize_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicOptionalSizeNone_succeeds(ColumnTypeDto columnType) throws UserNotFoundException, SearchServiceException, NotAllowedException, SemanticEntityNotFoundException, TableNotFoundException, DataServiceConnectionException, MalformedException, DataServiceException, DatabaseNotFoundException, @@ -264,16 +264,16 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ if (EndpointValidator.NEED_SIZE.contains(columnType)) { assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } else { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } } @ParameterizedTest @MethodSource("canHaveSize_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicOptionalSize_succeeds(ColumnTypeDto columnType) throws UserNotFoundException, SearchServiceException, NotAllowedException, SemanticEntityNotFoundException, TableNotFoundException, DataServiceConnectionException, MalformedException, DataServiceException, DatabaseNotFoundException, @@ -296,12 +296,12 @@ public class TableEndpointUnitTest extends BaseTest { .thenReturn(TABLE_1) /* some table */; /* test */ - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } @ParameterizedTest @MethodSource("needNothing_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicNeedNothing_succeeds(ColumnTypeDto columnType) throws UserNotFoundException, SearchServiceException, NotAllowedException, SemanticEntityNotFoundException, TableNotFoundException, DataServiceConnectionException, MalformedException, DataServiceException, DatabaseNotFoundException, @@ -325,12 +325,12 @@ public class TableEndpointUnitTest extends BaseTest { .thenReturn(TABLE_1) /* some table */; /* test */ - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } @ParameterizedTest @MethodSource("needSize_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicNeedSize_succeeds(ColumnTypeDto columnType) throws UserNotFoundException, SearchServiceException, NotAllowedException, SemanticEntityNotFoundException, TableNotFoundException, DataServiceConnectionException, MalformedException, DataServiceException, DatabaseNotFoundException, @@ -353,12 +353,12 @@ public class TableEndpointUnitTest extends BaseTest { .thenReturn(TABLE_1) /* some table */; /* test */ - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } @ParameterizedTest @MethodSource("needSize_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicNeedSizeNone_fails(ColumnTypeDto columnType) { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -374,13 +374,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @ParameterizedTest @MethodSource("canHaveSizeAndD_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicCanHaveSizeAndDSizeNone_fails(ColumnTypeDto columnType) { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -396,13 +396,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @ParameterizedTest @MethodSource("canHaveSizeAndD_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicCanHaveSizeAndDDNone_fails(ColumnTypeDto columnType) { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -418,13 +418,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @ParameterizedTest @MethodSource("canHaveSizeAndD_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicCanHaveSizeAndDBothNone_succeeds(ColumnTypeDto columnType) throws UserNotFoundException, SearchServiceException, NotAllowedException, SemanticEntityNotFoundException, DataServiceConnectionException, TableNotFoundException, MalformedException, DataServiceException, @@ -447,11 +447,11 @@ public class TableEndpointUnitTest extends BaseTest { .thenReturn(TABLE_1) /* some table */; /* test */ - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicHasMultipleSerial_fails() { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -474,12 +474,12 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicSerialNullAllowed_fails() { final CreateTableDto request = CreateTableDto.builder() .name("Some Table") @@ -496,13 +496,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @ParameterizedTest @MethodSource("canHaveSizeAndD_parameters") - @WithMockUser(username = USER_3_USERNAME, authorities = {"create-table"}) + @WithMockUser(username ="junit3", authorities = {"create-table"}) public void create_publicCanHaveSizeAndDBothNotNone_succeeds(ColumnTypeDto columnType) throws UserNotFoundException, SearchServiceException, NotAllowedException, SemanticEntityNotFoundException, DataServiceConnectionException, TableNotFoundException, MalformedException, DataServiceException, @@ -525,7 +525,7 @@ public class TableEndpointUnitTest extends BaseTest { .thenReturn(TABLE_1) /* some table */; /* test */ - generic_create(DATABASE_3_ID, DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_3.getId(), DATABASE_3, request, USER_1_PRINCIPAL, USER_1, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } @Test @@ -538,44 +538,44 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void findById_publicHasRoleTableNotFound_fails() { /* test */ assertThrows(TableNotFoundException.class, () -> { - generic_findById(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, null, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + generic_findById(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, null, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void findById_publicHasRoleDatabaseNotFound_fails() { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - generic_findById(DATABASE_3_ID, null, TABLE_8_ID, TABLE_8, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + generic_findById(DATABASE_3.getId(), null, TABLE_8_ID, TABLE_8, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void findById_publicHasRole_succeeds() throws UserNotFoundException, TableNotFoundException, NotAllowedException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - final ResponseEntity<TableDto> response = generic_findById(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + final ResponseEntity<TableDto> response = generic_findById(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); assertEquals(HttpStatus.OK, response.getStatusCode()); final TableDto body = response.getBody(); assertNotNull(body); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void findById_publicNoRole_succeeds() throws UserNotFoundException, TableNotFoundException, NotAllowedException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - generic_findById(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, USER_1_PRINCIPAL, USER_1, null); + generic_findById(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, USER_1_PRINCIPAL, USER_1, null); } @Test @@ -584,37 +584,37 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - analyseTable_generic(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, null); + analyseTable_generic(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, null); }); } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {"table-semantic-analyse"}) + @WithMockUser(username = "junit4", authorities = {"table-semantic-analyse"}) public void analyseTable_notOwner_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - analyseTable_generic(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, USER_4_PRINCIPAL); + analyseTable_generic(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, USER_4_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void findAll_noRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - analyseTable_generic(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, USER_4_PRINCIPAL); + analyseTable_generic(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, USER_4_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"table-semantic-analyse"}) + @WithMockUser(username = "junit1", authorities = {"table-semantic-analyse"}) public void findAll_hasRole_succeeds() throws MalformedException, TableNotFoundException, DatabaseNotFoundException, NotAllowedException { /* test */ - analyseTable_generic(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, USER_1_PRINCIPAL); + analyseTable_generic(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, USER_1_PRINCIPAL); } @Test @@ -623,27 +623,27 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - analyseTableColumn_generic(DATABASE_1_ID, TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), null); + analyseTableColumn_generic(DATABASE_1.getId(), TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), null); }); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void analyseTableColumn_noRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - analyseTableColumn_generic(DATABASE_1_ID, TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_4_PRINCIPAL); + analyseTableColumn_generic(DATABASE_1.getId(), TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_4_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"table-semantic-analyse"}) + @WithMockUser(username = "junit1", authorities = {"table-semantic-analyse"}) public void analyseTableColumn_hasRole_succeeds() throws MalformedException, TableNotFoundException, DatabaseNotFoundException { /* test */ - analyseTableColumn_generic(DATABASE_1_ID, TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_1_PRINCIPAL); + analyseTableColumn_generic(DATABASE_1.getId(), TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_1_PRINCIPAL); } @Test @@ -655,13 +655,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), null, null, request, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_publicHasRoleNoAccess_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .conceptUri(CONCEPT_2_URI) @@ -669,13 +669,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessNotFoundException.class, () -> { - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_publicHasRoleHasOnlyReadAccess_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .conceptUri(CONCEPT_2_URI) @@ -683,13 +683,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, DATABASE_3_USER_1_READ_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_publicHasRoleHasOwnWriteAccess_succeeds() throws MalformedException, DataServiceException, NotAllowedException, DataServiceConnectionException, UserNotFoundException, TableNotFoundException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceException, @@ -699,12 +699,12 @@ public class TableEndpointUnitTest extends BaseTest { .build(); /* test */ - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, DATABASE_3_USER_1_WRITE_OWN_ACCESS); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username ="junit2", authorities = {"modify-table-column-semantics"}) public void update_publicHasRoleForeignHasOwnWriteAccess_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .unitUri(UNIT_1_URI) @@ -712,13 +712,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), USER_2_PRINCIPAL, USER_2, request, DATABASE_3_USER_2_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_publicTableNotFound_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .unitUri(UNIT_1_URI) @@ -726,13 +726,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(TableNotFoundException.class, () -> { - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, null, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, null, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, DATABASE_3_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username ="junit2", authorities = {"modify-table-column-semantics"}) public void update_publicHasRoleForeignHasAllWriteAccess_succeeds() throws MalformedException, DataServiceException, NotAllowedException, DataServiceConnectionException, UserNotFoundException, TableNotFoundException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceException, @@ -742,7 +742,7 @@ public class TableEndpointUnitTest extends BaseTest { .build(); /* test */ - generic_updateColumn(DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_3.getId(), DATABASE_3, TABLE_8_ID, TABLE_8, TABLE_8_COLUMNS.get(0).getId(), TABLE_8_COLUMNS.get(0), USER_2_PRINCIPAL, USER_2, request, DATABASE_3_USER_2_WRITE_ALL_ACCESS); } @@ -759,13 +759,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), null, null, request, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_privateHasRoleNoAccess_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .unitUri(UNIT_1_URI) @@ -773,13 +773,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessNotFoundException.class, () -> { - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_privateHasRoleHasOnlyReadAccess_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .unitUri(UNIT_1_URI) @@ -787,13 +787,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), - TABLE_1_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, DATABASE_1_USER_1_READ_ACCESS); + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), + TABLE_1_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, DATABASE_1.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_privateHasRoleHasOwnWriteAccess_succeeds() throws MalformedException, DataServiceException, NotAllowedException, DataServiceConnectionException, UserNotFoundException, TableNotFoundException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceException, @@ -803,12 +803,12 @@ public class TableEndpointUnitTest extends BaseTest { .build(); /* test */ - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_1_PRINCIPAL, USER_1, request, DATABASE_1_USER_1_WRITE_OWN_ACCESS); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username ="junit2", authorities = {"modify-table-column-semantics"}) public void update_privateHasRoleForeignHasOwnWriteAccess_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .unitUri(UNIT_1_URI) @@ -816,13 +816,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_2_PRINCIPAL, USER_2, request, DATABASE_1_USER_2_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username = "junit1", authorities = {"modify-table-column-semantics"}) public void update_privateTableNotFound_fails() { final ColumnSemanticsUpdateDto request = ColumnSemanticsUpdateDto.builder() .unitUri(UNIT_1_URI) @@ -830,13 +830,13 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(TableNotFoundException.class, () -> { - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, null, TABLE_1_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, null, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_2_PRINCIPAL, USER_2, request, DATABASE_1_USER_2_WRITE_ALL_ACCESS); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-table-column-semantics"}) + @WithMockUser(username ="junit2", authorities = {"modify-table-column-semantics"}) public void update_privateHasRoleForeignHasAllWriteAccess_succeeds() throws MalformedException, DataServiceException, NotAllowedException, DataServiceConnectionException, UserNotFoundException, TableNotFoundException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceException, @@ -847,27 +847,27 @@ public class TableEndpointUnitTest extends BaseTest { .build(); /* test */ - generic_updateColumn(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), + generic_updateColumn(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, TABLE_1_COLUMNS.get(0).getId(), TABLE_1_COLUMNS.get(0), USER_2_PRINCIPAL, USER_2, request, DATABASE_1_USER_2_WRITE_ALL_ACCESS); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void list_privateHasRoleDatabaseNotFound_fails() { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - generic_list(DATABASE_1_ID, null, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + generic_list(DATABASE_1.getId(), null, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void list_privateHasRole_succeeds() throws NotAllowedException, UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - final ResponseEntity<List<TableBriefDto>> response = generic_list(DATABASE_1_ID, DATABASE_1, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + final ResponseEntity<List<TableBriefDto>> response = generic_list(DATABASE_1.getId(), DATABASE_1, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); assertEquals(HttpStatus.OK, response.getStatusCode()); final List<TableBriefDto> body = response.getBody(); assertNotNull(body); @@ -879,47 +879,47 @@ public class TableEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_create(DATABASE_1_ID, DATABASE_1, TABLE_5_CREATE_DTO, null, null, null); + generic_create(DATABASE_1.getId(), DATABASE_1, TABLE_5_CREATE_DTO, null, null, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table"}) + @WithMockUser(username = "junit1", authorities = {"create-table"}) public void create_privateHasRoleDatabaseNotFound_fails() { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - generic_create(DATABASE_1_ID, null, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_1.getId(), null, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table"}) + @WithMockUser(username = "junit1", authorities = {"create-table"}) public void create_privateHasRoleNoAccess_fails() { /* test */ assertThrows(AccessNotFoundException.class, () -> { - generic_create(DATABASE_1_ID, DATABASE_1, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, null); + generic_create(DATABASE_1.getId(), DATABASE_1, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void create_privateNoRole_fails() { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - generic_create(DATABASE_1_ID, DATABASE_1, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_WRITE_OWN_ACCESS); + generic_create(DATABASE_1.getId(), DATABASE_1, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_WRITE_OWN_ACCESS); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table"}) + @WithMockUser(username = "junit1", authorities = {"create-table"}) public void create_privateHasRoleOnlyReadAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(DATABASE_1_ID, DATABASE_1, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + generic_create(DATABASE_1.getId(), DATABASE_1, TABLE_5_CREATE_DTO, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); }); } @@ -929,55 +929,55 @@ public class TableEndpointUnitTest extends BaseTest { TableNotFoundException, NotAllowedException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - generic_findById(DATABASE_1_ID, DATABASE_1, TABLE_2_ID, TABLE_2, null, null, null); + generic_findById(DATABASE_1.getId(), DATABASE_1, TABLE_2_ID, TABLE_2, null, null, null); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void findById_publicSchemaNotOwnerNoAccess_succeeds() throws UserNotFoundException, TableNotFoundException, NotAllowedException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - final ResponseEntity<TableDto> response = generic_findById(DATABASE_1_ID, DATABASE_1, TABLE_2_ID, TABLE_2, USER_4_PRINCIPAL, USER_4, null); + final ResponseEntity<TableDto> response = generic_findById(DATABASE_1.getId(), DATABASE_1, TABLE_2_ID, TABLE_2, USER_4_PRINCIPAL, USER_4, null); assertEquals(HttpStatus.OK, response.getStatusCode()); final TableDto body = response.getBody(); assertNotNull(body); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void findById_privateHasRoleTableNotFound_fails() { /* test */ assertThrows(TableNotFoundException.class, () -> { - generic_findById(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, null, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + generic_findById(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, null, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void findById_privateHasRoleDatabaseNotFound_fails() { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - generic_findById(DATABASE_1_ID, null, TABLE_1_ID, TABLE_1, USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + generic_findById(DATABASE_1.getId(), null, TABLE_1_ID, TABLE_1, USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "find-table") + @WithMockUser(username = "junit1", authorities = "find-table") public void findById_privateHasRole_succeeds() throws UserNotFoundException, TableNotFoundException, NotAllowedException, DatabaseNotFoundException, AccessNotFoundException { /* test */ - final ResponseEntity<TableDto> response = generic_findById(DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, - USER_1_PRINCIPAL, USER_1, DATABASE_1_USER_1_READ_ACCESS); + final ResponseEntity<TableDto> response = generic_findById(DATABASE_1.getId(), DATABASE_1, TABLE_1_ID, TABLE_1, + USER_1_PRINCIPAL, USER_1, DATABASE_1.getAccesses().get(0)); assertEquals(HttpStatus.OK, response.getStatusCode()); final TableDto body = response.getBody(); assertNotNull(body); } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void delete_privateNoRole_fails() { /* test */ @@ -987,7 +987,7 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"delete-table"}) + @WithMockUser(username = "junit1", authorities = {"delete-table"}) public void delete_succeeds() throws NotAllowedException, DataServiceException, DataServiceConnectionException, TableNotFoundException, DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { @@ -997,7 +997,7 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"delete-table"}) + @WithMockUser(username ="junit3", authorities = {"delete-table"}) public void delete_foreign_fails() { /* test */ @@ -1018,12 +1018,12 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-table"}) + @WithMockUser(username ="junit2", authorities = {"delete-table"}) public void delete_hasIdentifiers_fails() { final Table response = Table.builder() .identifiers(List.of(IDENTIFIER_1)) .owner(USER_1) - .ownedBy(USER_1_ID) + .ownedBy(USER_1.getId()) .build(); /* test */ @@ -1033,7 +1033,7 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"update-table"}) + @WithMockUser(username = "junit1", authorities = {"update-table"}) public void update_succeeds() throws TableNotFoundException, SearchServiceException, NotAllowedException, DataServiceException, DatabaseNotFoundException, SearchServiceConnectionException, DataServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { @@ -1050,7 +1050,7 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"update-table"}) + @WithMockUser(username ="junit2", authorities = {"update-table"}) public void update_notOwner_fails() { final TableUpdateDto request = TableUpdateDto.builder() .isPublic(true) @@ -1065,7 +1065,7 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"update-table-statistic"}) + @WithMockUser(username ="junit2", authorities = {"update-table-statistic"}) public void updateStatistic_notOwner_fails() { /* test */ @@ -1075,7 +1075,7 @@ public class TableEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"update-table-statistic"}) + @WithMockUser(username = "junit1", authorities = {"update-table-statistic"}) public void updateStatistic_succeeds() throws TableNotFoundException, SearchServiceException, MalformedException, NotAllowedException, DataServiceException, DatabaseNotFoundException, SearchServiceConnectionException, DataServiceConnectionException { @@ -1244,13 +1244,13 @@ public class TableEndpointUnitTest extends BaseTest { DashboardServiceConnectionException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(tableService.findById(any(Database.class), any(UUID.class))) .thenReturn(table); /* test */ - return tableEndpoint.delete(DATABASE_1_ID, TABLE_1_ID, principal); + return tableEndpoint.delete(DATABASE_1.getId(), TABLE_1_ID, principal); } protected ResponseEntity<ColumnDto> generic_updateColumn(UUID databaseId, Database database, UUID tableId, @@ -1304,7 +1304,7 @@ public class TableEndpointUnitTest extends BaseTest { DashboardServiceException, DashboardServiceConnectionException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(tableService.findById(DATABASE_1, TABLE_1_ID)) .thenReturn(TABLE_1); @@ -1312,7 +1312,7 @@ public class TableEndpointUnitTest extends BaseTest { .thenReturn(TABLE_1); /* test */ - return tableEndpoint.update(DATABASE_1_ID, TABLE_1_ID, data, caller); + return tableEndpoint.update(DATABASE_1.getId(), TABLE_1_ID, data, caller); } protected ResponseEntity<Void> generic_updateStatistic(Principal caller) @@ -1321,7 +1321,7 @@ public class TableEndpointUnitTest extends BaseTest { MalformedException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(tableService.findById(DATABASE_1, TABLE_1_ID)) .thenReturn(TABLE_1); @@ -1330,6 +1330,6 @@ public class TableEndpointUnitTest extends BaseTest { .updateStatistics(TABLE_1); /* test */ - return tableEndpoint.updateStatistic(DATABASE_1_ID, TABLE_1_ID, caller); + return tableEndpoint.updateStatistic(DATABASE_1.getId(), TABLE_1_ID, caller); } } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UnitEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UnitEndpointUnitTest.java index de54e96b7d..dcef575b6b 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UnitEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UnitEndpointUnitTest.java @@ -41,7 +41,7 @@ public class UnitEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME, authorities = {}) + @WithMockUser(username = "junit4", authorities = {}) public void findAllUnits_noRole_succeeds() { /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UserEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UserEndpointUnitTest.java index 05ab6e5d3a..e3f7fb7f74 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UserEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/UserEndpointUnitTest.java @@ -63,7 +63,7 @@ public class UserEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void findAll_noRole_succeeds() throws UserNotFoundException { /* test */ @@ -77,7 +77,7 @@ public class UserEndpointUnitTest extends BaseTest { /* test */ final List<UserBriefDto> response = findAll_generic(USER_2_USERNAME, USER_2); assertEquals(1, response.size()); - assertEquals(USER_2_ID, response.get(0).getId()); + assertEquals(USER_2.getId(), response.get(0).getId()); } @Test @@ -99,35 +99,35 @@ public class UserEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void find_self_succeeds() throws NotAllowedException, UserNotFoundException { /* test */ - find_generic(USER_1_ID, USER_1, USER_1_PRINCIPAL); + find_generic(USER_1.getId(), USER_1, USER_1_PRINCIPAL); } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void find_foreign_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - find_generic(USER_2_ID, USER_2, USER_1_PRINCIPAL); + find_generic(USER_2.getId(), USER_2, USER_1_PRINCIPAL); }); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"find-foreign-user"}) + @WithMockUser(username ="junit3", authorities = {"find-foreign-user"}) public void find_hasRoleForeign_succeeds() throws UserNotFoundException, NotAllowedException { final Principal principal = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, USER_3_PASSWORD, List.of( new SimpleGrantedAuthority("find-foreign-user"))); /* test */ - find_generic(USER_2_ID, USER_2, principal); + find_generic(USER_2.getId(), USER_2, principal); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"system"}) + @WithMockUser(username ="junit3", authorities = {"system"}) public void find_system_succeeds() throws UserNotFoundException, NotAllowedException { final Principal principal = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, USER_3_PASSWORD, List.of( new SimpleGrantedAuthority("system"))); @@ -135,7 +135,7 @@ public class UserEndpointUnitTest extends BaseTest { /* test */ final ResponseEntity<UserDto> response = find_generic(USER_3_ID, USER_3, principal); assertNotNull(response.getHeaders().get("X-Username")); - assertEquals(USER_3_USERNAME, response.getHeaders().get("X-Username").get(0)); + assertEquals(USER_3.getUsername(), response.getHeaders().get("X-Username").get(0)); assertNotNull(response.getHeaders().get("X-Password")); assertNotEquals(USER_3_PASSWORD, response.getHeaders().get("X-Password").get(0)); assertEquals(USER_3_DATABASE_PASSWORD, response.getHeaders().get("X-Password").get(0)); @@ -170,7 +170,7 @@ public class UserEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_4_USERNAME) + @WithMockUser(username = "junit4") public void modify_noRole_fails() { final UserUpdateDto request = UserUpdateDto.builder() .firstname(USER_1_FIRSTNAME) @@ -181,12 +181,12 @@ public class UserEndpointUnitTest extends BaseTest { /* test */ assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { - modify_generic(USER_4_ID, USER_4, USER_4_PRINCIPAL, request); + modify_generic(USER_4.getId(), USER_4, USER_4_PRINCIPAL, request); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-user-information"}) + @WithMockUser(username ="junit2", authorities = {"modify-user-information"}) public void modify_hasRoleForeign_fails() { final UserUpdateDto request = UserUpdateDto.builder() .firstname(USER_1_FIRSTNAME) @@ -197,12 +197,12 @@ public class UserEndpointUnitTest extends BaseTest { /* test */ assertThrows(NotAllowedException.class, () -> { - modify_generic(USER_1_ID, USER_1, USER_2_PRINCIPAL, request); + modify_generic(USER_1.getId(), USER_1, USER_2_PRINCIPAL, request); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-user-information"}) + @WithMockUser(username = "junit1", authorities = {"modify-user-information"}) public void modify_succeeds() throws NotAllowedException, UserNotFoundException, AuthServiceException { final UserUpdateDto request = UserUpdateDto.builder() .firstname(USER_1_FIRSTNAME) @@ -212,7 +212,7 @@ public class UserEndpointUnitTest extends BaseTest { .build(); /* test */ - modify_generic(USER_1_ID, USER_1, USER_1_PRINCIPAL, request); + modify_generic(USER_1.getId(), USER_1, USER_1_PRINCIPAL, request); } @Test @@ -226,7 +226,7 @@ public class UserEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void create_notInternalUser_fails() { /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ViewEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ViewEndpointUnitTest.java index 2673ea3068..80e9d9f069 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ViewEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/endpoints/ViewEndpointUnitTest.java @@ -60,34 +60,34 @@ public class ViewEndpointUnitTest extends BaseTest { DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_3_ID, DATABASE_3, null, null, null, null); + findAll_generic(DATABASE_3.getId(), DATABASE_3, null, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + @WithMockUser(username ="junit2", authorities = {"list-views"}) public void findAll_publicHasRole_succeeds() throws UserNotFoundException, AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_3_ID, DATABASE_3, USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + findAll_generic(DATABASE_3.getId(), DATABASE_3, USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + @WithMockUser(username ="junit2", authorities = {"list-views"}) public void findAll_publicHasRoleHasAccess_succeeds() throws UserNotFoundException, AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_3_ID, DATABASE_3, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_3_USER_2_READ_ACCESS); + findAll_generic(DATABASE_3.getId(), DATABASE_3, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_3_USER_2_READ_ACCESS); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void findAll_publicNoRole_succeeds() throws UserNotFoundException, AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_3_ID, DATABASE_3, USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + findAll_generic(DATABASE_3.getId(), DATABASE_3, USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); } @Test @@ -96,58 +96,58 @@ public class ViewEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - create_generic(DATABASE_3_ID, DATABASE_3, "View", null, null, null, null); + create_generic(DATABASE_3.getId(), DATABASE_3, "View", null, null, null, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + @WithMockUser(username ="junit2", authorities = {"create-database-view"}) public void create_publicHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(DATABASE_3_ID, DATABASE_3, "View", USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + create_generic(DATABASE_3.getId(), DATABASE_3, "View", USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + @WithMockUser(username ="junit2", authorities = {"create-database-view"}) public void create_publicHasRoleHasAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(DATABASE_3_ID, DATABASE_3, "View", USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + create_generic(DATABASE_3.getId(), DATABASE_3, "View", USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void create_publicNoRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - create_generic(DATABASE_3_ID, DATABASE_3, "View", USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + create_generic(DATABASE_3.getId(), DATABASE_3, "View", USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database-view"}) + @WithMockUser(username = "junit1", authorities = {"create-database-view"}) public void create_succeeds() throws UserNotFoundException, SearchServiceException, MalformedException, NotAllowedException, DataServiceException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceConnectionException, DataServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException, TableNotFoundException, ViewExistsException, ImageNotFoundException { /* test */ - create_generic(DATABASE_1_ID, DATABASE_1, "View", USER_1_PRINCIPAL, USER_1_ID, USER_1, DATABASE_1_USER_1_WRITE_ALL_ACCESS); + create_generic(DATABASE_1.getId(), DATABASE_1, "View", USER_1_PRINCIPAL, USER_1.getId(), USER_1, DATABASE_1_USER_1_WRITE_ALL_ACCESS); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database-view"}) + @WithMockUser(username = "junit1", authorities = {"create-database-view"}) public void create_exists_fails() { /* test */ assertThrows(ViewExistsException.class, () -> { - create_generic(DATABASE_1_ID, DATABASE_1, VIEW_1_NAME, USER_1_PRINCIPAL, USER_1_ID, USER_1, DATABASE_1_USER_1_WRITE_ALL_ACCESS); + create_generic(DATABASE_1.getId(), DATABASE_1, VIEW_1_NAME, USER_1_PRINCIPAL, USER_1.getId(), USER_1, DATABASE_1_USER_1_WRITE_ALL_ACCESS); }); } @@ -157,34 +157,34 @@ public class ViewEndpointUnitTest extends BaseTest { AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_3_ID, DATABASE_3, null, null, null, null); + find_generic(DATABASE_3.getId(), DATABASE_3, null, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"find-database-view"}) + @WithMockUser(username ="junit2", authorities = {"find-database-view"}) public void find_publicHasRole_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_3_ID, DATABASE_3, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + find_generic(DATABASE_3.getId(), DATABASE_3, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void find_publicNoRole_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_3_ID, DATABASE_3, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + find_generic(DATABASE_3.getId(), DATABASE_3, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void find_publicHasRoleHasAccess_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_3_ID, DATABASE_3, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + find_generic(DATABASE_3.getId(), DATABASE_3, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); } @Test @@ -193,39 +193,39 @@ public class ViewEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - delete_generic(DATABASE_3_ID, DATABASE_3, VIEW_1_ID, VIEW_1, null, null, null, null); + delete_generic(DATABASE_3.getId(), DATABASE_3, VIEW_1_ID, VIEW_1, null, null, null, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-database-view"}) + @WithMockUser(username ="junit2", authorities = {"delete-database-view"}) public void delete_publicHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(DATABASE_3_ID, DATABASE_3, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + delete_generic(DATABASE_3.getId(), DATABASE_3, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void delete_publicNoRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - delete_generic(DATABASE_3_ID, DATABASE_3, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + delete_generic(DATABASE_3.getId(), DATABASE_3, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_3_USERNAME, authorities = {"delete-database-view"}) + @WithMockUser(username ="junit3", authorities = {"delete-database-view"}) public void delete_publicOwner_succeeds() throws NotAllowedException, DataServiceException, UserNotFoundException, DataServiceConnectionException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, SearchServiceException, SearchServiceConnectionException, DashboardServiceException, DashboardServiceConnectionException { /* test */ - delete_generic(DATABASE_3_ID, DATABASE_3, VIEW_5_ID, VIEW_5, USER_3_PRINCIPAL, USER_3_ID, USER_3, DATABASE_3_USER_1_WRITE_ALL_ACCESS); + delete_generic(DATABASE_3.getId(), DATABASE_3, VIEW_5_ID, VIEW_5, USER_3_PRINCIPAL, USER_3_ID, USER_3, DATABASE_3_USER_1_WRITE_ALL_ACCESS); } /* ################################################################################################### */ @@ -238,34 +238,34 @@ public class ViewEndpointUnitTest extends BaseTest { AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_1_ID, DATABASE_1, null, null, null, null); + findAll_generic(DATABASE_1.getId(), DATABASE_1, null, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + @WithMockUser(username ="junit2", authorities = {"list-views"}) public void findAll_privateHasRole_succeeds() throws UserNotFoundException, AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + findAll_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"list-views"}) + @WithMockUser(username ="junit2", authorities = {"list-views"}) public void findAll_privateHasRoleHasAccess_succeeds() throws UserNotFoundException, AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_1_USER_2_READ_ACCESS); + findAll_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_1_USER_2_READ_ACCESS); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void findAll_privateNoRole_succeeds() throws UserNotFoundException, AccessNotFoundException, DatabaseNotFoundException { /* test */ - findAll_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + findAll_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); } @Test @@ -274,37 +274,37 @@ public class ViewEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - create_generic(DATABASE_1_ID, DATABASE_1, "View", null, null, null, null); + create_generic(DATABASE_1.getId(), DATABASE_1, "View", null, null, null, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + @WithMockUser(username ="junit2", authorities = {"create-database-view"}) public void create_privateHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(DATABASE_1_ID, DATABASE_1, "View", USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + create_generic(DATABASE_1.getId(), DATABASE_1, "View", USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"create-database-view"}) + @WithMockUser(username ="junit2", authorities = {"create-database-view"}) public void create_privateHasRoleHasAccess_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(DATABASE_1_ID, DATABASE_1, "View", USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + create_generic(DATABASE_1.getId(), DATABASE_1, "View", USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void create_privateNoRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - create_generic(DATABASE_1_ID, DATABASE_1, "View", USER_2_PRINCIPAL, USER_2_ID, USER_2, null); + create_generic(DATABASE_1.getId(), DATABASE_1, "View", USER_2_PRINCIPAL, USER_2.getId(), USER_2, null); }); } @@ -314,34 +314,34 @@ public class ViewEndpointUnitTest extends BaseTest { AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_1_ID, DATABASE_1, null, null, null, null); + find_generic(DATABASE_1.getId(), DATABASE_1, null, null, null, null); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"find-database-view"}) + @WithMockUser(username ="junit2", authorities = {"find-database-view"}) public void find_privateHasRole_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + find_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void find_privateNoRole_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + find_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void find_privateHasRoleHasAccess_succeeds() throws UserNotFoundException, DatabaseNotFoundException, AccessNotFoundException, ViewNotFoundException, NotAllowedException { /* test */ - find_generic(DATABASE_1_ID, DATABASE_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + find_generic(DATABASE_1.getId(), DATABASE_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); } @Test @@ -350,39 +350,39 @@ public class ViewEndpointUnitTest extends BaseTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - delete_generic(DATABASE_1_ID, DATABASE_1, VIEW_1_ID, VIEW_1, null, null, null, null); + delete_generic(DATABASE_1.getId(), DATABASE_1, VIEW_1_ID, VIEW_1, null, null, null, null); }); } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"delete-database-view"}) + @WithMockUser(username ="junit2", authorities = {"delete-database-view"}) public void delete_privateHasRole_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(DATABASE_1_ID, DATABASE_1, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + delete_generic(DATABASE_1.getId(), DATABASE_1, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_2_USERNAME) + @WithMockUser(username ="junit2") public void delete_privateNoRole_fails() { /* test */ assertThrows(AccessDeniedException.class, () -> { - delete_generic(DATABASE_1_ID, DATABASE_1, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2_ID, USER_2, DATABASE_2_USER_1_READ_ACCESS); + delete_generic(DATABASE_1.getId(), DATABASE_1, VIEW_1_ID, VIEW_1, USER_2_PRINCIPAL, USER_2.getId(), USER_2, DATABASE_2.getAccesses().get(0)); }); } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"delete-database-view"}) + @WithMockUser(username = "junit1", authorities = {"delete-database-view"}) public void delete_privateOwner_succeeds() throws NotAllowedException, DataServiceException, DataServiceConnectionException, DatabaseNotFoundException, AccessNotFoundException, SearchServiceException, SearchServiceConnectionException, ViewNotFoundException, UserNotFoundException, DashboardServiceException, DashboardServiceConnectionException { /* test */ - delete_generic(DATABASE_1_ID, DATABASE_1, VIEW_1_ID, VIEW_1, USER_1_PRINCIPAL, USER_1_ID, USER_1, DATABASE_1_USER_1_WRITE_ALL_ACCESS); + delete_generic(DATABASE_1.getId(), DATABASE_1, VIEW_1_ID, VIEW_1, USER_1_PRINCIPAL, USER_1.getId(), USER_1, DATABASE_1_USER_1_WRITE_ALL_ACCESS); } @Test @@ -396,7 +396,7 @@ public class ViewEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void update_noRole_fails() { /* test */ @@ -406,7 +406,7 @@ public class ViewEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_2_USERNAME, authorities = {"modify-view-visibility"}) + @WithMockUser(username ="junit2", authorities = {"modify-view-visibility"}) public void update_notOwner_fails() { /* test */ @@ -416,7 +416,7 @@ public class ViewEndpointUnitTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"modify-view-visibility"}) + @WithMockUser(username = "junit1", authorities = {"modify-view-visibility"}) public void update_succeeds() throws NotAllowedException, DataServiceConnectionException, DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException, ViewNotFoundException, UserNotFoundException, DashboardServiceException, DashboardServiceConnectionException { @@ -569,7 +569,7 @@ public class ViewEndpointUnitTest extends BaseTest { .build(); /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(viewService.findById(DATABASE_1, VIEW_1_ID)) .thenReturn(VIEW_1); @@ -577,7 +577,7 @@ public class ViewEndpointUnitTest extends BaseTest { .thenReturn(VIEW_1); /* test */ - final ResponseEntity<ViewBriefDto> response = viewEndpoint.update(DATABASE_1_ID, VIEW_1_ID, request, principal); + final ResponseEntity<ViewBriefDto> response = viewEndpoint.update(DATABASE_1.getId(), VIEW_1_ID, request, principal); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); assertNotNull(response.getBody()); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/BrokerServiceGatewayUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/BrokerServiceGatewayUnitTest.java index e8d2b01923..b5dabf97c4 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/BrokerServiceGatewayUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/BrokerServiceGatewayUnitTest.java @@ -37,8 +37,8 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { private final GrantExchangePermissionsDto WRITE_ALL_PERMISSIONS = GrantExchangePermissionsDto.builder() .exchange("dbrepo") - .read("^(dbrepo\\." + DATABASE_1_ID + "\\..*)$") /* WRITE_ALL */ - .write("^(dbrepo\\." + DATABASE_1_ID + "\\..*)$") + .read("^(dbrepo\\." + DATABASE_1.getId() + "\\..*)$") /* WRITE_ALL */ + .write("^(dbrepo\\." + DATABASE_1.getId() + "\\..*)$") .build(); @Test @@ -52,7 +52,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { .thenReturn(mock); /* test */ - brokerServiceGateway.grantTopicPermission(USER_1_USERNAME, VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); + brokerServiceGateway.grantTopicPermission("junit1", VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); } @Test @@ -66,7 +66,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { .thenReturn(mock); /* test */ - brokerServiceGateway.grantTopicPermission(USER_1_USERNAME, VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); + brokerServiceGateway.grantTopicPermission("junit1", VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); } @Test @@ -80,7 +80,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceException.class, () -> { - brokerServiceGateway.grantTopicPermission(USER_1_USERNAME, VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); + brokerServiceGateway.grantTopicPermission("junit1", VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); }); } @@ -95,7 +95,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { .thenReturn(mock); /* test */ - brokerServiceGateway.grantVirtualHostPermission(USER_1_USERNAME, VIRTUAL_HOST_GRANT_DTO); + brokerServiceGateway.grantVirtualHostPermission("junit1", VIRTUAL_HOST_GRANT_DTO); } @Test @@ -109,7 +109,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { .thenReturn(mock); /* test */ - brokerServiceGateway.grantVirtualHostPermission(USER_1_USERNAME, VIRTUAL_HOST_GRANT_DTO); + brokerServiceGateway.grantVirtualHostPermission("junit1", VIRTUAL_HOST_GRANT_DTO); } @Test @@ -123,7 +123,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceException.class, () -> { - brokerServiceGateway.grantVirtualHostPermission(USER_1_USERNAME, VIRTUAL_HOST_GRANT_DTO); + brokerServiceGateway.grantVirtualHostPermission("junit1", VIRTUAL_HOST_GRANT_DTO); }); } @@ -137,7 +137,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceException.class, () -> { - brokerServiceGateway.grantVirtualHostPermission(USER_1_USERNAME, VIRTUAL_HOST_GRANT_DTO); + brokerServiceGateway.grantVirtualHostPermission("junit1", VIRTUAL_HOST_GRANT_DTO); }); } @@ -151,7 +151,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceConnectionException.class, () -> { - brokerServiceGateway.grantVirtualHostPermission(USER_1_USERNAME, VIRTUAL_HOST_GRANT_DTO); + brokerServiceGateway.grantVirtualHostPermission("junit1", VIRTUAL_HOST_GRANT_DTO); }); } @@ -165,7 +165,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceException.class, () -> { - brokerServiceGateway.grantTopicPermission(USER_1_USERNAME, VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); + brokerServiceGateway.grantTopicPermission("junit1", VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); }); } @@ -179,7 +179,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceConnectionException.class, () -> { - brokerServiceGateway.grantTopicPermission(USER_1_USERNAME, VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); + brokerServiceGateway.grantTopicPermission("junit1", VIRTUAL_HOST_EXCHANGE_UPDATE_DTO); }); } @@ -193,7 +193,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - brokerServiceGateway.grantExchangePermission(USER_1_USERNAME, WRITE_ALL_PERMISSIONS); + brokerServiceGateway.grantExchangePermission("junit1", WRITE_ALL_PERMISSIONS); } @Test @@ -206,7 +206,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - brokerServiceGateway.grantExchangePermission(USER_1_USERNAME, WRITE_ALL_PERMISSIONS); + brokerServiceGateway.grantExchangePermission("junit1", WRITE_ALL_PERMISSIONS); } @Test @@ -219,7 +219,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceException.class, () -> { - brokerServiceGateway.grantExchangePermission(USER_1_USERNAME, WRITE_ALL_PERMISSIONS); + brokerServiceGateway.grantExchangePermission("junit1", WRITE_ALL_PERMISSIONS); }); } @@ -233,7 +233,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceConnectionException.class, () -> { - brokerServiceGateway.grantExchangePermission(USER_1_USERNAME, WRITE_ALL_PERMISSIONS); + brokerServiceGateway.grantExchangePermission("junit1", WRITE_ALL_PERMISSIONS); }); } @@ -247,7 +247,7 @@ public class BrokerServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(BrokerServiceException.class, () -> { - brokerServiceGateway.grantExchangePermission(USER_1_USERNAME, WRITE_ALL_PERMISSIONS); + brokerServiceGateway.grantExchangePermission("junit1", WRITE_ALL_PERMISSIONS); }); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/DataServiceGatewayUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/DataServiceGatewayUnitTest.java index 14df28608a..327423d4a2 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/DataServiceGatewayUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/DataServiceGatewayUnitTest.java @@ -50,7 +50,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.createAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.createAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); } @Test @@ -63,7 +63,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.createAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.createAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -77,7 +77,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - dataServiceGateway.createAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.createAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -91,7 +91,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.createAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -105,7 +105,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.createAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -118,7 +118,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.updateAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.updateAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); } @Test @@ -131,7 +131,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.updateAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.updateAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -145,7 +145,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(AccessNotFoundException.class, () -> { - dataServiceGateway.updateAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.updateAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -159,7 +159,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.updateAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -173,7 +173,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateAccess(DATABASE_1_ID, USER_1_ID, AccessTypeDto.READ); + dataServiceGateway.updateAccess(DATABASE_1.getId(), USER_1.getId(), AccessTypeDto.READ); }); } @@ -186,7 +186,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.deleteAccess(DATABASE_1_ID, USER_1_ID); + dataServiceGateway.deleteAccess(DATABASE_1.getId(), USER_1.getId()); } @Test @@ -199,7 +199,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.deleteAccess(DATABASE_1_ID, USER_1_ID); + dataServiceGateway.deleteAccess(DATABASE_1.getId(), USER_1.getId()); }); } @@ -213,7 +213,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(AccessNotFoundException.class, () -> { - dataServiceGateway.deleteAccess(DATABASE_1_ID, USER_1_ID); + dataServiceGateway.deleteAccess(DATABASE_1.getId(), USER_1.getId()); }); } @@ -227,7 +227,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.deleteAccess(DATABASE_1_ID, USER_1_ID); + dataServiceGateway.deleteAccess(DATABASE_1.getId(), USER_1.getId()); }); } @@ -241,7 +241,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.deleteAccess(DATABASE_1_ID, USER_1_ID); + dataServiceGateway.deleteAccess(DATABASE_1.getId(), USER_1.getId()); }); } @@ -338,7 +338,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.updateDatabase(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); + dataServiceGateway.updateDatabase(DATABASE_1.getId(), USER_1_UPDATE_PASSWORD_DTO); } @Test @@ -351,7 +351,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.updateDatabase(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); + dataServiceGateway.updateDatabase(DATABASE_1.getId(), USER_1_UPDATE_PASSWORD_DTO); }); } @@ -365,7 +365,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateDatabase(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); + dataServiceGateway.updateDatabase(DATABASE_1.getId(), USER_1_UPDATE_PASSWORD_DTO); }); } @@ -379,7 +379,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - dataServiceGateway.updateDatabase(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); + dataServiceGateway.updateDatabase(DATABASE_1.getId(), USER_1_UPDATE_PASSWORD_DTO); }); } @@ -393,7 +393,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateDatabase(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); + dataServiceGateway.updateDatabase(DATABASE_1.getId(), USER_1_UPDATE_PASSWORD_DTO); }); } @@ -407,7 +407,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateDatabase(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); + dataServiceGateway.updateDatabase(DATABASE_1.getId(), USER_1_UPDATE_PASSWORD_DTO); }); } @@ -421,7 +421,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); } @Test @@ -434,7 +434,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); }); } @@ -448,7 +448,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); }); } @@ -462,7 +462,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); }); } @@ -476,7 +476,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(TableExistsException.class, () -> { - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); }); } @@ -490,7 +490,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); }); } @@ -504,7 +504,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createTable(DATABASE_1_ID, TABLE_1_CREATE_DTO); + dataServiceGateway.createTable(DATABASE_1.getId(), TABLE_1_CREATE_DTO); }); } @@ -518,7 +518,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.deleteTable(DATABASE_1_ID, TABLE_1_ID); + dataServiceGateway.deleteTable(DATABASE_1.getId(), TABLE_1_ID); } @Test @@ -531,7 +531,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.deleteTable(DATABASE_1_ID, TABLE_1_ID); + dataServiceGateway.deleteTable(DATABASE_1.getId(), TABLE_1_ID); }); } @@ -545,7 +545,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.deleteTable(DATABASE_1_ID, TABLE_1_ID); + dataServiceGateway.deleteTable(DATABASE_1.getId(), TABLE_1_ID); }); } @@ -559,7 +559,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(TableNotFoundException.class, () -> { - dataServiceGateway.deleteTable(DATABASE_1_ID, TABLE_1_ID); + dataServiceGateway.deleteTable(DATABASE_1.getId(), TABLE_1_ID); }); } @@ -573,7 +573,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.deleteTable(DATABASE_1_ID, TABLE_1_ID); + dataServiceGateway.deleteTable(DATABASE_1.getId(), TABLE_1_ID); }); } @@ -586,7 +586,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .body(VIEW_1_DTO)); /* test */ - dataServiceGateway.createView(DATABASE_1_ID, VIEW_1_CREATE_DTO); + dataServiceGateway.createView(DATABASE_1.getId(), VIEW_1_CREATE_DTO); } @Test @@ -599,7 +599,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.createView(DATABASE_1_ID, VIEW_1_CREATE_DTO); + dataServiceGateway.createView(DATABASE_1.getId(), VIEW_1_CREATE_DTO); }); } @@ -613,7 +613,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createView(DATABASE_1_ID, VIEW_1_CREATE_DTO); + dataServiceGateway.createView(DATABASE_1.getId(), VIEW_1_CREATE_DTO); }); } @@ -627,7 +627,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createView(DATABASE_1_ID, VIEW_1_CREATE_DTO); + dataServiceGateway.createView(DATABASE_1.getId(), VIEW_1_CREATE_DTO); }); } @@ -641,7 +641,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createView(DATABASE_1_ID, VIEW_1_CREATE_DTO); + dataServiceGateway.createView(DATABASE_1.getId(), VIEW_1_CREATE_DTO); }); } @@ -655,7 +655,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.createView(DATABASE_1_ID, VIEW_1_CREATE_DTO); + dataServiceGateway.createView(DATABASE_1.getId(), VIEW_1_CREATE_DTO); }); } @@ -669,7 +669,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.deleteView(DATABASE_1_ID, VIEW_1_ID); + dataServiceGateway.deleteView(DATABASE_1.getId(), VIEW_1_ID); } @Test @@ -682,7 +682,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.deleteView(DATABASE_1_ID, VIEW_1_ID); + dataServiceGateway.deleteView(DATABASE_1.getId(), VIEW_1_ID); }); } @@ -696,7 +696,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.deleteView(DATABASE_1_ID, VIEW_1_ID); + dataServiceGateway.deleteView(DATABASE_1.getId(), VIEW_1_ID); }); } @@ -710,7 +710,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(ViewNotFoundException.class, () -> { - dataServiceGateway.deleteView(DATABASE_1_ID, VIEW_1_ID); + dataServiceGateway.deleteView(DATABASE_1.getId(), VIEW_1_ID); }); } @@ -724,7 +724,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.deleteView(DATABASE_1_ID, VIEW_1_ID); + dataServiceGateway.deleteView(DATABASE_1.getId(), VIEW_1_ID); }); } @@ -738,7 +738,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .body(QUERY_1_DTO)); /* test */ - dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID); + dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID); } @Test @@ -751,7 +751,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID); + dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID); }); } @@ -765,7 +765,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID); + dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID); }); } @@ -779,7 +779,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(QueryNotFoundException.class, () -> { - dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID); + dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID); }); } @@ -793,7 +793,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID); + dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID); }); } @@ -807,7 +807,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID); + dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID); }); } @@ -820,7 +820,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .body(new TableDto[]{})); /* test */ - dataServiceGateway.getTableSchemas(DATABASE_1_ID); + dataServiceGateway.getTableSchemas(DATABASE_1.getId()); } @Test @@ -833,7 +833,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.getTableSchemas(DATABASE_1_ID); + dataServiceGateway.getTableSchemas(DATABASE_1.getId()); }); } @@ -847,7 +847,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getTableSchemas(DATABASE_1_ID); + dataServiceGateway.getTableSchemas(DATABASE_1.getId()); }); } @@ -861,7 +861,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(TableNotFoundException.class, () -> { - dataServiceGateway.getTableSchemas(DATABASE_1_ID); + dataServiceGateway.getTableSchemas(DATABASE_1.getId()); }); } @@ -875,7 +875,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getTableSchemas(DATABASE_1_ID); + dataServiceGateway.getTableSchemas(DATABASE_1.getId()); }); } @@ -889,7 +889,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getTableSchemas(DATABASE_1_ID); + dataServiceGateway.getTableSchemas(DATABASE_1.getId()); }); } @@ -903,7 +903,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .body(new ViewDto[]{})); /* test */ - dataServiceGateway.getViewSchemas(DATABASE_1_ID); + dataServiceGateway.getViewSchemas(DATABASE_1.getId()); } @Test @@ -916,7 +916,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.getViewSchemas(DATABASE_1_ID); + dataServiceGateway.getViewSchemas(DATABASE_1.getId()); }); } @@ -930,7 +930,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getViewSchemas(DATABASE_1_ID); + dataServiceGateway.getViewSchemas(DATABASE_1.getId()); }); } @@ -944,7 +944,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(ViewNotFoundException.class, () -> { - dataServiceGateway.getViewSchemas(DATABASE_1_ID); + dataServiceGateway.getViewSchemas(DATABASE_1.getId()); }); } @@ -958,7 +958,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getViewSchemas(DATABASE_1_ID); + dataServiceGateway.getViewSchemas(DATABASE_1.getId()); }); } @@ -972,7 +972,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getViewSchemas(DATABASE_1_ID); + dataServiceGateway.getViewSchemas(DATABASE_1.getId()); }); } @@ -986,7 +986,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .body(TABLE_8_STATISTIC_DTO)); /* test */ - dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID); + dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID); } @Test @@ -999,7 +999,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID); + dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID); }); } @@ -1013,7 +1013,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID); + dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID); }); } @@ -1027,7 +1027,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(TableNotFoundException.class, () -> { - dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID); + dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID); }); } @@ -1041,7 +1041,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID); + dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID); }); } @@ -1055,7 +1055,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { .build()); /* test */ - dataServiceGateway.updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + dataServiceGateway.updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); } @Test @@ -1068,7 +1068,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataServiceGateway.updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + dataServiceGateway.updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); }); } @@ -1082,7 +1082,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - dataServiceGateway.updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + dataServiceGateway.updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); }); } @@ -1096,7 +1096,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + dataServiceGateway.updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); }); } @@ -1110,7 +1110,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + dataServiceGateway.updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); }); } @@ -1124,7 +1124,7 @@ public class DataServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DataServiceException.class, () -> { - dataServiceGateway.updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + dataServiceGateway.updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); }); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/KeycloakGatewayIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/KeycloakGatewayIntegrationTest.java index 40d8eab970..e8465d68cb 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/KeycloakGatewayIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/KeycloakGatewayIntegrationTest.java @@ -37,7 +37,7 @@ public class KeycloakGatewayIntegrationTest extends BaseTest { @BeforeEach public void beforeEach() { /* auth service */ - keycloakUtils.deleteUser(USER_1_USERNAME); + keycloakUtils.deleteUser("junit1"); } @Container @@ -59,10 +59,10 @@ public class KeycloakGatewayIntegrationTest extends BaseTest { public void deleteUser_succeeds() throws UserNotFoundException { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - keycloakGateway.deleteUser(keycloakUtils.getUserId(USER_1_USERNAME)); + keycloakGateway.deleteUser(keycloakUtils.getUserId("junit1")); } @Test @@ -70,7 +70,7 @@ public class KeycloakGatewayIntegrationTest extends BaseTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - keycloakGateway.deleteUser(USER_1_ID); + keycloakGateway.deleteUser(USER_1.getId()); }); } @@ -78,10 +78,10 @@ public class KeycloakGatewayIntegrationTest extends BaseTest { public void findByUsername_succeeds() throws UserNotFoundException { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - keycloakGateway.findByUsername(USER_1_USERNAME); + keycloakGateway.findByUsername("junit1"); } @Test @@ -89,7 +89,7 @@ public class KeycloakGatewayIntegrationTest extends BaseTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - keycloakGateway.findByUsername(USER_1_USERNAME); + keycloakGateway.findByUsername("junit1"); }); } @@ -97,11 +97,11 @@ public class KeycloakGatewayIntegrationTest extends BaseTest { public void updateUser_succeeds() throws UserNotFoundException, AuthServiceException { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - keycloakGateway.updateUser(keycloakUtils.getUserId(USER_1_USERNAME), USER_1_UPDATE_DTO); - final UserRepresentation user = keycloakUtils.getUser(USER_1_USERNAME); + keycloakGateway.updateUser(keycloakUtils.getUserId("junit1"), USER_1_UPDATE_DTO); + final UserRepresentation user = keycloakUtils.getUser("junit1"); assertNotNull(user.getId()); assertEquals(USER_1_FIRSTNAME, user.getFirstName()); assertEquals(USER_1_LASTNAME, user.getLastName()); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/SearchServiceGatewayUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/SearchServiceGatewayUnitTest.java index 3ff4a3a508..309a82d4b7 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/SearchServiceGatewayUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/gateway/SearchServiceGatewayUnitTest.java @@ -119,7 +119,7 @@ public class SearchServiceGatewayUnitTest extends BaseTest { .thenReturn(mock); /* test */ - searchServiceGateway.delete(DATABASE_1_ID); + searchServiceGateway.delete(DATABASE_1.getId()); } @Test @@ -133,7 +133,7 @@ public class SearchServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(SearchServiceException.class, () -> { - searchServiceGateway.delete(DATABASE_1_ID); + searchServiceGateway.delete(DATABASE_1.getId()); }); } @@ -147,7 +147,7 @@ public class SearchServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(SearchServiceException.class, () -> { - searchServiceGateway.delete(DATABASE_1_ID); + searchServiceGateway.delete(DATABASE_1.getId()); }); } @@ -162,7 +162,7 @@ public class SearchServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(SearchServiceException.class, () -> { - searchServiceGateway.delete(DATABASE_1_ID); + searchServiceGateway.delete(DATABASE_1.getId()); }); } @@ -176,7 +176,7 @@ public class SearchServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(SearchServiceConnectionException.class, () -> { - searchServiceGateway.delete(DATABASE_1_ID); + searchServiceGateway.delete(DATABASE_1.getId()); }); } @@ -190,7 +190,7 @@ public class SearchServiceGatewayUnitTest extends BaseTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - searchServiceGateway.delete(DATABASE_1_ID); + searchServiceGateway.delete(DATABASE_1.getId()); }); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mapper/MetadataMapperUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mapper/MetadataMapperUnitTest.java index ef1ce49f09..9165f407e3 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mapper/MetadataMapperUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mapper/MetadataMapperUnitTest.java @@ -117,7 +117,7 @@ public class MetadataMapperUnitTest extends BaseTest { /* test */ final UserBriefDto response = metadataMapper.userToUserBriefDto(USER_1); assertEquals(USER_1_NAME, response.getName()); - assertEquals(USER_1_NAME + " — @" + USER_1_USERNAME, response.getQualifiedName()); + assertEquals(USER_1_NAME + " — @" + "junit1", response.getQualifiedName()); } @Test diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/AuthenticationPrivilegedIntegrationMvcTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/AuthenticationPrivilegedIntegrationMvcTest.java index eb75887adf..d7b5f415d9 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/AuthenticationPrivilegedIntegrationMvcTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/AuthenticationPrivilegedIntegrationMvcTest.java @@ -85,7 +85,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { containerRepository.save(CONTAINER_1); databaseRepository.save(DATABASE_1); /* keycloak */ - keycloakUtils.deleteUser(USER_1_USERNAME); + keycloakUtils.deleteUser("junit1"); keycloakUtils.deleteUser(USER_LOCAL_ADMIN_USERNAME); } @@ -93,10 +93,10 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { public void findById_database_basicUser_succeeds() throws Exception { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID).with(httpBasic(USER_1_USERNAME, USER_1_PASSWORD))) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId()).with(httpBasic("junit1", USER_1_PASSWORD))) .andDo(print()) .andExpect(status().isOk()); } @@ -108,13 +108,13 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { keycloakUtils.createUser(USER_LOCAL_ADMIN_ID, USER_LOCAL_KEYCLOAK_SIGNUP_REQUEST); /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID).with(httpBasic(USER_LOCAL_ADMIN_USERNAME, USER_LOCAL_ADMIN_PASSWORD))) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId()).with(httpBasic(USER_LOCAL_ADMIN_USERNAME, USER_LOCAL_ADMIN_PASSWORD))) .andDo(print()) - .andExpect(header().string("X-Host", CONTAINER_1_HOST)) - .andExpect(header().string("X-Port", "" + CONTAINER_1_PORT)) + .andExpect(header().string("X-Host", CONTAINER_1.getHost())) + .andExpect(header().string("X-Port", "" + CONTAINER_1.getPort())) .andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME)) .andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD)) - .andExpect(header().string("X-Jdbc-Method", IMAGE_1_JDBC)) + .andExpect(header().string("X-Jdbc-Method", IMAGE_1.getJdbcMethod())) .andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password X-Jdbc-Method X-Host X-Port")) .andExpect(status().isOk()); } @@ -127,13 +127,13 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { final TokenDto jwt = keycloakGateway.obtainUserToken(USER_LOCAL_ADMIN_USERNAME, USER_LOCAL_ADMIN_PASSWORD); /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID).header("Authorization", "Bearer " + jwt.getAccessToken())) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId()).header("Authorization", "Bearer " + jwt.getAccessToken())) .andDo(print()) - .andExpect(header().string("X-Host", CONTAINER_1_HOST)) - .andExpect(header().string("X-Port", "" + CONTAINER_1_PORT)) + .andExpect(header().string("X-Host", CONTAINER_1.getHost())) + .andExpect(header().string("X-Port", "" + CONTAINER_1.getPort())) .andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME)) .andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD)) - .andExpect(header().string("X-Jdbc-Method", IMAGE_1_JDBC)) + .andExpect(header().string("X-Jdbc-Method", IMAGE_1.getJdbcMethod())) .andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password X-Jdbc-Method X-Host X-Port")) .andExpect(status().isOk()); } @@ -147,7 +147,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID + "/table/" + TABLE_1_ID).header("Authorization", "Bearer " + jwt.getAccessToken())) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId() + "/table/" + TABLE_1_ID).header("Authorization", "Bearer " + jwt.getAccessToken())) .andDo(print()) .andExpect(status().isOk()); } @@ -156,10 +156,10 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { public void findById_table_basicUser_succeeds() throws Exception { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID + "/table/" + TABLE_1_ID).with(httpBasic(USER_1_USERNAME, USER_1_PASSWORD))) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId() + "/table/" + TABLE_1_ID).with(httpBasic("junit1", USER_1_PASSWORD))) .andDo(print()) .andExpect(status().isOk()); } @@ -171,7 +171,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { keycloakUtils.createUser(USER_LOCAL_ADMIN_ID, USER_LOCAL_KEYCLOAK_SIGNUP_REQUEST); /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID + "/table/" + TABLE_1_ID).with(httpBasic(USER_LOCAL_ADMIN_USERNAME, USER_LOCAL_ADMIN_PASSWORD))) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId() + "/table/" + TABLE_1_ID).with(httpBasic(USER_LOCAL_ADMIN_USERNAME, USER_LOCAL_ADMIN_PASSWORD))) .andDo(print()) .andExpect(status().isOk()); } @@ -181,10 +181,10 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { public void findById_view_basicUser_succeeds() throws Exception { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_1_ID + "/view/" + VIEW_1_ID).with(httpBasic(USER_1_USERNAME, USER_1_PASSWORD))) + this.mockMvc.perform(get("/api/database/" + DATABASE_1.getId() + "/view/" + VIEW_1_ID).with(httpBasic("junit1", USER_1_PASSWORD))) .andDo(print()) .andExpect(status().isOk()); } @@ -193,10 +193,10 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends BaseTest { public void findById_container_basicUser_succeeds() throws Exception { /* mock */ - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); /* test */ - this.mockMvc.perform(get("/api/container/" + CONTAINER_1_ID).with(httpBasic(USER_1_USERNAME, USER_1_PASSWORD))) + this.mockMvc.perform(get("/api/container/" + CONTAINER_1.getId()).with(httpBasic("junit1", USER_1_PASSWORD))) .andDo(print()) .andExpect(status().isOk()); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/MetadataEndpointMvcTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/MetadataEndpointMvcTest.java index 870251323e..d75421b4bf 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/MetadataEndpointMvcTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/MetadataEndpointMvcTest.java @@ -112,15 +112,15 @@ public class MetadataEndpointMvcTest extends BaseTest { public void getRecord_oai_succeeds() throws Exception { /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) + when(identifierRepository.findById(IDENTIFIER_1.getId())) .thenReturn(Optional.of(IDENTIFIER_1)); /* test */ - this.mockMvc.perform(get("/api/oai?verb=GetRecord&identifier=oai:" + IDENTIFIER_1_ID)) + this.mockMvc.perform(get("/api/oai?verb=GetRecord&identifier=oai:" + IDENTIFIER_1.getId())) .andDo(print()) .andExpect(content().contentType("text/xml;charset=UTF-8")) .andExpect(xpath("//request[@verb='GetRecord']").exists()) - .andExpect(xpath("//request[@identifier='oai:" + IDENTIFIER_1_ID + "']").exists()) + .andExpect(xpath("//request[@identifier='oai:" + IDENTIFIER_1.getId() + "']").exists()) .andExpect(xpath("//identifier").string("doi:" + IDENTIFIER_1_DOI)) .andExpect(status().isOk()); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/PrometheusEndpointMvcTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/PrometheusEndpointMvcTest.java index 198a6c6270..fce5a7bf2e 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/PrometheusEndpointMvcTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/mvc/PrometheusEndpointMvcTest.java @@ -107,27 +107,27 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database-access", "update-database-access", "check-database-access", "delete-database-access"}) + @WithMockUser(username = "junit1", authorities = {"create-database-access", "update-database-access", "check-database-access", "delete-database-access"}) public void prometheusAccessEndpoint_succeeds() { /* mock */ try { - accessEndpoint.create(DATABASE_1_ID, USER_1_ID, UPDATE_DATABASE_ACCESS_READ_DTO, USER_1_PRINCIPAL); + accessEndpoint.create(DATABASE_1.getId(), USER_1.getId(), UPDATE_DATABASE_ACCESS_READ_DTO, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - accessEndpoint.update(DATABASE_1_ID, USER_1_ID, UPDATE_DATABASE_ACCESS_READ_DTO, USER_1_PRINCIPAL); + accessEndpoint.update(DATABASE_1.getId(), USER_1.getId(), UPDATE_DATABASE_ACCESS_READ_DTO, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - accessEndpoint.find(DATABASE_1_ID, USER_1_ID, USER_1_PRINCIPAL); + accessEndpoint.find(DATABASE_1.getId(), USER_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - accessEndpoint.revoke(DATABASE_1_ID, USER_1_ID, USER_1_PRINCIPAL); + accessEndpoint.revoke(DATABASE_1.getId(), USER_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } @@ -140,7 +140,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-container", "delete-container"}) + @WithMockUser(username = "junit1", authorities = {"create-container", "delete-container"}) public void prometheusContainerEndpoint_succeeds() { /* mock */ @@ -150,17 +150,17 @@ public class PrometheusEndpointMvcTest extends BaseTest { /* ignore */ } try { - containerEndpoint.create(CreateContainerDto.builder().name(CONTAINER_1_NAME).imageId(IMAGE_1_ID).build()); + containerEndpoint.create(CreateContainerDto.builder().name(CONTAINER_1.getName()).imageId(CONTAINER_1.getId()).build()); } catch (Exception e) { /* ignore */ } try { - containerEndpoint.findById(CONTAINER_1_ID, USER_1_PRINCIPAL); + containerEndpoint.findById(CONTAINER_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - containerEndpoint.delete(CONTAINER_1_ID); + containerEndpoint.delete(CONTAINER_1.getId()); } catch (Exception e) { /* ignore */ } @@ -173,7 +173,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database", "modify-database-visibility", "modify-database-owner", "delete-database", "modify-database-image"}) + @WithMockUser(username = "junit1", authorities = {"create-database", "modify-database-visibility", "modify-database-owner", "delete-database", "modify-database-image"}) public void prometheusDatabaseEndpoint_succeeds() { /* mock */ @@ -188,27 +188,27 @@ public class PrometheusEndpointMvcTest extends BaseTest { /* ignore */ } try { - databaseEndpoint.visibility(DATABASE_1_ID, DatabaseModifyVisibilityDto.builder().isPublic(true).build(), USER_1_PRINCIPAL); + databaseEndpoint.visibility(DATABASE_1.getId(), DatabaseModifyVisibilityDto.builder().isPublic(true).build(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - databaseEndpoint.transfer(DATABASE_1_ID, DatabaseTransferDto.builder().id(USER_2_ID).build(), USER_1_PRINCIPAL); + databaseEndpoint.transfer(DATABASE_1.getId(), DatabaseTransferDto.builder().id(USER_2.getId()).build(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - databaseEndpoint.findById(DATABASE_1_ID, USER_1_PRINCIPAL); + databaseEndpoint.findById(DATABASE_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - databaseEndpoint.modifyImage(DATABASE_1_ID, DatabaseModifyImageDto.builder().build(), USER_1_PRINCIPAL); + databaseEndpoint.modifyImage(DATABASE_1.getId(), DatabaseModifyImageDto.builder().build(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - databaseEndpoint.findPreviewImage(DATABASE_1_ID); + databaseEndpoint.findPreviewImage(DATABASE_1.getId()); } catch (Exception e) { /* ignore */ } @@ -221,22 +221,22 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-identifier", "create-foreign-identifier", "publish-identifier"}) + @WithMockUser(username = "junit1", authorities = {"create-identifier", "create-foreign-identifier", "publish-identifier"}) public void prometheusIdentifierEndpoint_succeeds() { /* mock */ try { - identifierEndpoint.create(IDENTIFIER_1_CREATE_DTO, USER_1_PRINCIPAL); + identifierEndpoint.create(metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - identifierEndpoint.save(IDENTIFIER_1_ID, IDENTIFIER_1_SAVE_DTO, USER_1_PRINCIPAL); + identifierEndpoint.save(IDENTIFIER_1.getId(), metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - identifierEndpoint.publish(IDENTIFIER_1_ID); + identifierEndpoint.publish(IDENTIFIER_1.getId()); } catch (Exception e) { /* ignore */ } @@ -246,12 +246,12 @@ public class PrometheusEndpointMvcTest extends BaseTest { /* ignore */ } try { - identifierEndpoint.delete(IDENTIFIER_1_ID); + identifierEndpoint.delete(IDENTIFIER_1.getId()); } catch (Exception e) { /* ignore */ } try { - identifierEndpoint.findAll(IdentifierTypeDto.DATABASE, null, DATABASE_1_ID, null, null, null, MediaType.APPLICATION_JSON_VALUE, null); + identifierEndpoint.findAll(IdentifierTypeDto.DATABASE, null, DATABASE_1.getId(), null, null, null, MediaType.APPLICATION_JSON_VALUE, null); } catch (Exception e) { /* ignore */ } @@ -266,7 +266,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-image", "modify-image", "delete-image"}) + @WithMockUser(username = "junit1", authorities = {"create-image", "modify-image", "delete-image"}) public void prometheusImageEndpoint_succeeds() { /* mock */ @@ -276,22 +276,22 @@ public class PrometheusEndpointMvcTest extends BaseTest { /* ignore */ } try { - imageEndpoint.create(IMAGE_1_CREATE_DTO, USER_1_PRINCIPAL); + imageEndpoint.create(metadataMapper.containerImageToCreateImageDto(IMAGE_1_), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - imageEndpoint.findById(IMAGE_1_ID); + imageEndpoint.findById(CONTAINER_1.getId()); } catch (Exception e) { /* ignore */ } try { - imageEndpoint.update(IMAGE_1_ID, IMAGE_1_CHANGE_DTO); + imageEndpoint.update(CONTAINER_1.getId(), IMAGE_1_CHANGE_DTO); } catch (Exception e) { /* ignore */ } try { - imageEndpoint.delete(IMAGE_1_ID); + imageEndpoint.delete(CONTAINER_1.getId()); } catch (Exception e) { /* ignore */ } @@ -305,7 +305,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void prometheusLicenseEndpoint_succeeds() { /* mock */ @@ -321,7 +321,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-maintenance-message", "update-maintenance-message", "delete-maintenance-message"}) + @WithMockUser(username = "junit1", authorities = {"create-maintenance-message", "update-maintenance-message", "delete-maintenance-message"}) public void prometheusMaintenanceEndpoint_succeeds() { /* mock */ @@ -359,7 +359,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME) + @WithMockUser(username = "junit1") public void prometheusMetadataEndpoint_succeeds() { /* mock */ @@ -392,7 +392,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-ontology", "update-ontology", "delete-ontology", "execute-semantic-query"}) + @WithMockUser(username = "junit1", authorities = {"create-ontology", "update-ontology", "delete-ontology", "execute-semantic-query"}) public void prometheusOntologyEndpoint_succeeds() { /* mock */ @@ -435,7 +435,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-semantic-concept", "admin"}) + @WithMockUser(username = "junit1", authorities = {"create-semantic-concept", "admin"}) public void prometheusConceptEndpoint_succeeds() { /* mock */ @@ -453,7 +453,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-semantic-unit", "admin"}) + @WithMockUser(username = "junit1", authorities = {"create-semantic-unit", "admin"}) public void prometheusUnitEndpoint_succeeds() { /* mock */ @@ -471,7 +471,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-table", "delete-table", + @WithMockUser(username = "junit1", authorities = {"create-table", "delete-table", "modify-table-column-semantics", "modify-foreign-table-column-semantics", "update-table-statistic", "table-semantic-analyse"}) public void prometheusTableEndpoint_succeeds() { @@ -482,42 +482,42 @@ public class PrometheusEndpointMvcTest extends BaseTest { /* mock */ try { - tableEndpoint.list(DATABASE_1_ID, USER_1_PRINCIPAL); + tableEndpoint.list(DATABASE_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.create(DATABASE_1_ID, TABLE_3_CREATE_DTO, USER_1_PRINCIPAL); + tableEndpoint.create(DATABASE_1.getId(), TABLE_3_CREATE_DTO, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.findById(DATABASE_1_ID, TABLE_1_ID, USER_1_PRINCIPAL); + tableEndpoint.findById(DATABASE_1.getId(), TABLE_1_ID, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.delete(DATABASE_1_ID, TABLE_1_ID, USER_1_PRINCIPAL); + tableEndpoint.delete(DATABASE_1.getId(), TABLE_1_ID, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.analyseTable(DATABASE_1_ID, TABLE_1_ID, USER_1_PRINCIPAL); + tableEndpoint.analyseTable(DATABASE_1.getId(), TABLE_1_ID, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.updateStatistic(DATABASE_1_ID, TABLE_1_ID, USER_1_PRINCIPAL); + tableEndpoint.updateStatistic(DATABASE_1.getId(), TABLE_1_ID, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.analyseTableColumn(DATABASE_1_ID, TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), USER_1_PRINCIPAL); + tableEndpoint.analyseTableColumn(DATABASE_1.getId(), TABLE_1_ID, TABLE_1_COLUMNS.get(0).getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - tableEndpoint.updateColumn(DATABASE_1_ID, TABLE_1_ID, TABLE_1_COLUMNS.get(3).getId(), request, USER_1_PRINCIPAL); + tableEndpoint.updateColumn(DATABASE_1.getId(), TABLE_1_ID, TABLE_1_COLUMNS.get(3).getId(), request, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } @@ -532,7 +532,7 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"find-user", "modify-user-information", "modify-user-theme"}) + @WithMockUser(username = "junit1", authorities = {"find-user", "modify-user-information", "modify-user-theme"}) public void prometheusUserEndpoint_succeeds() { /* mock */ @@ -542,12 +542,12 @@ public class PrometheusEndpointMvcTest extends BaseTest { /* ignore */ } try { - userEndpoint.find(USER_1_ID, USER_1_PRINCIPAL); + userEndpoint.find(USER_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - userEndpoint.modify(USER_1_ID, USER_1_UPDATE_DTO, USER_1_PRINCIPAL); + userEndpoint.modify(USER_1.getId(), USER_1_UPDATE_DTO, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } @@ -560,27 +560,27 @@ public class PrometheusEndpointMvcTest extends BaseTest { } @Test - @WithMockUser(username = USER_1_USERNAME, authorities = {"create-database-view", "delete-database-view"}) + @WithMockUser(username = "junit1", authorities = {"create-database-view", "delete-database-view"}) public void prometheusViewEndpoint_succeeds() { /* mock */ try { - viewEndpoint.findAll(DATABASE_1_ID, USER_1_PRINCIPAL); + viewEndpoint.findAll(DATABASE_1.getId(), USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - viewEndpoint.create(DATABASE_1_ID, VIEW_1_CREATE_DTO, USER_1_PRINCIPAL); + viewEndpoint.create(DATABASE_1.getId(), VIEW_1_CREATE_DTO, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - viewEndpoint.find(DATABASE_1_ID, VIEW_1_ID, USER_1_PRINCIPAL); + viewEndpoint.find(DATABASE_1.getId(), VIEW_1_ID, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } try { - viewEndpoint.delete(DATABASE_1_ID, VIEW_1_ID, USER_1_PRINCIPAL); + viewEndpoint.delete(DATABASE_1.getId(), VIEW_1_ID, USER_1_PRINCIPAL); } catch (Exception e) { /* ignore */ } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AccessServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AccessServiceUnitTest.java index 17a7cb32f8..80ba929678 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AccessServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AccessServiceUnitTest.java @@ -369,7 +369,7 @@ public class AccessServiceUnitTest extends BaseTest { DatabaseNotFoundException, SearchServiceException, SearchServiceConnectionException { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -430,7 +430,7 @@ public class AccessServiceUnitTest extends BaseTest { public void delete_searchService400_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -451,7 +451,7 @@ public class AccessServiceUnitTest extends BaseTest { public void delete_searchService403_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -472,7 +472,7 @@ public class AccessServiceUnitTest extends BaseTest { public void delete_searchService404_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -493,7 +493,7 @@ public class AccessServiceUnitTest extends BaseTest { public void delete_searchService500_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AuthenticationServiceIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AuthenticationServiceIntegrationTest.java index 016e0f949b..59e5d0d3a3 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AuthenticationServiceIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/AuthenticationServiceIntegrationTest.java @@ -57,11 +57,11 @@ public class AuthenticationServiceIntegrationTest extends BaseTest { AuthServiceException, AuthServiceConnectionException, CredentialsInvalidException { /* mock */ - keycloakUtils.deleteUser(USER_1_USERNAME); - keycloakUtils.createUser(USER_1_ID, USER_1_KEYCLOAK_SIGNUP_REQUEST); + keycloakUtils.deleteUser("junit1"); + keycloakUtils.createUser(USER_1.getId(), USER_1_KEYCLOAK_SIGNUP_REQUEST); final User request = User.builder() - .keycloakId(UUID.fromString(keycloakGateway.findByUsername(USER_1_USERNAME).getId())) - .username(USER_1_USERNAME) + .keycloakId(UUID.fromString(keycloakGateway.findByUsername("junit1").getId())) + .username("junit1") .build(); /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/BrokerServiceIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/BrokerServiceIntegrationTest.java index 05ab5f8bc7..6f805a4f70 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/BrokerServiceIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/BrokerServiceIntegrationTest.java @@ -45,7 +45,7 @@ public class BrokerServiceIntegrationTest extends BaseTest { @Container private static final RabbitMQContainer rabbitContainer = new RabbitMQContainer("rabbitmq:3-management") - .withUser(USER_1_USERNAME, USER_1_PASSWORD, Set.of("administrator")) + .withUser("junit1", USER_1_PASSWORD, Set.of("administrator")) .withVhost("dbrepo"); @DynamicPropertySource @@ -58,7 +58,7 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final VirtualHostPermissionDto permissions = setVirtualHostPermissions_generic(); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals("", permissions.getConfigure()); assertEquals(".*", permissions.getRead()); @@ -70,7 +70,7 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final VirtualHostPermissionDto permissions = setVirtualHostPermissions_generic(); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals("", permissions.getConfigure()); assertEquals(".*", permissions.getRead()); @@ -82,7 +82,7 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final VirtualHostPermissionDto permissions = setVirtualHostPermissions_generic(); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals("", permissions.getConfigure()); assertEquals(".*", permissions.getRead()); @@ -94,7 +94,7 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final VirtualHostPermissionDto permissions = setVirtualHostPermissions_generic(); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals("", permissions.getConfigure()); assertEquals(".*", permissions.getRead()); @@ -108,7 +108,7 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final TopicPermissionDto permissions = setTopicExchangePermissions_generic(List.of()); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals(DATABASE_1_EXCHANGE, permissions.getExchange()); assertEquals("", permissions.getRead()); @@ -122,11 +122,11 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final TopicPermissionDto permissions = setTopicExchangePermissions_generic(List.of(DATABASE_1_USER_1_WRITE_ALL_ACCESS)); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals(DATABASE_1_EXCHANGE, permissions.getExchange()); - assertEquals("^(dbrepo\\." + DATABASE_1_ID + "\\..*)$", permissions.getRead()); - assertEquals("^(dbrepo\\." + DATABASE_1_ID + "\\..*)$", permissions.getWrite()); + assertEquals("^(dbrepo\\." + DATABASE_1.getId() + "\\..*)$", permissions.getRead()); + assertEquals("^(dbrepo\\." + DATABASE_1.getId() + "\\..*)$", permissions.getWrite()); } @Test @@ -136,11 +136,11 @@ public class BrokerServiceIntegrationTest extends BaseTest { /* test */ final TopicPermissionDto permissions = setTopicExchangePermissions_generic(List.of(DATABASE_1_USER_1_WRITE_OWN_ACCESS)); - assertEquals(USER_1_USERNAME, permissions.getUser()); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals(DATABASE_1_EXCHANGE, permissions.getExchange()); - assertEquals("^(dbrepo\\." + DATABASE_1_ID + "\\..*)$", permissions.getRead()); - assertEquals("^(dbrepo\\." + DATABASE_1_ID + "\\." + TABLE_1_ID + "|dbrepo\\." + DATABASE_1_ID + "\\." + TABLE_4_ID + ")$", permissions.getWrite()); + assertEquals("^(dbrepo\\." + DATABASE_1.getId() + "\\..*)$", permissions.getRead()); + assertEquals("^(dbrepo\\." + DATABASE_1.getId() + "\\." + TABLE_1_ID + "|dbrepo\\." + DATABASE_1.getId() + "\\." + TABLE_4_ID + ")$", permissions.getWrite()); } @Test @@ -149,11 +149,11 @@ public class BrokerServiceIntegrationTest extends BaseTest { BrokerServiceConnectionException { /* test */ - final TopicPermissionDto permissions = setTopicExchangePermissions_generic(List.of(DATABASE_1_USER_1_READ_ACCESS)); - assertEquals(USER_1_USERNAME, permissions.getUser()); + final TopicPermissionDto permissions = setTopicExchangePermissions_generic(List.of(DATABASE_1.getAccesses().get(0))); + assertEquals("junit1", permissions.getUser()); assertEquals(REALM_DBREPO_NAME, permissions.getVhost()); assertEquals(DATABASE_1_EXCHANGE, permissions.getExchange()); - assertEquals("^(dbrepo\\." + DATABASE_1_ID + "\\..*)$", permissions.getRead()); + assertEquals("^(dbrepo\\." + DATABASE_1.getId() + "\\..*)$", permissions.getRead()); assertEquals("", permissions.getWrite()); } @@ -171,11 +171,11 @@ public class BrokerServiceIntegrationTest extends BaseTest { final AmqpUtils amqpUtils = new AmqpUtils(rabbitContainer.getHttpUrl()); /* mock */ - amqpUtils.setVirtualHostPermissions(REALM_DBREPO_NAME, USER_1_USERNAME, permissions); + amqpUtils.setVirtualHostPermissions(REALM_DBREPO_NAME, "junit1", permissions); /* test */ brokerService.setVirtualHostPermissions(USER_1); - return amqpUtils.getVirtualHostPermissions(USER_1_USERNAME); + return amqpUtils.getVirtualHostPermissions("junit1"); } @Transactional(readOnly = true) @@ -188,18 +188,18 @@ public class BrokerServiceIntegrationTest extends BaseTest { .write("") .build(); final User user = User.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) + .id(USER_1.getId()) + .username("junit1") .accesses(accesses) .build(); /* mock */ - amqpUtils.setVirtualHostPermissions(REALM_DBREPO_NAME, USER_1_USERNAME, VIRTUAL_HOST_GRANT_DTO); - amqpUtils.setTopicPermissions(REALM_DBREPO_NAME, USER_1_USERNAME, request); + amqpUtils.setVirtualHostPermissions(REALM_DBREPO_NAME, "junit1", VIRTUAL_HOST_GRANT_DTO); + amqpUtils.setTopicPermissions(REALM_DBREPO_NAME, "junit1", request); /* test */ brokerService.setTopicExchangePermissions(user); - return amqpUtils.getTopicPermissions(USER_1_USERNAME); + return amqpUtils.getTopicPermissions("junit1"); } } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ContainerServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ContainerServiceUnitTest.java index 3af0a8816b..11755e66b8 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ContainerServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ContainerServiceUnitTest.java @@ -45,32 +45,32 @@ public class ContainerServiceUnitTest extends BaseTest { @Test public void create_succeeds() throws ContainerAlreadyExistsException, ImageNotFoundException { final CreateContainerDto request = CreateContainerDto.builder() - .imageId(IMAGE_1_ID) - .name(CONTAINER_1_NAME) + .imageId(CONTAINER_1.getId()) + .name(CONTAINER_1.getName()) .build(); /* mock */ - when(containerRepository.findByInternalName(CONTAINER_1_NAME)) + when(containerRepository.findByInternalName(CONTAINER_1.getName())) .thenReturn(Optional.empty()); - when(imageRepository.findById(IMAGE_1_ID)) + when(imageRepository.findById(CONTAINER_1.getId())) .thenReturn(Optional.of(IMAGE_1)); when(containerRepository.save(any(Container.class))) .thenReturn(CONTAINER_1); /* test */ final Container container = containerService.create(request); - assertEquals(CONTAINER_1_NAME, container.getName()); + assertEquals(CONTAINER_1.getName(), container.getName()); } @Test public void create_containerExists_fails() { final CreateContainerDto request = CreateContainerDto.builder() - .imageId(IMAGE_1_ID) - .name(CONTAINER_1_NAME) + .imageId(CONTAINER_1.getId()) + .name(CONTAINER_1.getName()) .build(); /* mock */ - when(containerRepository.findByInternalName(CONTAINER_1_INTERNALNAME)) + when(containerRepository.findByInternalName(CONTAINER_1.getInternalName())) .thenReturn(Optional.of(CONTAINER_1)); /* test */ @@ -87,9 +87,9 @@ public class ContainerServiceUnitTest extends BaseTest { .build(); /* mock */ - when(containerRepository.findByInternalName(CONTAINER_1_NAME)) + when(containerRepository.findByInternalName(CONTAINER_1.getName())) .thenReturn(Optional.empty()); - when(imageRepository.findById(IMAGE_1_ID)) + when(imageRepository.findById(CONTAINER_1.getId())) .thenReturn(Optional.empty()); /* test */ @@ -103,7 +103,7 @@ public class ContainerServiceUnitTest extends BaseTest { /* test */ assertThrows(ContainerNotFoundException.class, () -> { - find_generic(CONTAINER_1_ID, null); + find_generic(CONTAINER_1.getId(), null); }); } @@ -111,7 +111,7 @@ public class ContainerServiceUnitTest extends BaseTest { public void find_succeeds() throws ContainerNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, CONTAINER_1); + find_generic(CONTAINER_1.getId(), CONTAINER_1); } @Test @@ -178,6 +178,6 @@ public class ContainerServiceUnitTest extends BaseTest { /* test */ final Container response = containerService.find(containerId); - assertEquals(CONTAINER_1_ID, response.getId()); + assertEquals(CONTAINER_1.getId(), response.getId()); } } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DataCiteIdentifierServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DataCiteIdentifierServicePersistenceTest.java index 3f3720b2d8..23738e761d 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DataCiteIdentifierServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DataCiteIdentifierServicePersistenceTest.java @@ -88,7 +88,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { /* test */ final List<Identifier> response = dataCiteIdentifierService.findAll(null, null, null, null, null); assertEquals(7, response.size()); - for (UUID id : List.of(IDENTIFIER_1_ID, IDENTIFIER_2_ID, IDENTIFIER_3_ID, IDENTIFIER_4_ID, IDENTIFIER_5_ID, IDENTIFIER_6_ID, IDENTIFIER_7_ID)) { + for (UUID id : List.of(IDENTIFIER_1.getId(), IDENTIFIER_2_ID, IDENTIFIER_3_ID, IDENTIFIER_4_ID, IDENTIFIER_5_ID, IDENTIFIER_6_ID, IDENTIFIER_7.getId())) { assertTrue(response.stream().map(Identifier::getId).toList().contains(id)); } } @@ -97,9 +97,9 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { public void findAll_databaseId_succeeds() { /* test */ - final List<Identifier> response = dataCiteIdentifierService.findAll(null, DATABASE_1_ID, null, null, null); + final List<Identifier> response = dataCiteIdentifierService.findAll(null, DATABASE_1.getId(), null, null, null); assertEquals(4, response.size()); - assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_1_ID)); + assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_1.getId())); assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_2_ID)); assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_3_ID)); assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_4_ID)); @@ -117,7 +117,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { public void findAll_empty_succeeds() { /* test */ - final List<Identifier> response = dataCiteIdentifierService.findAll(null, DATABASE_2_ID, QUERY_1_ID, null, null); + final List<Identifier> response = dataCiteIdentifierService.findAll(null, DATABASE_2.getId(), QUERY_1_ID, null, null); assertEquals(0, response.size()); } @@ -126,7 +126,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { public void find_succeeds() throws IdentifierNotFoundException { /* test */ - final Identifier response = dataCiteIdentifierService.find(IDENTIFIER_1_ID); + final Identifier response = dataCiteIdentifierService.find(IDENTIFIER_1.getId()); assertEquals(IDENTIFIER_1, response); } @@ -144,7 +144,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { .thenReturn(DATABASE_1_BRIEF_DTO); /* test */ - dataCiteIdentifierService.save(DATABASE_1, USER_1, IDENTIFIER_1_SAVE_DTO); + dataCiteIdentifierService.save(DATABASE_1, USER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1)); } @Test @@ -160,7 +160,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { /* test */ assertThrows(MalformedException.class, () -> { - dataCiteIdentifierService.save(DATABASE_1, USER_1, IDENTIFIER_1_SAVE_DTO); + dataCiteIdentifierService.save(DATABASE_1, USER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1)); }); } @@ -177,7 +177,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { /* test */ assertThrows(DataServiceConnectionException.class, () -> { - dataCiteIdentifierService.save(DATABASE_1, USER_1, IDENTIFIER_1_SAVE_DTO); + dataCiteIdentifierService.save(DATABASE_1, USER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1)); }); } @@ -194,7 +194,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { .thenReturn(mock); /* test */ - final Identifier response = dataCiteIdentifierService.create(DATABASE_1, USER_1, IDENTIFIER_1_CREATE_DTO); + final Identifier response = dataCiteIdentifierService.create(DATABASE_1, USER_1, metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1)); assertNotNull(response.getDoi()); } @@ -227,7 +227,7 @@ public class DataCiteIdentifierServicePersistenceTest extends BaseTest { /* test */ final Identifier response = dataCiteIdentifierService.publish(IDENTIFIER_7); - assertEquals(IDENTIFIER_7_ID, response.getId()); + assertEquals(IDENTIFIER_7.getId(), response.getId()); assertEquals(IdentifierStatusType.PUBLISHED, response.getStatus()); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServicePersistenceTest.java index c0d36efdba..c5e39d95b9 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServicePersistenceTest.java @@ -56,7 +56,7 @@ public class DatabaseServicePersistenceTest extends BaseTest { public void findById_succeeds() throws DatabaseNotFoundException { /* test */ - final Database response = databaseService.findById(DATABASE_1_ID); + final Database response = databaseService.findById(DATABASE_1.getId()); assertEquals(DATABASE_1, response); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServiceUnitTest.java index d38b12b3ab..05ba776388 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/DatabaseServiceUnitTest.java @@ -61,10 +61,10 @@ public class DatabaseServiceUnitTest extends BaseTest { public void findById_succeeds() throws DatabaseNotFoundException { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); - final Database response = databaseService.findById(DATABASE_1_ID); + final Database response = databaseService.findById(DATABASE_1.getId()); /* test */ assertEquals(DATABASE_1, response); @@ -74,12 +74,12 @@ public class DatabaseServiceUnitTest extends BaseTest { public void findById_notFound_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.empty()); /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - databaseService.findById(DATABASE_1_ID); + databaseService.findById(DATABASE_1.getId()); }); } @@ -88,11 +88,11 @@ public class DatabaseServiceUnitTest extends BaseTest { DataServiceConnectionException { /* mock */ - when(databaseRepository.findAllAtLestReadAccessDesc(USER_1_ID)) + when(databaseRepository.findAllAtLestReadAccessDesc(USER_1.getId())) .thenReturn(List.of(DATABASE_1)); doNothing() .when(dataServiceGateway) - .updateDatabase(eq(DATABASE_1_ID), any(UpdateUserPasswordDto.class)); + .updateDatabase(eq(DATABASE_1.getId()), any(UpdateUserPasswordDto.class)); /* test */ databaseService.updatePassword(DATABASE_1, USER_1); @@ -155,7 +155,7 @@ public class DatabaseServiceUnitTest extends BaseTest { DataServiceConnectionException, ViewNotFoundException { /* mock */ - when(dataServiceGateway.getViewSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getViewSchemas(DATABASE_1.getId())) .thenReturn(List.of()); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -173,7 +173,7 @@ public class DatabaseServiceUnitTest extends BaseTest { ViewNotFoundException { /* mock */ - when(dataServiceGateway.getViewSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getViewSchemas(DATABASE_1.getId())) .thenReturn(List.of()); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -193,7 +193,7 @@ public class DatabaseServiceUnitTest extends BaseTest { ViewNotFoundException { /* mock */ - when(dataServiceGateway.getViewSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getViewSchemas(DATABASE_1.getId())) .thenReturn(List.of()); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -213,7 +213,7 @@ public class DatabaseServiceUnitTest extends BaseTest { DataServiceConnectionException, ViewNotFoundException { /* mock */ - when(dataServiceGateway.getViewSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getViewSchemas(DATABASE_1.getId())) .thenReturn(List.of(VIEW_1_DTO, VIEW_2_DTO, VIEW_3_DTO, VIEW_4_DTO)); /* <<< */ when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -231,7 +231,7 @@ public class DatabaseServiceUnitTest extends BaseTest { DataServiceConnectionException, ViewNotFoundException { /* mock */ - when(dataServiceGateway.getViewSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getViewSchemas(DATABASE_1.getId())) .thenReturn(List.of(VIEW_1_DTO, VIEW_2_DTO, VIEW_3_DTO)); /* <<< */ when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -249,7 +249,7 @@ public class DatabaseServiceUnitTest extends BaseTest { SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(dataServiceGateway.getTableSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getTableSchemas(DATABASE_1.getId())) .thenReturn(List.of()); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -267,7 +267,7 @@ public class DatabaseServiceUnitTest extends BaseTest { SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(dataServiceGateway.getTableSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getTableSchemas(DATABASE_1.getId())) .thenReturn(List.of(TABLE_1_DTO, TABLE_2_DTO, TABLE_3_DTO, TABLE_4_DTO)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -285,7 +285,7 @@ public class DatabaseServiceUnitTest extends BaseTest { SearchServiceConnectionException, DataServiceConnectionException { /* mock */ - when(dataServiceGateway.getTableSchemas(DATABASE_1_ID)) + when(dataServiceGateway.getTableSchemas(DATABASE_1.getId())) .thenReturn(List.of(TABLE_1_DTO, TABLE_2_DTO, TABLE_3_DTO, TABLE_4_DTO, TABLE_5_DTO)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -331,12 +331,12 @@ public class DatabaseServiceUnitTest extends BaseTest { public void find_succeeds() throws DatabaseNotFoundException { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_1)); /* test */ - final Database response = databaseService.findById(DATABASE_1_ID); - assertEquals(DATABASE_1_ID, response.getId()); + final Database response = databaseService.findById(DATABASE_1.getId()); + assertEquals(DATABASE_1.getId(), response.getId()); } @Test @@ -453,9 +453,9 @@ public class DatabaseServiceUnitTest extends BaseTest { /* test */ final Database response = generic_modifyOwner(DATABASE_1, USER_2); assertEquals(USER_2, response.getOwner()); - assertEquals(USER_2_ID, response.getOwnedBy()); + assertEquals(USER_2.getId(), response.getOwnedBy()); assertEquals(USER_2, response.getContact()); - assertEquals(USER_2_ID, response.getContactPerson()); + assertEquals(USER_2.getId(), response.getContactPerson()); } @Test diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/IdentifierServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/IdentifierServicePersistenceTest.java index 3474e21f47..b3da5c6691 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/IdentifierServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/IdentifierServicePersistenceTest.java @@ -83,7 +83,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { /* test */ final List<Identifier> response = identifierService.findAll(null, null, null, null, null); assertEquals(7, response.size()); - for (UUID id : List.of(IDENTIFIER_1_ID, IDENTIFIER_2_ID, IDENTIFIER_3_ID, IDENTIFIER_4_ID, IDENTIFIER_5_ID, IDENTIFIER_6_ID, IDENTIFIER_7_ID)) { + for (UUID id : List.of(IDENTIFIER_1.getId(), IDENTIFIER_2_ID, IDENTIFIER_3_ID, IDENTIFIER_4_ID, IDENTIFIER_5_ID, IDENTIFIER_6_ID, IDENTIFIER_7.getId())) { assertTrue(response.stream().map(Identifier::getId).toList().contains(id)); } } @@ -92,9 +92,9 @@ public class IdentifierServicePersistenceTest extends BaseTest { public void findAll_databaseId_succeeds() { /* test */ - final List<Identifier> response = identifierService.findAll(null, DATABASE_1_ID, null, null, null); + final List<Identifier> response = identifierService.findAll(null, DATABASE_1.getId(), null, null, null); assertEquals(4, response.size()); - assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_1_ID)); + assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_1.getId())); assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_2_ID)); assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_3_ID)); assertTrue(response.stream().map(Identifier::getId).toList().contains(IDENTIFIER_4_ID)); @@ -112,7 +112,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { public void findAll_empty_succeeds() { /* test */ - final List<Identifier> response = identifierService.findAll(null, DATABASE_2_ID, QUERY_1_ID, null, null); + final List<Identifier> response = identifierService.findAll(null, DATABASE_2.getId(), QUERY_1_ID, null, null); assertEquals(0, response.size()); } @@ -121,7 +121,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { public void find_succeeds() throws IdentifierNotFoundException { /* test */ - final Identifier response = identifierService.find(IDENTIFIER_1_ID); + final Identifier response = identifierService.find(IDENTIFIER_1.getId()); assertEquals(IDENTIFIER_1, response); } @@ -129,10 +129,10 @@ public class IdentifierServicePersistenceTest extends BaseTest { public void findByDatabaseIdAndQueryId_succeeds() { /* test */ - final List<Identifier> response = identifierService.findByDatabaseIdAndQueryId(DATABASE_1_ID, QUERY_1_ID); + final List<Identifier> response = identifierService.findByDatabaseIdAndQueryId(DATABASE_1.getId(), QUERY_1_ID); assertEquals(2, response.size()); final Identifier identifier0 = response.get(0); - assertEquals(IDENTIFIER_1_ID, identifier0.getId()); + assertEquals(IDENTIFIER_1.getId(), identifier0.getId()); final Identifier identifier1 = response.get(1); assertEquals(IDENTIFIER_2_ID, identifier1.getId()); } @@ -157,7 +157,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { /* test */ - identifierService.save(DATABASE_1, USER_1, IDENTIFIER_1_SAVE_DTO); + identifierService.save(DATABASE_1, USER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1)); } @Test @@ -166,13 +166,13 @@ public class IdentifierServicePersistenceTest extends BaseTest { QueryNotFoundException, SearchServiceException, SearchServiceConnectionException, ExternalServiceException { /* mock */ - when(dataServiceGateway.findQuery(DATABASE_2_ID, QUERY_2_ID)) + when(dataServiceGateway.findQuery(DATABASE_2.getId(), QUERY_2_DTO.getId())) .thenReturn(QUERY_2_DTO); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_2_BRIEF_DTO); /* test */ - identifierService.save(DATABASE_2, USER_2, IDENTIFIER_5_SAVE_DTO); + identifierService.save(DATABASE_2, USER_2, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_5)); } @Test @@ -182,7 +182,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { ExternalServiceException { /* test */ - identifierService.save(DATABASE_1, USER_1, IDENTIFIER_1_SAVE_DTO); + identifierService.save(DATABASE_1, USER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1)); } @Test @@ -300,11 +300,11 @@ public class IdentifierServicePersistenceTest extends BaseTest { QueryNotFoundException, SearchServiceException, SearchServiceConnectionException, ExternalServiceException { /* mock */ - when(dataServiceGateway.findQuery(DATABASE_2_ID, QUERY_2_ID)) + when(dataServiceGateway.findQuery(DATABASE_2.getId(), QUERY_2_DTO.getId())) .thenReturn(QUERY_2_DTO); /* test */ - final Identifier response = identifierService.save(DATABASE_2, USER_2, IDENTIFIER_5_SAVE_DTO); + final Identifier response = identifierService.save(DATABASE_2, USER_2, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_5)); assertNotNull(response.getTitles()); assertEquals(1, response.getTitles().size()); final IdentifierTitle title0 = response.getTitles().get(0); @@ -315,11 +315,11 @@ public class IdentifierServicePersistenceTest extends BaseTest { assertEquals(1, response.getDescriptions().size()); final IdentifierDescription description0 = response.getDescriptions().get(0); assertEquals(IDENTIFIER_5_DESCRIPTION_1_DESCRIPTION, description0.getDescription()); - assertEquals(IDENTIFIER_5_DESCRIPTION_1_LANG, description0.getLanguage()); + assertEquals(IDENTIFIER_5_DESCRIPTION_1_LANG, metadataMapper.languageTypeDtoToLanguageType(description0.getLanguage())); assertEquals(IDENTIFIER_5_DESCRIPTION_1_TYPE, description0.getDescriptionType()); assertNull(response.getDoi()); assertEquals(IDENTIFIER_5_PUBLISHER, response.getPublisher()); - assertEquals(DATABASE_2_ID, response.getDatabase().getId()); + assertEquals(DATABASE_2.getId(), response.getDatabase().getId()); assertNull(response.getLanguage()); assertEquals(IDENTIFIER_5_PUBLICATION_YEAR, response.getPublicationYear()); assertEquals(IDENTIFIER_5_PUBLICATION_MONTH, response.getPublicationMonth()); @@ -339,12 +339,12 @@ public class IdentifierServicePersistenceTest extends BaseTest { SearchServiceException, SearchServiceConnectionException, ExternalServiceException { /* test */ - final Identifier response = identifierService.save(DATABASE_1, USER_1, IDENTIFIER_1_SAVE_DTO); + final Identifier response = identifierService.save(DATABASE_1, USER_1, metadataMapper.identifierToIdentifierSaveDto(IDENTIFIER_1)); assertNotNull(response.getTitles()); final List<IdentifierTitle> titles = response.getTitles(); assertEquals(2, titles.size()); final IdentifierTitle title0 = titles.get(0); - assertEquals(IDENTIFIER_1_TITLE_1_TITLE, title0.getTitle()); + assertEquals(IDENTIFIER_1.getTitles().get(0).getTitle(), title0.getTitle()); assertEquals(IDENTIFIER_1_TITLE_1_LANG, title0.getLanguage()); assertEquals(IDENTIFIER_1_TITLE_1_TYPE, title0.getTitleType()); final IdentifierTitle title1 = titles.get(1); @@ -356,8 +356,8 @@ public class IdentifierServicePersistenceTest extends BaseTest { final List<IdentifierDescription> descriptions = response.getDescriptions(); final IdentifierDescription description0 = descriptions.get(0); assertNotNull(description0.getId()); - assertEquals(IDENTIFIER_1_DESCRIPTION_1_DESCRIPTION, description0.getDescription()); - assertEquals(IDENTIFIER_1_DESCRIPTION_1_LANG, description0.getLanguage()); + assertEquals(IDENTIFIER_1.getDescriptions().get(0).getDescription(), description0.getDescription()); + assertEquals(IDENTIFIER_1_DESCRIPTION_1_LANG, metadataMapper.languageTypeDtoToLanguageType(description0.getLanguage())); assertEquals(IDENTIFIER_1_DESCRIPTION_1_TYPE, description0.getDescriptionType()); assertNotNull(response.getCreators()); assertEquals(1, response.getCreators().size()); @@ -390,7 +390,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { final List<IdentifierTitle> titles = response.getTitles(); assertEquals(1, titles.size()); final IdentifierTitle title0 = titles.get(0); - assertEquals(IDENTIFIER_1_TITLE_1_TITLE, title0.getTitle()); + assertEquals(IDENTIFIER_1.getTitles().get(0).getTitle(), title0.getTitle()); assertEquals(IDENTIFIER_1_TITLE_1_LANG, title0.getLanguage()); assertEquals(IDENTIFIER_1_TITLE_1_TYPE, title0.getTitleType()); assertNotNull(response.getDescriptions()); @@ -432,12 +432,12 @@ public class IdentifierServicePersistenceTest extends BaseTest { ExternalServiceException { /* mock */ - when(dataServiceGateway.findQuery(DATABASE_1_ID, QUERY_1_ID)) + when(dataServiceGateway.findQuery(DATABASE_1.getId(), QUERY_1_ID)) .thenReturn(QUERY_1_DTO); /* test */ final Identifier response = identifierService.save(DATABASE_1, USER_1, IDENTIFIER_2_SAVE_DTO); - assertEquals(DATABASE_1_ID, response.getDatabase().getId()); + assertEquals(DATABASE_1.getId(), response.getDatabase().getId()); assertEquals(IDENTIFIER_2_QUERY, response.getQuery()); assertEquals(IDENTIFIER_2_QUERY_HASH, response.getQueryHash()); assertEquals(IDENTIFIER_2_RESULT_HASH, response.getResultHash()); @@ -453,7 +453,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { /* test */ final Identifier response = identifierService.save(DATABASE_1, USER_1, IDENTIFIER_3_SAVE_DTO); - assertEquals(DATABASE_1_ID, response.getDatabase().getId()); + assertEquals(DATABASE_1.getId(), response.getDatabase().getId()); assertEquals(IDENTIFIER_3_QUERY, response.getQuery()); assertEquals(IDENTIFIER_3_QUERY_HASH, response.getQueryHash()); assertEquals(IDENTIFIER_3_RESULT_HASH, response.getResultHash()); @@ -468,7 +468,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { IdentifierNotFoundException, ViewNotFoundException, ExternalServiceException { /* test */ - final Identifier response = identifierService.create(DATABASE_1, USER_1, IDENTIFIER_1_CREATE_DTO); + final Identifier response = identifierService.create(DATABASE_1, USER_1, metadataMapper.identifierToCreateIdentifierDto(IDENTIFIER_1)); assertNotNull(response.getId()); } @@ -490,7 +490,7 @@ public class IdentifierServicePersistenceTest extends BaseTest { /* test */ final Identifier response = identifierService.publish(IDENTIFIER_7); - assertEquals(IDENTIFIER_7_ID, response.getId()); + assertEquals(IDENTIFIER_7.getId(), response.getId()); assertEquals(IdentifierStatusType.PUBLISHED, response.getStatus()); } } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServicePersistenceTest.java index da0e741028..5bb8ca618e 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServicePersistenceTest.java @@ -41,13 +41,13 @@ public class ImageServicePersistenceTest extends BaseTest { @Test public void create_succeeds() throws ImageAlreadyExistsException, ImageInvalidException { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) + .name(IMAGE_1.getName()) .version("11.1.4") // new tag - .registry(IMAGE_1_REGISTRY) - .jdbcMethod(IMAGE_1_JDBC) - .dialect(IMAGE_1_DIALECT) - .driverClass(IMAGE_1_DRIVER) - .defaultPort(IMAGE_1_PORT) + .registry(IMAGE_1.getRegistry()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) + .dialect(IMAGE_1.getDialect()) + .driverClass(IMAGE_1.getDriverClass()) + .defaultPort(IMAGE_1.getDefaultPort()) .isDefault(false) .build(); @@ -58,12 +58,12 @@ public class ImageServicePersistenceTest extends BaseTest { @Test public void create_duplicate_fails() { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) - .version(IMAGE_1_VERSION) - .defaultPort(IMAGE_1_PORT) - .driverClass(IMAGE_1_DRIVER) - .jdbcMethod(IMAGE_1_JDBC) - .dialect(IMAGE_1_DIALECT) + .name(IMAGE_1.getName()) + .version(IMAGE_1.getVersion()) + .defaultPort(IMAGE_1.getDefaultPort()) + .driverClass(IMAGE_1.getDriverClass()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) + .dialect(IMAGE_1.getDialect()) .isDefault(IMAGE_1_IS_DEFAULT) .build(); @@ -78,11 +78,11 @@ public class ImageServicePersistenceTest extends BaseTest { final ImageCreateDto request = ImageCreateDto.builder() .name("mariadb") .version("10.5") - .registry(IMAGE_1_REGISTRY) - .defaultPort(IMAGE_1_PORT) - .driverClass(IMAGE_1_DRIVER) - .jdbcMethod(IMAGE_1_JDBC) - .dialect(IMAGE_1_DIALECT) + .registry(IMAGE_1.getRegistry()) + .defaultPort(IMAGE_1.getDefaultPort()) + .driverClass(IMAGE_1.getDriverClass()) + .jdbcMethod(IMAGE_1.getJdbcMethod()) + .dialect(IMAGE_1.getDialect()) .isDefault(true) // <<<< .build(); @@ -97,8 +97,8 @@ public class ImageServicePersistenceTest extends BaseTest { /* test */ imageService.delete(IMAGE_1); - assertTrue(imageRepository.findById(IMAGE_1_ID).isEmpty()); - assertFalse(containerRepository.findById(CONTAINER_1_ID).isPresent()); /* container should NEVER be deletable in the metadata db */ + assertTrue(imageRepository.findById(CONTAINER_1.getId()).isEmpty()); + assertFalse(containerRepository.findById(CONTAINER_1.getId()).isPresent()); /* container should NEVER be deletable in the metadata db */ } @Test @@ -106,7 +106,7 @@ public class ImageServicePersistenceTest extends BaseTest { /* test */ imageService.delete(IMAGE_1); - assertTrue(imageRepository.findById(IMAGE_1_ID).isEmpty()); + assertTrue(imageRepository.findById(CONTAINER_1.getId()).isEmpty()); } } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServiceUnitTest.java index 289c5bc104..3534d8b982 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ImageServiceUnitTest.java @@ -44,46 +44,46 @@ public class ImageServiceUnitTest extends BaseTest { /* test */ final List<ContainerImage> response = imageService.getAll(); assertEquals(1, response.size()); - assertEquals(IMAGE_1_NAME, response.get(0).getName()); - assertEquals(IMAGE_1_VERSION, response.get(0).getVersion()); + assertEquals(IMAGE_1.getName(), response.get(0).getName()); + assertEquals(IMAGE_1.getVersion(), response.get(0).getVersion()); } @Test public void getById_succeeds() throws ImageNotFoundException { /* mock */ - when(imageRepository.findById(IMAGE_1_ID)) + when(imageRepository.findById(CONTAINER_1.getId())) .thenReturn(Optional.of(IMAGE_1)); /* test */ - final ContainerImage response = imageService.find(IMAGE_1_ID); - assertEquals(IMAGE_1_NAME, response.getName()); - assertEquals(IMAGE_1_VERSION, response.getVersion()); + final ContainerImage response = imageService.find(CONTAINER_1.getId()); + assertEquals(IMAGE_1.getName(), response.getName()); + assertEquals(IMAGE_1.getVersion(), response.getVersion()); } @Test public void getById_notFound_fails() { /* mock */ - when(imageRepository.findById(IMAGE_1_ID)) + when(imageRepository.findById(CONTAINER_1.getId())) .thenReturn(Optional.empty()); /* test */ assertThrows(ImageNotFoundException.class, () -> { - imageService.find(IMAGE_1_ID); + imageService.find(CONTAINER_1.getId()); }); } @Test public void create_duplicate_fails() { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) - .version(IMAGE_1_VERSION) - .defaultPort(IMAGE_1_PORT) + .name(IMAGE_1.getName()) + .version(IMAGE_1.getVersion()) + .defaultPort(IMAGE_1.getDefaultPort()) .build(); /* mock */ - when(imageRepository.findByNameAndVersion(IMAGE_1_NAME, IMAGE_1_VERSION)) + when(imageRepository.findByNameAndVersion(IMAGE_1.getName(), IMAGE_1.getVersion())) .thenReturn(Optional.of(IMAGE_1)); /* test */ @@ -95,14 +95,14 @@ public class ImageServiceUnitTest extends BaseTest { @Test public void create_multipleDefaults_fails() { final ImageCreateDto request = ImageCreateDto.builder() - .name(IMAGE_1_NAME) + .name(IMAGE_1.getName()) .version("10.5") - .defaultPort(IMAGE_1_PORT) + .defaultPort(IMAGE_1.getDefaultPort()) .isDefault(true) .build(); /* mock */ - when(imageRepository.findByNameAndVersion(IMAGE_1_NAME, IMAGE_1_VERSION)) + when(imageRepository.findByNameAndVersion(IMAGE_1.getName(), IMAGE_1.getVersion())) .thenReturn(Optional.empty()); when(imageRepository.findByIsDefault(true)) .thenReturn(Optional.of(IMAGE_1)); @@ -117,11 +117,11 @@ public class ImageServiceUnitTest extends BaseTest { public void update_succeeds() { final ImageServiceImpl mockImageService = mock(ImageServiceImpl.class); final ImageChangeDto request = ImageChangeDto.builder() - .defaultPort(IMAGE_1_PORT) + .defaultPort(IMAGE_1.getDefaultPort()) .build(); /* mock */ - when(imageRepository.findById(IMAGE_1_ID)) + when(imageRepository.findById(CONTAINER_1.getId())) .thenReturn(Optional.of(IMAGE_1)); when(imageRepository.save(any())) .thenReturn(IMAGE_1); @@ -130,8 +130,8 @@ public class ImageServiceUnitTest extends BaseTest { /* test */ final ContainerImage response = mockImageService.update(IMAGE_1, request); - assertEquals(IMAGE_1_NAME, response.getName()); - assertEquals(IMAGE_1_VERSION, response.getVersion()); + assertEquals(IMAGE_1.getName(), response.getName()); + assertEquals(IMAGE_1.getVersion(), response.getVersion()); } @Test @@ -142,7 +142,7 @@ public class ImageServiceUnitTest extends BaseTest { .build(); /* mock */ - when(imageRepository.findById(IMAGE_1_ID)) + when(imageRepository.findById(CONTAINER_1.getId())) .thenReturn(Optional.of(IMAGE_1)); when(imageRepository.save(any())) .thenReturn(IMAGE_1); @@ -151,8 +151,8 @@ public class ImageServiceUnitTest extends BaseTest { /* test */ final ContainerImage response = mockImageService.update(IMAGE_1, request); - assertEquals(IMAGE_1_NAME, response.getName()); - assertEquals(IMAGE_1_VERSION, response.getVersion()); + assertEquals(IMAGE_1.getName(), response.getName()); + assertEquals(IMAGE_1.getVersion(), response.getVersion()); } @Test diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/MetadataServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/MetadataServiceUnitTest.java index a00b44e392..f9c3acf1c3 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/MetadataServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/MetadataServiceUnitTest.java @@ -108,11 +108,11 @@ public class MetadataServiceUnitTest extends BaseTest { @Transactional public void getRecord_succeeds() throws IdentifierNotFoundException { final OaiRecordParameters parameters = OaiRecordParameters.builder() - .identifier("oai:" + IDENTIFIER_1_ID) + .identifier("oai:" + IDENTIFIER_1.getId()) .build(); /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) + when(identifierService.find(IDENTIFIER_1.getId())) .thenReturn(IDENTIFIER_1); /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServicePersistenceTest.java index 503a4be8d3..4a96897ab2 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServicePersistenceTest.java @@ -105,11 +105,11 @@ public class TableServicePersistenceTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); doNothing() .when(dataServiceGateway) - .createTable(DATABASE_1_ID, request); + .createTable(DATABASE_1.getId(), request); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_1_BRIEF_DTO); @@ -165,7 +165,7 @@ public class TableServicePersistenceTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + .updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_3_BRIEF_DTO); @@ -183,7 +183,7 @@ public class TableServicePersistenceTest extends BaseTest { /* mock */ doThrow(DataServiceConnectionException.class) .when(dataServiceGateway) - .updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + .updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); /* test */ assertThrows(DataServiceConnectionException.class, () -> { @@ -198,7 +198,7 @@ public class TableServicePersistenceTest extends BaseTest { /* mock */ doThrow(DataServiceException.class) .when(dataServiceGateway) - .updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + .updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); /* test */ assertThrows(DataServiceException.class, () -> { @@ -213,7 +213,7 @@ public class TableServicePersistenceTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + .updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); doThrow(SearchServiceConnectionException.class) .when(searchServiceGateway) .update(any(Database.class)); @@ -231,7 +231,7 @@ public class TableServicePersistenceTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .updateTable(DATABASE_3_ID, TABLE_8_ID, TABLE_8_UPDATE_DTO); + .updateTable(DATABASE_3.getId(), TABLE_8_ID, TABLE_8_UPDATE_DTO); doThrow(SearchServiceException.class) .when(searchServiceGateway) .update(any(Database.class)); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServiceUnitTest.java index 56df16cf8c..eee0e778dc 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/TableServiceUnitTest.java @@ -71,7 +71,7 @@ public class TableServiceUnitTest extends BaseTest { public void findById_succeeds() throws TableNotFoundException, DatabaseNotFoundException { /* mock */ - when(databaseRepository.findById(DATABASE_3_ID)) + when(databaseRepository.findById(DATABASE_3.getId())) .thenReturn(Optional.of(DATABASE_3)); /* test */ @@ -85,7 +85,7 @@ public class TableServiceUnitTest extends BaseTest { public void findById_notFound_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_3_ID)) + when(databaseRepository.findById(DATABASE_3.getId())) .thenReturn(Optional.of(DATABASE_3)); /* test */ @@ -98,7 +98,7 @@ public class TableServiceUnitTest extends BaseTest { public void findByName_succeeds() throws TableNotFoundException, DatabaseNotFoundException { /* mock */ - when(databaseRepository.findById(DATABASE_3_ID)) + when(databaseRepository.findById(DATABASE_3.getId())) .thenReturn(Optional.of(DATABASE_3)); /* test */ @@ -112,7 +112,7 @@ public class TableServiceUnitTest extends BaseTest { public void findByName_notFound_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_3_ID)) + when(databaseRepository.findById(DATABASE_3.getId())) .thenReturn(Optional.empty()); /* test */ @@ -127,7 +127,7 @@ public class TableServiceUnitTest extends BaseTest { SearchServiceConnectionException, MalformedException { /* mock */ - when(dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID)) + when(dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID)) .thenReturn(TABLE_8_STATISTIC_DTO); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -144,7 +144,7 @@ public class TableServiceUnitTest extends BaseTest { SearchServiceConnectionException { /* mock */ - when(dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID)) + when(dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID)) .thenReturn(TABLE_8_STATISTIC_DTO); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -164,7 +164,7 @@ public class TableServiceUnitTest extends BaseTest { SearchServiceConnectionException { /* mock */ - when(dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID)) + when(dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID)) .thenReturn(TABLE_8_STATISTIC_DTO); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -193,7 +193,7 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(dataServiceGateway.getTableStatistics(DATABASE_3_ID, TABLE_8_ID)) + when(dataServiceGateway.getTableStatistics(DATABASE_3.getId(), TABLE_8_ID)) .thenReturn(mock); /* test */ @@ -267,11 +267,11 @@ public class TableServiceUnitTest extends BaseTest { SemanticEntityNotFoundException { /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); doNothing() .when(dataServiceGateway) - .createTable(eq(DATABASE_1_ID), any(CreateTableDto.class)); + .createTable(eq(DATABASE_1.getId()), any(CreateTableDto.class)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); when(searchServiceGateway.update(any(Database.class))) @@ -304,11 +304,11 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); doNothing() .when(dataServiceGateway) - .createTable(eq(DATABASE_1_ID), any(CreateTableDto.class)); + .createTable(eq(DATABASE_1.getId()), any(CreateTableDto.class)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); when(searchServiceGateway.update(any(Database.class))) @@ -363,11 +363,11 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); doNothing() .when(dataServiceGateway) - .createTable(eq(DATABASE_1_ID), any(CreateTableDto.class)); + .createTable(eq(DATABASE_1.getId()), any(CreateTableDto.class)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); when(searchServiceGateway.update(any(Database.class))) @@ -405,11 +405,11 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); doNothing() .when(dataServiceGateway) - .createTable(eq(DATABASE_1_ID), any(CreateTableDto.class)); + .createTable(eq(DATABASE_1.getId()), any(CreateTableDto.class)); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); when(searchServiceGateway.update(any(Database.class))) @@ -445,13 +445,13 @@ public class TableServiceUnitTest extends BaseTest { SemanticEntityNotFoundException { /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); doNothing() .when(dataServiceGateway) - .createTable(DATABASE_1_ID, TABLE_3_CREATE_DTO); + .createTable(DATABASE_1.getId(), TABLE_3_CREATE_DTO); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_1_BRIEF_DTO); @@ -466,13 +466,13 @@ public class TableServiceUnitTest extends BaseTest { SearchServiceConnectionException { /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); doThrow(DataServiceException.class) .when(dataServiceGateway) - .createTable(DATABASE_1_ID, TABLE_5_CREATE_DTO); + .createTable(DATABASE_1.getId(), TABLE_5_CREATE_DTO); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_1_BRIEF_DTO); @@ -497,7 +497,7 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); /* test */ @@ -521,7 +521,7 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -552,7 +552,7 @@ public class TableServiceUnitTest extends BaseTest { .build(); /* mock */ - when(userService.findByUsername(USER_1_USERNAME)) + when(userService.findByUsername("junit1")) .thenReturn(USER_1); /* test */ @@ -570,7 +570,7 @@ public class TableServiceUnitTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteTable(DATABASE_1_ID, TABLE_1_ID); + .deleteTable(DATABASE_1.getId(), TABLE_1_ID); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_1_BRIEF_DTO); @@ -586,7 +586,7 @@ public class TableServiceUnitTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteTable(DATABASE_1_ID, TABLE_4_ID); + .deleteTable(DATABASE_1.getId(), TABLE_4_ID); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_1_BRIEF_DTO); @@ -598,7 +598,7 @@ public class TableServiceUnitTest extends BaseTest { public void findById_tableNotFound_fails() { /* mock */ - when(databaseRepository.findById(DATABASE_1_ID)) + when(databaseRepository.findById(DATABASE_1.getId())) .thenReturn(Optional.of(DATABASE_2)) /* any other db */; /* test */ diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceIntegrationTest.java index 9311d0dd34..64e62d5e92 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceIntegrationTest.java @@ -42,7 +42,7 @@ public class UserServiceIntegrationTest extends BaseTest { public void beforeEach() { /* keycloak */ userRepository.deleteAll(); - keycloakUtils.deleteUser(USER_1_USERNAME); + keycloakUtils.deleteUser("junit1"); } @Container @@ -65,9 +65,9 @@ public class UserServiceIntegrationTest extends BaseTest { /* test */ final User response = userService.create(USER_1_CREATE_USER_DTO); - assertEquals(USER_1_ID, response.getId()); + assertEquals(USER_1.getId(), response.getId()); assertEquals(USER_1_KEYCLOAK_ID, response.getKeycloakId()); - assertEquals(USER_1_USERNAME, response.getUsername()); + assertEquals("junit1", response.getUsername()); assertEquals(USER_1_THEME, response.getTheme()); assertNotNull(response.getMariadbPassword()); assertEquals(USER_1_LANGUAGE, response.getLanguage()); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServicePersistenceTest.java index cb4e873ac9..7108552e5e 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServicePersistenceTest.java @@ -47,9 +47,9 @@ public class UserServicePersistenceTest extends BaseTest { public void findByUsername_succeeds() throws UserNotFoundException { /* test */ - final User response = userService.findByUsername(USER_1_USERNAME); - assertEquals(USER_1_ID, response.getId()); - assertEquals(USER_1_USERNAME, response.getUsername()); + final User response = userService.findByUsername("junit1"); + assertEquals(USER_1.getId(), response.getId()); + assertEquals("junit1", response.getUsername()); } @Test @@ -93,11 +93,11 @@ public class UserServicePersistenceTest extends BaseTest { /* mock */ doNothing() .when(keycloakGateway) - .updateUser(USER_1_ID, request); + .updateUser(USER_1.getId(), request); /* test */ final User response = userService.modify(USER_1, request); - assertEquals(USER_1_ID, response.getId()); + assertEquals(USER_1.getId(), response.getId()); assertEquals(USER_1_FIRSTNAME, response.getFirstname()); assertEquals(USER_1_LASTNAME, response.getLastname()); assertEquals("dark", response.getTheme()); @@ -110,8 +110,8 @@ public class UserServicePersistenceTest extends BaseTest { public void find_succeeds() throws UserNotFoundException { /* test */ - final User user = userService.findById(USER_1_ID); - assertEquals(USER_1_USERNAME, user.getUsername()); + final User user = userService.findById(USER_1.getId()); + assertEquals("junit1", user.getUsername()); } @Test @@ -119,7 +119,7 @@ public class UserServicePersistenceTest extends BaseTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - userService.findById(USER_2_ID); + userService.findById(USER_2.getId()); }); } } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceUnitTest.java index 8a6a29400b..c413c1e2d9 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/UserServiceUnitTest.java @@ -39,26 +39,26 @@ public class UserServiceUnitTest extends BaseTest { public void findByUsername_succeeds() throws UserNotFoundException { /* mock */ - when(userRepository.findByUsername(USER_1_USERNAME)) + when(userRepository.findByUsername("junit1")) .thenReturn(Optional.of(USER_1)); /* test */ - final User response = userService.findByUsername(USER_1_USERNAME); - assertEquals(USER_1_ID, response.getId()); - assertEquals(USER_1_USERNAME, response.getUsername()); + final User response = userService.findByUsername("junit1"); + assertEquals(USER_1.getId(), response.getId()); + assertEquals("junit1", response.getUsername()); } @Test public void find_succeeds() throws UserNotFoundException { /* mock */ - when(userRepository.findById(USER_1_ID)) + when(userRepository.findById(USER_1.getId())) .thenReturn(Optional.of(USER_1)); /* test */ - final User response = userService.findById(USER_1_ID); - assertEquals(USER_1_ID, response.getId()); - assertEquals(USER_1_USERNAME, response.getUsername()); + final User response = userService.findById(USER_1.getId()); + assertEquals(USER_1.getId(), response.getId()); + assertEquals("junit1", response.getUsername()); } @Test @@ -77,7 +77,7 @@ public class UserServiceUnitTest extends BaseTest { public void modify_succeeds() throws UserNotFoundException, AuthServiceException { /* mock */ - when(userRepository.findById(USER_1_ID)) + when(userRepository.findById(USER_1.getId())) .thenReturn(Optional.of(USER_1)); when(userRepository.save(any(User.class))) .thenReturn(USER_1); @@ -87,8 +87,8 @@ public class UserServiceUnitTest extends BaseTest { /* test */ final User response = userService.modify(USER_1, USER_1_UPDATE_DTO); - assertEquals(USER_1_ID, response.getId()); - assertEquals(USER_1_USERNAME, response.getUsername()); + assertEquals(USER_1.getId(), response.getId()); + assertEquals("junit1", response.getUsername()); } @Test @@ -96,7 +96,7 @@ public class UserServiceUnitTest extends BaseTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - userService.findByUsername(USER_1_USERNAME); + userService.findByUsername("junit1"); }); } @@ -105,7 +105,7 @@ public class UserServiceUnitTest extends BaseTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - userService.findById(USER_1_ID); + userService.findById(USER_1.getId()); }); } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServicePersistenceTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServicePersistenceTest.java index 33cc7db8a4..493d6f7059 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServicePersistenceTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServicePersistenceTest.java @@ -85,7 +85,7 @@ public class ViewServicePersistenceTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); when(searchServiceGateway.update(any(Database.class))) .thenReturn(DATABASE_1_BRIEF_DTO); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServiceUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServiceUnitTest.java index a50b7ca339..880eff9db1 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServiceUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/service/ViewServiceUnitTest.java @@ -53,7 +53,7 @@ public class ViewServiceUnitTest extends BaseTest { .build(); /* mock */ - when(dataServiceGateway.createView(DATABASE_1_ID, request)) + when(dataServiceGateway.createView(DATABASE_1.getId(), request)) .thenReturn(VIEW_1_DTO); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); @@ -95,7 +95,7 @@ public class ViewServiceUnitTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); when(searchServiceGateway.update(any(Database.class))) @@ -112,7 +112,7 @@ public class ViewServiceUnitTest extends BaseTest { /* mock */ doThrow(DataServiceException.class) .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); /* test */ assertThrows(DataServiceException.class, () -> { @@ -127,7 +127,7 @@ public class ViewServiceUnitTest extends BaseTest { /* mock */ doThrow(DataServiceConnectionException.class) .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); /* test */ assertThrows(DataServiceConnectionException.class, () -> { @@ -142,7 +142,7 @@ public class ViewServiceUnitTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); doThrow(SearchServiceException.class) @@ -162,7 +162,7 @@ public class ViewServiceUnitTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); doThrow(SearchServiceConnectionException.class) @@ -182,7 +182,7 @@ public class ViewServiceUnitTest extends BaseTest { /* mock */ doNothing() .when(dataServiceGateway) - .deleteView(DATABASE_1_ID, VIEW_1_ID); + .deleteView(DATABASE_1.getId(), VIEW_1_ID); when(databaseRepository.save(any(Database.class))) .thenReturn(DATABASE_1); doThrow(DatabaseNotFoundException.class) diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/utils/AmqpUtils.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/utils/AmqpUtils.java index 09017252d8..bdd475f09d 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/utils/AmqpUtils.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/utils/AmqpUtils.java @@ -26,7 +26,7 @@ import java.util.stream.Collectors; @Log4j2 public class AmqpUtils extends BaseTest { - private static final String BASIC_AUTH = new String(Base64.encodeBase64((USER_1_USERNAME + ":" + USER_1_PASSWORD).getBytes(Charset.defaultCharset()))); + private static final String BASIC_AUTH = new String(Base64.encodeBase64(("junit1" + ":" + USER_1_PASSWORD).getBytes(Charset.defaultCharset()))); private final RestTemplate restTemplate; @@ -34,7 +34,7 @@ public class AmqpUtils extends BaseTest { final RestTemplate restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(endpoint)); restTemplate.getInterceptors() - .add(new BasicAuthenticationInterceptor(USER_1_USERNAME, USER_1_PASSWORD)); + .add(new BasicAuthenticationInterceptor("junit1", USER_1_PASSWORD)); this.restTemplate = restTemplate; } diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/validator/EndpointValidatorUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/validator/EndpointValidatorUnitTest.java index 324fa81206..654d3aa0f5 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/validator/EndpointValidatorUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/ac/tuwien/ifs/dbrepo/validator/EndpointValidatorUnitTest.java @@ -207,10 +207,10 @@ public class EndpointValidatorUnitTest extends BaseTest { DatabaseNotFoundException, AccessNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(accessService.find(eq(DATABASE_1), any(User.class))) - .thenReturn(DATABASE_1_USER_1_READ_ACCESS); + .thenReturn(DATABASE_1.getAccesses().get(0)); /* test */ endpointValidator.validateOnlyAccessOrPublic(DATABASE_1, USER_1_PRINCIPAL); @@ -221,7 +221,7 @@ public class EndpointValidatorUnitTest extends BaseTest { DatabaseNotFoundException, AccessNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(accessService.find(eq(DATABASE_1), any(User.class))) .thenReturn(DATABASE_1_USER_1_WRITE_OWN_ACCESS); @@ -235,7 +235,7 @@ public class EndpointValidatorUnitTest extends BaseTest { DatabaseNotFoundException, AccessNotFoundException { /* mock */ - when(databaseService.findById(DATABASE_1_ID)) + when(databaseService.findById(DATABASE_1.getId())) .thenReturn(DATABASE_1); when(accessService.find(eq(DATABASE_1), any(User.class))) .thenReturn(DATABASE_1_USER_1_WRITE_ALL_ACCESS); @@ -280,7 +280,7 @@ public class EndpointValidatorUnitTest extends BaseTest { when(tableService.findById(DATABASE_1, TABLE_1_ID)) .thenReturn(TABLE_1); when(accessService.find(eq(DATABASE_1), any(User.class))) - .thenReturn(DATABASE_1_USER_1_READ_ACCESS); + .thenReturn(DATABASE_1.getAccesses().get(0)); /* test */ assertThrows(NotAllowedException.class, () -> { @@ -368,7 +368,7 @@ public class EndpointValidatorUnitTest extends BaseTest { when(tableService.findById(DATABASE_1, TABLE_1_ID)) .thenReturn(TABLE_1); when(accessService.find(DATABASE_1, USER_1)) - .thenReturn(DATABASE_1_USER_1_READ_ACCESS); + .thenReturn(DATABASE_1.getAccesses().get(0)); /* test */ assertThrows(NotAllowedException.class, () -> { @@ -604,7 +604,7 @@ public class EndpointValidatorUnitTest extends BaseTest { public void validateOnlyMineOrWriteAccessOrHasRole_readAccess_fails() { /* test */ - assertFalse(endpointValidator.validateOnlyMineOrWriteAccessOrHasRole(USER_1, USER_1_PRINCIPAL, DATABASE_1_USER_1_READ_ACCESS, "nobody-role")); + assertFalse(endpointValidator.validateOnlyMineOrWriteAccessOrHasRole(USER_1, USER_1_PRINCIPAL, DATABASE_1.getAccesses().get(0), "nobody-role")); } @Test diff --git a/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/mapper/MetadataMapper.java b/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/mapper/MetadataMapper.java index 249a9842f2..3db28cc7d6 100644 --- a/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/mapper/MetadataMapper.java +++ b/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/mapper/MetadataMapper.java @@ -459,12 +459,18 @@ public interface MetadataMapper { .build(); } - Identifier identifierCreateDtoToIdentifier(CreateIdentifierDto data); + Identifier createIdentifierDtoToIdentifier(CreateIdentifierDto data); - Identifier identifierUpdateDtoToIdentifier(IdentifierSaveDto data); + Identifier identifierSaveDtoToIdentifier(IdentifierSaveDto data); + + IdentifierSaveDto identifierToIdentifierSaveDto(Identifier data); + + CreateIdentifierDto identifierToCreateIdentifierDto(Identifier data); License licenseDtoToLicense(LicenseDto data); + ImageCreateDto containerImageToImageCreateDto(ContainerImage data); + IdentifierTitle identifierCreateTitleDtoToIdentifierTitle(SaveIdentifierTitleDto data); IdentifierDescription identifierCreateDescriptionDtoToIdentifierDescription(SaveIdentifierDescriptionDto data); diff --git a/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/test/BaseTest.java b/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/test/BaseTest.java index 2a1a13252f..2e7b7c877d 100644 --- a/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/test/BaseTest.java +++ b/lib/java/dbrepo-core/src/main/java/at/ac/tuwien/ifs/dbrepo/core/test/BaseTest.java @@ -169,12 +169,19 @@ public class BaseTest { public static final String KEYCLOAK_IMAGE = "quay.io/keycloak/keycloak:26.0.4"; + public static final ContainerImage IMAGE_1; public static final Container CONTAINER_1; public static final ContainerDto CONTAINER_1_DTO; public static final ContainerBriefDto CONTAINER_1_BRIEF_DTO; public static final Container CONTAINER_2; public static final ContainerDto CONTAINER_2_DTO; public static final ContainerBriefDto CONTAINER_2_BRIEF_DTO; + public static final Container CONTAINER_3; + public static final ContainerDto CONTAINER_3_DTO; + public static final ContainerBriefDto CONTAINER_3_BRIEF_DTO; + public static final Container CONTAINER_4; + public static final ContainerDto CONTAINER_4_DTO; + public static final ContainerBriefDto CONTAINER_4_BRIEF_DTO; public static final Database DATABASE_1; public static final DatabaseDto DATABASE_1_DTO; public static final DatabaseBriefDto DATABASE_1_BRIEF_DTO; @@ -274,12 +281,19 @@ public class BaseTest { static { try { + IMAGE_1 = objectMapper().readValue(new File(resourcesPath + "/image-1.json"), ContainerImage.class); CONTAINER_1 = objectMapper().readValue(new File(resourcesPath + "/container-1.json"), Container.class); CONTAINER_1_DTO = metadataMapper.containerToContainerDto(CONTAINER_1); CONTAINER_1_BRIEF_DTO = metadataMapper.containerToContainerBriefDto(CONTAINER_1); - CONTAINER_2 = objectMapper().readValue(new File(resourcesPath + "/container-1.json"), Container.class); + CONTAINER_2 = objectMapper().readValue(new File(resourcesPath + "/container-2.json"), Container.class); CONTAINER_2_DTO = metadataMapper.containerToContainerDto(CONTAINER_2); CONTAINER_2_BRIEF_DTO = metadataMapper.containerToContainerBriefDto(CONTAINER_2); + CONTAINER_3 = objectMapper().readValue(new File(resourcesPath + "/container-3.json"), Container.class); + CONTAINER_3_DTO = metadataMapper.containerToContainerDto(CONTAINER_3); + CONTAINER_3_BRIEF_DTO = metadataMapper.containerToContainerBriefDto(CONTAINER_3); + CONTAINER_4 = objectMapper().readValue(new File(resourcesPath + "/container-4.json"), Container.class); + CONTAINER_4_DTO = metadataMapper.containerToContainerDto(CONTAINER_4); + CONTAINER_4_BRIEF_DTO = metadataMapper.containerToContainerBriefDto(CONTAINER_4); DATABASE_1 = objectMapper().readValue(new File(resourcesPath + "/database-1.json"), Database.class); DATABASE_1_DTO = metadataMapper.databaseToDatabaseDto(DATABASE_1); DATABASE_1_BRIEF_DTO = metadataMapper.databaseToDatabaseBriefDto(DATABASE_1); @@ -697,7 +711,7 @@ public class BaseTest { .columns(new LinkedList<>(List.of(TABLE_9.getColumns().get(2).getId(), TABLE_9.getColumns().get(3).getId()))) .filter(new LinkedList<>(List.of(FilterDto.builder() .columnId(TABLE_9.getColumns().get(1).getId()) - .operatorId(IMAGE_1 IMAGE_1_OPERATORS_2_ID) + .operatorId(IMAGE_1.getOperators().get(2).getId()) .value("Fuji") .type(FilterTypeDto.WHERE) .build()))) @@ -737,41 +751,41 @@ public class BaseTest { @SuppressWarnings("java:S3599") public static final List<Map<String, Object>> TABLE_8_DATA_DTO = new LinkedList<>(List.of( new HashMap<>() {{ - put(COLUMN_8_1_INTERNAL_NAME, BigInteger.valueOf(1L)); - put(COLUMN_8_2_INTERNAL_NAME, 11.2); - put(COLUMN_8_3_INTERNAL_NAME, null); + put(TABLE_8.getColumns().get(0).getInternalName(), BigInteger.valueOf(1L)); + put(TABLE_8.getColumns().get(1).getInternalName(), 11.2); + put(TABLE_8.getColumns().get(2).getInternalName(), null); }}, new HashMap<>() {{ - put(COLUMN_8_1_INTERNAL_NAME, BigInteger.valueOf(2L)); - put(COLUMN_8_2_INTERNAL_NAME, 11.3); - put(COLUMN_8_3_INTERNAL_NAME, null); + put(TABLE_8.getColumns().get(0).getInternalName(), BigInteger.valueOf(2L)); + put(TABLE_8.getColumns().get(1).getInternalName(), 11.3); + put(TABLE_8.getColumns().get(2).getInternalName(), null); }}, new HashMap<>() {{ - put(COLUMN_8_1_INTERNAL_NAME, BigInteger.valueOf(3L)); - put(COLUMN_8_2_INTERNAL_NAME, 11.4); - put(COLUMN_8_3_INTERNAL_NAME, null); + put(TABLE_8.getColumns().get(0).getInternalName(), BigInteger.valueOf(3L)); + put(TABLE_8.getColumns().get(1).getInternalName(), 11.4); + put(TABLE_8.getColumns().get(2).getInternalName(), null); }}, new HashMap<>() {{ - put(COLUMN_8_1_INTERNAL_NAME, BigInteger.valueOf(4L)); - put(COLUMN_8_2_INTERNAL_NAME, 11.9); - put(COLUMN_8_3_INTERNAL_NAME, null); + put(TABLE_8.getColumns().get(0).getInternalName(), BigInteger.valueOf(4L)); + put(TABLE_8.getColumns().get(1).getInternalName(), 11.9); + put(TABLE_8.getColumns().get(2).getInternalName(), null); }}, new HashMap<>() {{ - put(COLUMN_8_1_INTERNAL_NAME, BigInteger.valueOf(5L)); - put(COLUMN_8_2_INTERNAL_NAME, 12.3); - put(COLUMN_8_3_INTERNAL_NAME, null); + put(TABLE_8.getColumns().get(0).getInternalName(), BigInteger.valueOf(5L)); + put(TABLE_8.getColumns().get(1).getInternalName(), 12.3); + put(TABLE_8.getColumns().get(2).getInternalName(), null); }}, new HashMap<>() {{ - put(COLUMN_8_1_INTERNAL_NAME, BigInteger.valueOf(6L)); - put(COLUMN_8_2_INTERNAL_NAME, 23.1); - put(COLUMN_8_3_INTERNAL_NAME, null); + put(TABLE_8.getColumns().get(0).getInternalName(), BigInteger.valueOf(6L)); + put(TABLE_8.getColumns().get(1).getInternalName(), 23.1); + put(TABLE_8.getColumns().get(2).getInternalName(), null); }} )); @SuppressWarnings("java:S3599") public static final TableStatisticDto TABLE_8_STATISTIC_DTO = TableStatisticDto.builder() .columns(new LinkedList<>(List.of(ColumnStatisticDto.builder() - .name(COLUMN_8_1_INTERNAL_NAME) + .name(TABLE_8.getColumns().get(1).getInternalName()) .min(BigDecimal.valueOf(11.2)) .max(BigDecimal.valueOf(23.1)) .mean(BigDecimal.valueOf(13.5333)) @@ -865,7 +879,7 @@ public class BaseTest { .build(); public static final ExchangeUpdatePermissionsDto VIRTUAL_HOST_EXCHANGE_UPDATE_DTO = ExchangeUpdatePermissionsDto.builder() - .exchange(DATABASE_1_EXCHANGE) + .exchange(DATABASE_1.getExchangeName()) .read(".*") .write(".*") .build(); diff --git a/lib/java/dbrepo-core/src/main/resources/database-1-user-1-read-access.json b/lib/java/dbrepo-core/src/main/resources/database-1-user-1-read-access.json deleted file mode 100644 index bc6d208be2..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-1-user-1-read-access.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "user" : { - "id" : "cd5bab0d-7799-4069-85fb-c5d738572a0b", - "username" : "junit1", - "name" : "John Doe", - "orcid" : "https://orcid.org/0000-0003-4216-302X", - "qualified_name" : "John Doe — @junit1", - "given_name" : "John", - "family_name" : "Doe" - }, - "type" : "read" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-1-user-2-write-own-access.json b/lib/java/dbrepo-core/src/main/resources/database-1-user-2-write-own-access.json deleted file mode 100644 index 5c710b95f7..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-1-user-2-write-own-access.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "user" : { - "id" : "eeb9a51b-4cd8-4039-90bf-e24f17372f7c", - "username" : "junit2", - "name" : "Jane Doe", - "orcid" : "https://orcid.org/0000-0002-9272-6225", - "qualified_name" : "Jane Doe — @junit2", - "given_name" : "Jane", - "family_name" : "Doe" - }, - "type" : "write_own" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-1-user-3-write-all-access.json b/lib/java/dbrepo-core/src/main/resources/database-1-user-3-write-all-access.json deleted file mode 100644 index 3e614580b1..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-1-user-3-write-all-access.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "user" : { - "id" : "7b080e33-d8db-4276-9d53-47208e657006", - "username" : "junit3", - "name" : "System System", - "qualified_name" : "System System — @junit3", - "given_name" : "System", - "family_name" : "System" - }, - "type" : "write_all" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-1.json b/lib/java/dbrepo-core/src/main/resources/database-1.json index 668c73ae0e..1c3401916e 100644 --- a/lib/java/dbrepo-core/src/main/resources/database-1.json +++ b/lib/java/dbrepo-core/src/main/resources/database-1.json @@ -58,7 +58,39 @@ "subsets" : [ ], "tables" : [ ], "views" : [ ], - "accesses" : [ ], + "accesses" : [ { + "user" : { + "id" : "cd5bab0d-7799-4069-85fb-c5d738572a0b", + "username" : "junit1", + "name" : "John Doe", + "orcid" : "https://orcid.org/0000-0003-4216-302X", + "qualified_name" : "John Doe — @junit1", + "given_name" : "John", + "family_name" : "Doe" + }, + "type" : "read" + }, { + "user" : { + "id" : "eeb9a51b-4cd8-4039-90bf-e24f17372f7c", + "username" : "junit2", + "name" : "Jane Doe", + "orcid" : "https://orcid.org/0000-0002-9272-6225", + "qualified_name" : "Jane Doe — @junit2", + "given_name" : "Jane", + "family_name" : "Doe" + }, + "type" : "write_own" + }, { + "user" : { + "id" : "7b080e33-d8db-4276-9d53-47208e657006", + "username" : "junit3", + "name" : "System System", + "qualified_name" : "System System — @junit3", + "given_name" : "System", + "family_name" : "System" + }, + "type" : "write_all" + } ], "isPublic" : false, "isSchemaPublic" : false, "isDashboardEnabled" : false, diff --git a/lib/java/dbrepo-core/src/main/resources/database-2-user-2-write-all-access.json b/lib/java/dbrepo-core/src/main/resources/database-2-user-2-write-all-access.json deleted file mode 100644 index 9f81c28fb3..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-2-user-2-write-all-access.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "user" : { - "id" : "eeb9a51b-4cd8-4039-90bf-e24f17372f7c", - "username" : "junit2", - "name" : "Jane Doe", - "orcid" : "https://orcid.org/0000-0002-9272-6225", - "qualified_name" : "Jane Doe — @junit2", - "given_name" : "Jane", - "family_name" : "Doe" - }, - "type" : "write_all" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-2-user-3-read-access.json b/lib/java/dbrepo-core/src/main/resources/database-2-user-3-read-access.json deleted file mode 100644 index 0016a966c8..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-2-user-3-read-access.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "user" : { - "id" : "7b080e33-d8db-4276-9d53-47208e657006", - "username" : "junit3", - "name" : "System System", - "qualified_name" : "System System — @junit3", - "given_name" : "System", - "family_name" : "System" - }, - "type" : "read" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-2.json b/lib/java/dbrepo-core/src/main/resources/database-2.json index d6d5799dcc..ba44d1885d 100644 --- a/lib/java/dbrepo-core/src/main/resources/database-2.json +++ b/lib/java/dbrepo-core/src/main/resources/database-2.json @@ -57,7 +57,28 @@ "identifiers" : [ ], "tables" : [ ], "views" : [ ], - "accesses" : [ ], + "accesses" : [ { + "user" : { + "id" : "eeb9a51b-4cd8-4039-90bf-e24f17372f7c", + "username" : "junit2", + "name" : "Jane Doe", + "orcid" : "https://orcid.org/0000-0002-9272-6225", + "qualified_name" : "Jane Doe — @junit2", + "given_name" : "Jane", + "family_name" : "Doe" + }, + "type" : "write_all" + }, { + "user" : { + "id" : "7b080e33-d8db-4276-9d53-47208e657006", + "username" : "junit3", + "name" : "System System", + "qualified_name" : "System System — @junit3", + "given_name" : "System", + "family_name" : "System" + }, + "type" : "read" + } ], "isPublic" : false, "isSchemaPublic" : true, "isDashboardEnabled" : true, diff --git a/lib/java/dbrepo-core/src/main/resources/database-3-user-1-write-all-access.json b/lib/java/dbrepo-core/src/main/resources/database-3-user-1-write-all-access.json deleted file mode 100644 index faf76afc55..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-3-user-1-write-all-access.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "user" : { - "id" : "cd5bab0d-7799-4069-85fb-c5d738572a0b", - "username" : "junit1", - "name" : "John Doe", - "orcid" : "https://orcid.org/0000-0003-4216-302X", - "qualified_name" : "John Doe — @junit1", - "given_name" : "John", - "family_name" : "Doe" - }, - "type" : "write_all" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-3.json b/lib/java/dbrepo-core/src/main/resources/database-3.json index 8734403ca8..6c56d7d6b1 100644 --- a/lib/java/dbrepo-core/src/main/resources/database-3.json +++ b/lib/java/dbrepo-core/src/main/resources/database-3.json @@ -53,7 +53,18 @@ "identifiers" : [ ], "tables" : [ ], "views" : [ ], - "accesses" : [ ], + "accesses" : [ { + "user" : { + "id" : "cd5bab0d-7799-4069-85fb-c5d738572a0b", + "username" : "junit1", + "name" : "John Doe", + "orcid" : "https://orcid.org/0000-0003-4216-302X", + "qualified_name" : "John Doe — @junit1", + "given_name" : "John", + "family_name" : "Doe" + }, + "type" : "write_all" + } ], "isPublic" : true, "isSchemaPublic" : false, "isDashboardEnabled" : true, diff --git a/lib/java/dbrepo-core/src/main/resources/database-4-user-1-read-access.json b/lib/java/dbrepo-core/src/main/resources/database-4-user-1-read-access.json deleted file mode 100644 index 1be927f701..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-4-user-1-read-access.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type" : "read" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-4-user-2-write-own-access.json b/lib/java/dbrepo-core/src/main/resources/database-4-user-2-write-own-access.json deleted file mode 100644 index 059e1d6379..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-4-user-2-write-own-access.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type" : "write_own" -} \ No newline at end of file diff --git a/lib/java/dbrepo-core/src/main/resources/database-4-user-3-write-all-access.json b/lib/java/dbrepo-core/src/main/resources/database-4-user-3-write-all-access.json deleted file mode 100644 index 1659906509..0000000000 --- a/lib/java/dbrepo-core/src/main/resources/database-4-user-3-write-all-access.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type" : "write_all" -} \ No newline at end of file -- GitLab