Search in sources :

Example 1 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class DatasetConnectedTest method testOverlappingDeletes.

@Test
public void testOverlappingDeletes() throws Exception {
    // NO ASSERTS inside the block below where hang is enabled to reduce chance of failing before disabling the hang
    // ====================================================
    // enable hang in DeleteDatasetPrimaryDataStep
    configService.setFault(ConfigEnum.DATASET_DELETE_LOCK_CONFLICT_STOP_FAULT.name(), true);
    // try to delete the dataset
    MvcResult result1 = mvc.perform(delete("/api/repository/v1/datasets/" + summaryModel.getId())).andReturn();
    // give the flight time to launch
    TimeUnit.SECONDS.sleep(5);
    // try to delete the dataset again
    MvcResult result2 = mvc.perform(delete("/api/repository/v1/datasets/" + summaryModel.getId())).andReturn();
    // give the flight time to launch
    TimeUnit.SECONDS.sleep(5);
    // disable hang in DeleteDatasetPrimaryDataStep
    configService.setFault(ConfigEnum.DATASET_DELETE_LOCK_CONFLICT_CONTINUE_FAULT.name(), true);
    // ====================================================
    // check the response from the first delete request
    MockHttpServletResponse response1 = connectedOperations.validateJobModelAndWait(result1);
    DeleteResponseModel deleteResponseModel = connectedOperations.handleSuccessCase(response1, DeleteResponseModel.class);
    assertEquals("First delete returned successfully", DeleteResponseModel.ObjectStateEnum.DELETED, deleteResponseModel.getObjectState());
    // check that the second delete failed with a lock exception
    MockHttpServletResponse response2 = connectedOperations.validateJobModelAndWait(result2);
    ErrorModel errorModel2 = connectedOperations.handleFailureCase(response2, HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat("delete failed on lock exception", errorModel2.getMessage(), startsWith("Failed to lock the dataset"));
    // try to fetch the dataset again and confirm nothing is returned
    connectedOperations.getDatasetExpectError(summaryModel.getId(), HttpStatus.NOT_FOUND);
}
Also used : ErrorModel(bio.terra.model.ErrorModel) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DeleteResponseModel(bio.terra.model.DeleteResponseModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class DatasetConnectedTest method testDuplicateName.

@Test
public void testDuplicateName() throws Exception {
    assertNotNull("created dataset successfully the first time", summaryModel);
    // fetch the dataset and confirm the metadata matches the request
    DatasetModel datasetModel = connectedOperations.getDataset(summaryModel.getId());
    assertNotNull("fetched dataset successfully after creation", datasetModel);
    assertEquals("fetched dataset name matches request", datasetRequest.getName(), datasetModel.getName());
    // check that the dataset metadata row is unlocked
    String exclusiveLock = datasetDao.getExclusiveLock(UUID.fromString(summaryModel.getId()));
    assertNull("dataset row is unlocked", exclusiveLock);
    // try to create the same dataset again and check that it fails
    ErrorModel errorModel = connectedOperations.createDatasetExpectError(datasetRequest, HttpStatus.BAD_REQUEST);
    assertThat("error message includes name conflict", errorModel.getMessage(), containsString("Dataset name already exists"));
    // delete the dataset and check that it succeeds
    connectedOperations.deleteTestDataset(summaryModel.getId());
    // try to fetch the dataset again and confirm nothing is returned
    connectedOperations.getDatasetExpectError(summaryModel.getId(), HttpStatus.NOT_FOUND);
}
Also used : ErrorModel(bio.terra.model.ErrorModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testDuplicateAssetNames.

@Test
public void testDuplicateAssetNames() throws Exception {
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().assets(Arrays.asList(buildAsset(), buildAsset()));
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "DuplicateAssetNames" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testInvalidAssetTable.

@Test
public void testInvalidAssetTable() throws Exception {
    AssetTableModel invalidAssetTable = new AssetTableModel().name("mismatched_table_name").columns(Collections.emptyList());
    AssetModel asset = new AssetModel().name("bad_asset").rootTable("mismatched_table_name").tables(Collections.singletonList(invalidAssetTable)).follow(Collections.singletonList("participant_sample"));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().assets(Collections.singletonList(asset));
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "NotNull", "InvalidAssetTable", "InvalidRootColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testPartitionOptionsWithoutMode.

@Test
public void testPartitionOptionsWithoutMode() throws Exception {
    TableModel table = new TableModel().name("table").columns(Collections.emptyList()).datePartitionOptions(new DatePartitionOptionsModel().column("foo")).intPartitionOptions(new IntPartitionOptionsModel().column("bar").min(1L).max(2L).interval(1L));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Collections.singletonList(table)).relationships(Collections.emptyList()).assets(Collections.emptyList());
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "InvalidDatePartitionOptions", "InvalidIntPartitionOptions" });
}
Also used : IntPartitionOptionsModel(bio.terra.model.IntPartitionOptionsModel) DatasetRequestModel(bio.terra.model.DatasetRequestModel) DatePartitionOptionsModel(bio.terra.model.DatePartitionOptionsModel) ErrorModel(bio.terra.model.ErrorModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ErrorModel (bio.terra.model.ErrorModel)48 Test (org.junit.Test)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 DatasetRequestModel (bio.terra.model.DatasetRequestModel)21 AssetTableModel (bio.terra.model.AssetTableModel)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)16 MvcResult (org.springframework.test.web.servlet.MvcResult)14 TableModel (bio.terra.model.TableModel)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 ColumnModel (bio.terra.model.ColumnModel)8 IntPartitionOptionsModel (bio.terra.model.IntPartitionOptionsModel)6 AssetModel (bio.terra.model.AssetModel)5 FileModel (bio.terra.model.FileModel)5 DatePartitionOptionsModel (bio.terra.model.DatePartitionOptionsModel)4 IngestRequestModel (bio.terra.model.IngestRequestModel)4 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)3 DeleteResponseModel (bio.terra.model.DeleteResponseModel)3 FileLoadModel (bio.terra.model.FileLoadModel)3 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)3 Blob (com.google.cloud.storage.Blob)3