From e75a933456e646ee0063ad3ffd7369f14434fdd5 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Fri, 1 Dec 2023 10:11:57 +0100 Subject: [PATCH] Added stuff --- .../endpoints/TableEndpointUnitTest.java | 39 ++++++++++++------- .../service/ImageServiceIntegrationTest.java | 2 +- .../main/java/at/tuwien/test/BaseTest.java | 8 ++++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/TableEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/TableEndpointUnitTest.java index 5ee6b057a2..681f4efebc 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/TableEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/TableEndpointUnitTest.java @@ -321,7 +321,12 @@ public class TableEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_1_USERNAME, authorities = "delete-table") - public void delete_publicHasRoleTableNotFound_fails() { + public void delete_publicHasRoleTableNotFound_fails() throws TableNotFoundException, DatabaseNotFoundException { + + /* mock */ + doThrow(TableNotFoundException.class) + .when(tableService) + .find(DATABASE_3_ID, TABLE_8_ID); /* test */ assertThrows(TableNotFoundException.class, () -> { @@ -331,17 +336,13 @@ public class TableEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_1_USERNAME, authorities = "delete-table") - public void delete_publiceHasRoleDatabaseNotFound_fails() { - - /* test */ - assertThrows(DatabaseNotFoundException.class, () -> { - generic_delete(DATABASE_3_ID, TABLE_8_ID, null, TABLE_8, USER_1_PRINCIPAL); - }); - } + public void delete_publicHasRole_succeeds() throws DatabaseNotFoundException, NotAllowedException, + TableNotFoundException, TableMalformedException, QueryMalformedException, ImageNotSupportedException, + ContainerNotFoundException, DataProcessingException { - @Test - @WithMockUser(username = USER_1_USERNAME, authorities = "delete-table") - public void delete_publicHasRole_succeeds() throws DatabaseNotFoundException, NotAllowedException, TableNotFoundException, TableMalformedException, QueryMalformedException, ImageNotSupportedException, ContainerNotFoundException, DataProcessingException { + /* mock */ + when(tableService.find(DATABASE_3_ID, TABLE_8_ID)) + .thenReturn(TABLE_8); /* test */ final ResponseEntity<?> response = generic_delete(DATABASE_3_ID, TABLE_8_ID, DATABASE_3, TABLE_8, USER_1_PRINCIPAL); @@ -515,7 +516,11 @@ public class TableEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_1_USERNAME, authorities = "delete-table") - public void delete_privateHasRoleTableNotFound_fails() { + public void delete_privateHasRoleTableNotFound_fails() throws TableNotFoundException, DatabaseNotFoundException { + + doThrow(TableNotFoundException.class) + .when(tableService) + .find(DATABASE_1_ID, TABLE_1_ID); /* test */ assertThrows(TableNotFoundException.class, () -> { @@ -525,7 +530,11 @@ public class TableEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_1_USERNAME, authorities = "delete-table") - public void delete_privateHasRoleDatabaseNotFound_fails() { + public void delete_privateHasRoleDatabaseNotFound_fails() throws TableNotFoundException, DatabaseNotFoundException { + + /* mock */ + when(tableService.find(DATABASE_1_ID, TABLE_1_ID)) + .thenReturn(TABLE_1); /* test */ assertThrows(DatabaseNotFoundException.class, () -> { @@ -539,6 +548,10 @@ public class TableEndpointUnitTest extends BaseUnitTest { TableNotFoundException, TableMalformedException, QueryMalformedException, ImageNotSupportedException, ContainerNotFoundException, DataProcessingException { + /* mock */ + when(tableService.find(DATABASE_1_ID, TABLE_1_ID)) + .thenReturn(TABLE_1); + /* test */ final ResponseEntity<?> response = generic_delete(DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_PRINCIPAL); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java index d8557922fd..d87c4aef51 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java @@ -49,7 +49,7 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { public void create_succeeds() throws ImageAlreadyExistsException { final ImageCreateDto request = ImageCreateDto.builder() .name(IMAGE_1_NAME) - .version("11.1.3") + .version("11.1.4") // new tag .jdbcMethod(IMAGE_1_JDBC) .dialect(IMAGE_1_DIALECT) .driverClass(IMAGE_1_DRIVER) diff --git a/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java b/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java index 022b670e22..769348786e 100644 --- a/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java +++ b/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java @@ -1651,6 +1651,7 @@ public abstract class BaseTest { .created(TABLE_1_CREATED) .createdBy(USER_1_ID) .ownedBy(USER_1_ID) + .owner(USER_1) .lastModified(TABLE_1_LAST_MODIFIED) .build(); @@ -1702,6 +1703,7 @@ public abstract class BaseTest { .constraints(null /* TABLE_2_CONSTRAINTS */) .createdBy(USER_2_ID) .ownedBy(USER_2_ID) + .owner(USER_2) .created(TABLE_2_CREATED) .lastModified(TABLE_2_LAST_MODIFIED) .build(); @@ -1754,6 +1756,7 @@ public abstract class BaseTest { .constraints(null /* TABLE_3_CONSTRAINTS */) .createdBy(USER_3_ID) .ownedBy(USER_3_ID) + .owner(USER_3) .created(TABLE_3_CREATED) .lastModified(TABLE_3_LAST_MODIFIED) .build(); @@ -1830,6 +1833,7 @@ public abstract class BaseTest { .constraints(null) /* TABLE_4_CONSTRAINTS */ .createdBy(USER_1_ID) .ownedBy(USER_1_ID) + .owner(USER_1) .build(); public final static Table TABLE_4_SIMPLE = Table.builder() @@ -1882,6 +1886,7 @@ public abstract class BaseTest { .constraints(null) /* TABLE_5_CONSTRAINTS */ .createdBy(USER_1_ID) .ownedBy(USER_1_ID) + .owner(USER_1) .created(TABLE_5_CREATED) .lastModified(TABLE_5_LAST_MODIFIED) .build(); @@ -1932,6 +1937,7 @@ public abstract class BaseTest { .constraints(null) /* TABLE_6_CONSTRAINTS */ .createdBy(USER_1_ID) .ownedBy(USER_1_ID) + .owner(USER_1) .created(TABLE_6_CREATED) .lastModified(TABLE_6_LAST_MODIFIED) .build(); @@ -1979,6 +1985,7 @@ public abstract class BaseTest { .columns(List.of() /* needs to be set in the junit tests */) .createdBy(USER_1_ID) .ownedBy(USER_1_ID) + .owner(USER_1) .created(TABLE_7_CREATED) .lastModified(TABLE_7_LAST_MODIFIED) .build(); @@ -2088,6 +2095,7 @@ public abstract class BaseTest { .columns(List.of() /* needs to be set in the junit tests */) .createdBy(USER_1_ID) .ownedBy(USER_1_ID) + .owner(USER_1) .created(TABLE_8_CREATED) .lastModified(TABLE_8_LAST_MODIFIED) .build(); -- GitLab