diff --git a/service/src/main/java/org/databiosphere/workspacedataservice/service/CollectionService.java b/service/src/main/java/org/databiosphere/workspacedataservice/service/CollectionService.java index 15d578c64..86dc70c32 100644 --- a/service/src/main/java/org/databiosphere/workspacedataservice/service/CollectionService.java +++ b/service/src/main/java/org/databiosphere/workspacedataservice/service/CollectionService.java @@ -1,7 +1,6 @@ package org.databiosphere.workspacedataservice.service; import static org.databiosphere.workspacedataservice.dao.SqlUtils.quote; -import static org.databiosphere.workspacedataservice.service.RecordUtils.validateVersion; import bio.terra.common.db.WriteTransaction; import java.util.List; @@ -34,11 +33,9 @@ import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.relational.core.conversion.DbActionExecutionException; -import org.springframework.http.HttpStatus; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; -import org.springframework.web.server.ResponseStatusException; @Service public class CollectionService { @@ -326,69 +323,6 @@ private void handleDbException(DbActionExecutionException dbActionExecutionExcep throw dbActionExecutionException; } - // ============================== v0.2 methods ============================== - - /** - * @deprecated Use {@link #list(WorkspaceId)} instead. - */ - @Deprecated(forRemoval = true, since = "v0.14.0") - public List listCollections(String version) { - validateVersion(version); - return collectionDao.listCollectionSchemas().stream().map(CollectionId::id).toList(); - } - - /** - * @deprecated Use {@link #save(WorkspaceId, CollectionRequestServerModel)} instead. - */ - @Deprecated(forRemoval = true, since = "v0.14.0") - public void createCollection(UUID collectionId, String version) { - if (tenancyProperties.getAllowVirtualCollections()) { - throw new CollectionException( - "createCollection not allowed when virtual collections are enabled"); - } - if (workspaceId == null) { - throw new CollectionException( - "createCollection requires a workspaceId to be configured or provided"); - } - createCollection(workspaceId, CollectionId.of(collectionId), version); - } - - /** - * @deprecated Use {@link #save(WorkspaceId, CollectionRequestServerModel)} instead. - */ - @Deprecated(forRemoval = true, since = "v0.14.0") - public void createCollection(WorkspaceId workspaceId, CollectionId collectionId, String version) { - validateVersion(version); - - if (collectionDao.collectionSchemaExists(collectionId)) { - throw new ResponseStatusException(HttpStatus.CONFLICT, "This collection already exists"); - } - - // TODO(AJ-1662): this needs to pass the workspaceId argument so the collection is created - // correctly - // create collection schema in Postgres - collectionDao.createSchema(collectionId); - - activityLogger.saveEventForCurrentUser( - user -> user.created().collection().withUuid(collectionId.id())); - } - - /** - * @deprecated Use {@link #delete(WorkspaceId, CollectionId)} instead. - */ - @Deprecated(forRemoval = true, since = "v0.14.0") - public void deleteCollection(UUID collectionUuid, String version) { - validateVersion(version); - validateCollection(collectionUuid); - CollectionId collectionId = CollectionId.of(collectionUuid); - - // delete collection schema in Postgres - collectionDao.dropSchema(collectionId); - - activityLogger.saveEventForCurrentUser( - user -> user.deleted().collection().withUuid(collectionUuid)); - } - // ============================== helpers ============================== public void validateCollection(UUID collectionId) { diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/TestUtils.java b/service/src/test/java/org/databiosphere/workspacedataservice/TestUtils.java index ef34c66b1..35343874c 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/TestUtils.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/TestUtils.java @@ -12,6 +12,7 @@ import java.util.UUID; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; +import org.databiosphere.workspacedataservice.generated.CollectionRequestServerModel; import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.service.CollectionService; import org.databiosphere.workspacedataservice.service.RelationUtils; @@ -210,4 +211,13 @@ public static UUID getCollectionId(ObjectMapper objectMapper, String responseBod return created.getId(); } + + public static CollectionServerModel createCollection( + CollectionService collectionService, WorkspaceId workspaceId) { + String name = RandomStringUtils.randomAlphabetic(16); + String description = "test-description"; + CollectionRequestServerModel collectionRequestServerModel = + new CollectionRequestServerModel(name, description); + return collectionService.save(workspaceId, collectionRequestServerModel); + } } diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/activitylog/ActivityEventBuilderTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/activitylog/ActivityEventBuilderTest.java index 67098f10d..9e8b4b312 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/activitylog/ActivityEventBuilderTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/activitylog/ActivityEventBuilderTest.java @@ -11,7 +11,10 @@ import org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi; import org.broadinstitute.dsde.workbench.client.sam.api.UsersApi; import org.broadinstitute.dsde.workbench.client.sam.model.UserStatusInfo; +import org.databiosphere.workspacedataservice.TestUtils; import org.databiosphere.workspacedataservice.common.TestBase; +import org.databiosphere.workspacedataservice.config.TwdsProperties; +import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.sam.BearerTokenFilter; import org.databiosphere.workspacedataservice.sam.SamClientFactory; import org.databiosphere.workspacedataservice.service.CollectionService; @@ -37,6 +40,7 @@ class ActivityEventBuilderTest extends TestBase { @Autowired CollectionService collectionService; + @Autowired TwdsProperties twdsProperties; @MockBean SamClientFactory mockSamClientFactory; @@ -57,8 +61,6 @@ void testTokenResolutionViaSam(CapturedOutput output) throws ApiException { when(mockUsersApi.getUserStatusInfo()).thenReturn(userStatusInfo); when(mockResourcesApi.resourcePermissionV2(any(), any(), any())).thenReturn(true); - UUID collectionId = UUID.randomUUID(); - // ensure we have a token in the current request; else we'll get "anonymous" for our user RequestAttributes currentAttributes = RequestContextHolder.currentRequestAttributes(); currentAttributes.setAttribute( @@ -66,7 +68,9 @@ void testTokenResolutionViaSam(CapturedOutput output) throws ApiException { RequestContextHolder.setRequestAttributes(currentAttributes); // create a collection; this will trigger logging - collectionService.createCollection(collectionId, "v0.2"); + CollectionServerModel collectionServerModel = + TestUtils.createCollection(collectionService, twdsProperties.workspaceId()); + UUID collectionId = collectionServerModel.getId(); // did we log the assertThat(output.getOut()) diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobDataPlaneE2ETest.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobDataPlaneE2ETest.java index 2ee03fba1..260536f28 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobDataPlaneE2ETest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobDataPlaneE2ETest.java @@ -19,8 +19,9 @@ import java.util.UUID; import java.util.stream.Collectors; import org.databiosphere.workspacedataservice.TestUtils; -import org.databiosphere.workspacedataservice.annotations.SingleTenant; +import org.databiosphere.workspacedataservice.config.TwdsProperties; import org.databiosphere.workspacedataservice.dataimport.ImportValidator; +import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.sam.SamDao; import org.databiosphere.workspacedataservice.service.CollectionService; import org.databiosphere.workspacedataservice.service.RecordOrchestratorService; @@ -28,10 +29,8 @@ import org.databiosphere.workspacedataservice.service.model.AttributeSchema; import org.databiosphere.workspacedataservice.service.model.DataTypeMapping; import org.databiosphere.workspacedataservice.service.model.RecordTypeSchema; -import org.databiosphere.workspacedataservice.shared.model.CollectionId; import org.databiosphere.workspacedataservice.shared.model.RecordResponse; import org.databiosphere.workspacedataservice.shared.model.RecordType; -import org.databiosphere.workspacedataservice.shared.model.WorkspaceId; import org.databiosphere.workspacedataservice.workspacemanager.WorkspaceManagerDao; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -63,7 +62,7 @@ "rawlsUrl=https://localhost/" }) class PfbQuartzJobDataPlaneE2ETest { - @Autowired @SingleTenant WorkspaceId workspaceId; + @Autowired TwdsProperties twdsProperties; @Autowired RecordOrchestratorService recordOrchestratorService; @Autowired CollectionService collectionService; @Autowired PfbTestSupport testSupport; @@ -93,8 +92,10 @@ class PfbQuartzJobDataPlaneE2ETest { @BeforeEach void beforeEach() { - collectionId = UUID.randomUUID(); - collectionService.createCollection(workspaceId, CollectionId.of(collectionId), "v0.2"); + CollectionServerModel collectionServerModel = + TestUtils.createCollection(collectionService, twdsProperties.workspaceId()); + collectionId = collectionServerModel.getId(); + // stub out WSM to report no snapshots already linked to this workspace when(wsmDao.enumerateDataRepoSnapshotReferences(any(), anyInt(), anyInt())) .thenReturn(new ResourceList()); diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobE2ETest.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobE2ETest.java index 4051a375d..5a1b39527 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobE2ETest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobE2ETest.java @@ -21,7 +21,9 @@ import java.util.stream.Collectors; import org.databiosphere.workspacedataservice.TestUtils; import org.databiosphere.workspacedataservice.common.TestBase; +import org.databiosphere.workspacedataservice.config.TwdsProperties; import org.databiosphere.workspacedataservice.dataimport.ImportValidator; +import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.generated.ImportRequestServerModel; import org.databiosphere.workspacedataservice.service.CollectionService; import org.databiosphere.workspacedataservice.service.ImportService; @@ -68,6 +70,7 @@ class TdrManifestQuartzJobE2ETest extends TestBase { @Autowired private CollectionService collectionService; @Autowired private TdrTestSupport testSupport; @Autowired private NamedParameterJdbcTemplate namedTemplate; + @Autowired private TwdsProperties twdsProperties; // Mock ImportValidator to allow importing test data from a file:// URL. @MockBean ImportValidator importValidator; @@ -83,8 +86,9 @@ class TdrManifestQuartzJobE2ETest extends TestBase { @BeforeEach void beforeEach() { - collectionId = UUID.randomUUID(); - collectionService.createCollection(collectionId, "v0.2"); + CollectionServerModel collectionServerModel = + TestUtils.createCollection(collectionService, twdsProperties.workspaceId()); + collectionId = collectionServerModel.getId(); } @AfterEach diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobMultipleBatchTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobMultipleBatchTest.java index 5aa3eb9e7..a75ebb486 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobMultipleBatchTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/tdr/TdrManifestQuartzJobMultipleBatchTest.java @@ -17,14 +17,14 @@ import java.util.stream.Collectors; import org.databiosphere.workspacedataservice.TestUtils; import org.databiosphere.workspacedataservice.common.TestBase; +import org.databiosphere.workspacedataservice.config.TwdsProperties; import org.databiosphere.workspacedataservice.dataimport.ImportValidator; +import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.generated.ImportRequestServerModel; import org.databiosphere.workspacedataservice.service.CollectionService; import org.databiosphere.workspacedataservice.service.ImportService; import org.databiosphere.workspacedataservice.service.RecordOrchestratorService; import org.databiosphere.workspacedataservice.service.model.RecordTypeSchema; -import org.databiosphere.workspacedataservice.shared.model.CollectionId; -import org.databiosphere.workspacedataservice.shared.model.WorkspaceId; import org.databiosphere.workspacedataservice.workspacemanager.WorkspaceManagerDao; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -65,6 +65,7 @@ class TdrManifestQuartzJobMultipleBatchTest extends TestBase { @Autowired private CollectionService collectionService; @Autowired private TdrTestSupport testSupport; @Autowired private NamedParameterJdbcTemplate namedTemplate; + @Autowired private TwdsProperties twdsProperties; // Mock ImportValidator to allow importing test data from a file:// URL. @MockBean ImportValidator importValidator; @@ -77,9 +78,9 @@ class TdrManifestQuartzJobMultipleBatchTest extends TestBase { @BeforeEach void beforeEach() { - collectionId = UUID.randomUUID(); - collectionService.createCollection( - WorkspaceId.of(collectionId), CollectionId.of(collectionId), "v0.2"); + CollectionServerModel collectionServerModel = + TestUtils.createCollection(collectionService, twdsProperties.workspaceId()); + collectionId = collectionServerModel.getId(); } @AfterEach diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceNoWorkspaceTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceNoWorkspaceTest.java index 2f1ef6c2f..ca1d675e0 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceNoWorkspaceTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceNoWorkspaceTest.java @@ -2,13 +2,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.when; import java.util.UUID; import org.databiosphere.workspacedataservice.common.TestBase; import org.databiosphere.workspacedataservice.config.TenancyProperties; -import org.databiosphere.workspacedataservice.service.model.exception.CollectionException; +import org.databiosphere.workspacedataservice.config.TwdsProperties; import org.databiosphere.workspacedataservice.shared.model.CollectionId; import org.databiosphere.workspacedataservice.shared.model.WorkspaceId; import org.junit.jupiter.api.Test; @@ -31,6 +29,7 @@ class CollectionServiceNoWorkspaceTest extends TestBase { @Autowired private CollectionService collectionService; @SpyBean private TenancyProperties tenancyProperties; + @Autowired TwdsProperties twdsProperties; @Value("${twds.instance.workspace-id:}") private String workspaceIdProperty; @@ -48,29 +47,4 @@ void getWorkspaceId() { CollectionId collectionId = CollectionId.of(UUID.randomUUID()); assertEquals(WorkspaceId.of(collectionId.id()), collectionService.getWorkspaceId(collectionId)); } - - @Test - void createCollectionNotAllowed_virtualCollectionsEnabled() { - when(tenancyProperties.getAllowVirtualCollections()).thenReturn(true); - UUID collectionId = UUID.randomUUID(); - var thrown = - assertThrows( - CollectionException.class, - () -> collectionService.createCollection(collectionId, "v0.2")); - assertThat(thrown) - .hasMessageContaining("createCollection not allowed when virtual collections are enabled"); - } - - @Test - void createCollectionNotAllowed_missingWorkspaceId() { - when(tenancyProperties.getAllowVirtualCollections()).thenReturn(false); - UUID collectionId = UUID.randomUUID(); - var thrown = - assertThrows( - CollectionException.class, - () -> collectionService.createCollection(collectionId, "v0.2")); - assertThat(thrown) - .hasMessageContaining( - "createCollection requires a workspaceId to be configured or provided"); - } } diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceTest.java index 2d72070c8..5b866f047 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/service/CollectionServiceTest.java @@ -1,16 +1,11 @@ package org.databiosphere.workspacedataservice.service; import static org.assertj.core.api.Assertions.assertThat; -import static org.databiosphere.workspacedataservice.service.RecordUtils.VERSION; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.List; -import java.util.UUID; import org.databiosphere.workspacedataservice.common.TestBase; import org.databiosphere.workspacedataservice.config.TwdsProperties; import org.databiosphere.workspacedataservice.dao.CollectionDao; -import org.databiosphere.workspacedataservice.service.model.exception.MissingObjectException; import org.databiosphere.workspacedataservice.shared.model.CollectionId; import org.databiosphere.workspacedataservice.shared.model.WorkspaceId; import org.junit.jupiter.api.AfterEach; @@ -30,8 +25,6 @@ class CollectionServiceTest extends TestBase { @Autowired private CollectionDao collectionDao; @Autowired private TwdsProperties twdsProperties; - private static final UUID COLLECTION = UUID.fromString("111e9999-e89b-12d3-a456-426614174000"); - @BeforeEach @AfterEach void dropCollectionSchemas() { @@ -89,44 +82,4 @@ void testFindAndCreateDefault() { // find should be empty again assertThat(collectionService.find(workspaceId, collectionId)).isEmpty(); } - - // ========== following tests test the deprecated v0.2 CollectionService APIs - @Test - @Deprecated(forRemoval = true, since = "v0.14.0") - void testCreateAndValidateCollection() { - collectionService.createCollection(COLLECTION, VERSION); - collectionService.validateCollection(COLLECTION); - - UUID invalidCollection = UUID.fromString("000e4444-e22b-22d1-a333-426614174000"); - assertThrows( - MissingObjectException.class, - () -> collectionService.validateCollection(invalidCollection), - "validateCollection should have thrown an error"); - } - - @Test - @Deprecated(forRemoval = true, since = "v0.14.0") - void listCollections() { - collectionService.createCollection(COLLECTION, VERSION); - - UUID secondCollectionId = UUID.fromString("999e1111-e89b-12d3-a456-426614174000"); - collectionService.createCollection(secondCollectionId, VERSION); - - List collections = collectionService.listCollections(VERSION); - - assertThat(collections).hasSize(2).contains(COLLECTION).contains(secondCollectionId); - } - - @Test - @Deprecated(forRemoval = true, since = "v0.14.0") - void deleteCollection() { - collectionService.createCollection(COLLECTION, VERSION); - collectionService.validateCollection(COLLECTION); - - collectionService.deleteCollection(COLLECTION, VERSION); - assertThrows( - MissingObjectException.class, - () -> collectionService.validateCollection(COLLECTION), - "validateCollection should have thrown an error"); - } } diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/service/ImportServiceTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/service/ImportServiceTest.java index d6d6b6a8a..d73dad1e3 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/service/ImportServiceTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/service/ImportServiceTest.java @@ -24,11 +24,10 @@ import java.util.stream.Stream; import org.broadinstitute.dsde.workbench.client.sam.ApiException; import org.broadinstitute.dsde.workbench.client.sam.api.GoogleApi; +import org.databiosphere.workspacedataservice.TestUtils; import org.databiosphere.workspacedataservice.annotations.SingleTenant; import org.databiosphere.workspacedataservice.common.TestBase; -import org.databiosphere.workspacedataservice.dao.CollectionDao; import org.databiosphere.workspacedataservice.dao.JobDao; -import org.databiosphere.workspacedataservice.dao.MockCollectionDao; import org.databiosphere.workspacedataservice.dao.SchedulerDao; import org.databiosphere.workspacedataservice.dataimport.ImportJobInput; import org.databiosphere.workspacedataservice.dataimport.pfb.PfbQuartzJob; @@ -58,6 +57,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; @@ -67,12 +67,12 @@ class ImportServiceTest extends TestBase { @Autowired ImportService importService; - @Autowired CollectionDao collectionDao; @Autowired CollectionService collectionService; @Autowired @SingleTenant WorkspaceId workspaceId; @SpyBean JobDao jobDao; @MockBean SchedulerDao schedulerDao; @MockBean SamClientFactory mockSamClientFactory; + @Autowired NamedParameterJdbcTemplate namedTemplate; /** ArgumentCaptor for the Schedulable passed to {@link SchedulerDao#schedule(Schedulable)}. */ @Captor private ArgumentCaptor schedulableCaptor; @@ -82,8 +82,6 @@ class ImportServiceTest extends TestBase { private final URI importUri = URI.create("https://teststorageaccount.blob.core.windows.net/testcontainer/path/to/file"); - private static final String VERSION = "v0.2"; - @BeforeEach void setUp() throws ApiException { // return the mock ResourcesApi from the mock SamClientFactory @@ -92,9 +90,7 @@ void setUp() throws ApiException { given(mockSamGoogleApi.getArbitraryPetServiceAccountToken(any())).willReturn("arbitraryToken"); // reset to zero collections - if (collectionDao instanceof MockCollectionDao mockCollectionDao) { - mockCollectionDao.clearAllCollections(); - } + TestUtils.cleanAllCollections(collectionService, namedTemplate); } // does createSchedulable properly store the jobId, job group, and job data map? @@ -146,7 +142,7 @@ void persistsJobAsQueued(TypeEnum importType) { // schedulerDao.schedule(), which returns void, returns successfully doNothing().when(schedulerDao).schedule(any(Schedulable.class)); // create collection (in the MockCollectionDao) - collectionService.createCollection(workspaceId, defaultCollectionId(), VERSION); + TestUtils.createCollection(collectionService, workspaceId); // define the import request ImportRequestServerModel importRequest = new ImportRequestServerModel(importType, importUri); // perform the import request @@ -171,7 +167,7 @@ void addsJobToScheduler(TypeEnum importType) { // schedulerDao.schedule(), which returns void, returns successfully doNothing().when(schedulerDao).schedule(any(Schedulable.class)); // create collection (in the MockCollectionDao) - collectionService.createCollection(workspaceId, defaultCollectionId(), VERSION); + TestUtils.createCollection(collectionService, workspaceId); // define the import request ImportRequestServerModel importRequest = new ImportRequestServerModel(importType, importUri); // perform the import request @@ -206,7 +202,7 @@ void failsJobIfSchedulingFails(TypeEnum importType) { .when(schedulerDao) .schedule(any(Schedulable.class)); // create collection (in the MockCollectionDao) - collectionService.createCollection(workspaceId, defaultCollectionId(), VERSION); + TestUtils.createCollection(collectionService, workspaceId); // define the import request ImportRequestServerModel importRequest = new ImportRequestServerModel(importType, importUri); // perform the import request; this will internally hit the exception from the schedulerDao @@ -236,7 +232,8 @@ void doesNotCreateJobWithoutPetToken(TypeEnum importType) throws ApiException { doNothing().when(schedulerDao).schedule(any(Schedulable.class)); // create collection (in the MockCollectionDao) UUID randomCollectionId = UUID.randomUUID(); - collectionService.createCollection(workspaceId, CollectionId.of(randomCollectionId), VERSION); + TestUtils.createCollection(collectionService, workspaceId); + // define the import request ImportRequestServerModel importRequest = new ImportRequestServerModel(importType, importUri); @@ -257,7 +254,7 @@ void doesNotCreateJobIfImportSourceValidationFails(TypeEnum importType) { // schedulerDao.schedule(), which returns void, returns successfully doNothing().when(schedulerDao).schedule(any(Schedulable.class)); // create collection (in the MockCollectionDao) - collectionService.createCollection(workspaceId, defaultCollectionId(), VERSION); + TestUtils.createCollection(collectionService, workspaceId); // Act/Assert URI importUri = @@ -276,7 +273,7 @@ void doesNotCreateJobIfImportSourceValidationFails(TypeEnum importType) { @ValueSource(booleans = {true, false}) void passesThroughIsUpsert(boolean syncPermissions) { // Arrange - collectionService.createCollection(workspaceId, defaultCollectionId(), VERSION); + TestUtils.createCollection(collectionService, workspaceId); ImportRequestServerModel importRequest = new ImportRequestServerModel(TypeEnum.TDRMANIFEST, importUri); importRequest.getOptions().put(OPTION_TDR_SYNC_PERMISSIONS, syncPermissions); diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/service/RecordServiceTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/service/RecordServiceTest.java index f1f32dfdc..7196d8404 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/service/RecordServiceTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/service/RecordServiceTest.java @@ -17,7 +17,9 @@ import org.databiosphere.workspacedataservice.TestUtils; import org.databiosphere.workspacedataservice.annotations.WithTestObservationRegistry; import org.databiosphere.workspacedataservice.common.TestBase; +import org.databiosphere.workspacedataservice.config.TwdsProperties; import org.databiosphere.workspacedataservice.dao.RecordDao; +import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.service.model.DataTypeMapping; import org.databiosphere.workspacedataservice.shared.model.RecordAttributes; import org.databiosphere.workspacedataservice.shared.model.RecordRequest; @@ -40,13 +42,15 @@ class RecordServiceTest extends TestBase { @Autowired RecordDao recordDao; @Autowired TestObservationRegistry observationRegistry; @Autowired NamedParameterJdbcTemplate namedTemplate; + @Autowired TwdsProperties twdsProperties; private UUID collectionId; @BeforeEach void beforeEach() { - collectionId = UUID.randomUUID(); - collectionService.createCollection(collectionId, "v0.2"); + CollectionServerModel collectionServerModel = + TestUtils.createCollection(collectionService, twdsProperties.workspaceId()); + collectionId = collectionServerModel.getId(); } @AfterEach diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/tsv/TsvErrorMessageTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/tsv/TsvErrorMessageTest.java index dd3d0e260..e77c68d90 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/tsv/TsvErrorMessageTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/tsv/TsvErrorMessageTest.java @@ -9,6 +9,8 @@ import java.util.UUID; import org.databiosphere.workspacedataservice.TestUtils; import org.databiosphere.workspacedataservice.common.TestBase; +import org.databiosphere.workspacedataservice.config.TwdsProperties; +import org.databiosphere.workspacedataservice.generated.CollectionServerModel; import org.databiosphere.workspacedataservice.service.CollectionService; import org.databiosphere.workspacedataservice.service.RecordOrchestratorService; import org.databiosphere.workspacedataservice.service.model.exception.InvalidTsvException; @@ -33,6 +35,7 @@ class TsvErrorMessageTest extends TestBase { @Autowired CollectionService collectionService; @Autowired RecordOrchestratorService recordOrchestratorService; @Autowired NamedParameterJdbcTemplate namedTemplate; + @Autowired TwdsProperties twdsProperties; private UUID collectionId; @@ -40,8 +43,9 @@ class TsvErrorMessageTest extends TestBase { @BeforeEach void setUp() { - collectionId = UUID.randomUUID(); - collectionService.createCollection(collectionId, VERSION); + CollectionServerModel collectionServerModel = + TestUtils.createCollection(collectionService, twdsProperties.workspaceId()); + collectionId = collectionServerModel.getId(); } @AfterEach