Search in sources :

Example 11 with DatasetSummaryModel

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

the class SnapshotConnectedTest method setupMinimalDataset.

private DatasetSummaryModel setupMinimalDataset() throws Exception {
    DatasetSummaryModel datasetMinimalSummary = createTestDataset("dataset-minimal.json");
    loadCsvData(datasetMinimalSummary.getId(), "participant", "dataset-minimal-participant.csv");
    loadCsvData(datasetMinimalSummary.getId(), "sample", "dataset-minimal-sample.csv");
    return datasetMinimalSummary;
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel)

Example 12 with DatasetSummaryModel

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

the class DatasetIntegrationTest method datasetUnauthorizedPermissionsTest.

@Test
public void datasetUnauthorizedPermissionsTest() throws Exception {
    dataRepoFixtures.createDatasetError(custodian(), "dataset-minimal.json", HttpStatus.UNAUTHORIZED);
    dataRepoFixtures.createDatasetError(reader(), "dataset-minimal.json", HttpStatus.UNAUTHORIZED);
    EnumerateDatasetModel enumDatasetsResp = dataRepoFixtures.enumerateDatasets(reader());
    List<DatasetSummaryModel> items = enumDatasetsResp.getItems();
    if (items != null) {
        for (DatasetSummaryModel datasetModel : items) {
            logger.info(String.format("found dataset for reader: %s, created: %s", datasetModel.getId(), datasetModel.getCreatedDate()));
        }
    }
    assertThat("Reader does not have access to datasets", enumDatasetsResp.getTotal(), equalTo(0));
    DatasetSummaryModel summaryModel = null;
    summaryModel = dataRepoFixtures.createDataset(steward(), "dataset-minimal.json");
    datasetId = summaryModel.getId();
    DataRepoResponse<DatasetModel> getDatasetResp = dataRepoFixtures.getDatasetRaw(reader(), summaryModel.getId());
    assertThat("Reader is not authorized to get dataset", getDatasetResp.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
    // make sure reader cannot delete dataset
    DataRepoResponse<JobModel> deleteResp1 = dataRepoFixtures.deleteDatasetLaunch(reader(), summaryModel.getId());
    assertThat("Reader is not authorized to delete datasets", deleteResp1.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
    // right now the authorization for dataset delete is done directly in the controller.
    // so we need to check the response to the delete request for the unauthorized failure
    // once we move the authorization for dataset delete into a separate step,
    // then the check will need two parts, as below:
    // check job launched successfully, check job result is failure with unauthorized
    // DataRepoResponse<JobModel> jobResp1 = dataRepoFixtures.deleteDatasetLaunch(
    // reader(), summaryModel.getId());
    // assertTrue("dataset delete launch succeeded", jobResp1.getStatusCode().is2xxSuccessful());
    // assertTrue("dataset delete launch response is present", jobResp1.getResponseObject().isPresent());
    // DataRepoResponse<ErrorModel> deleteResp1 = dataRepoClient.waitForResponse(
    // reader(), jobResp1, ErrorModel.class);
    // assertThat("Reader is not authorized to delete datasets",
    // deleteResp1.getStatusCode(),
    // equalTo(HttpStatus.UNAUTHORIZED));
    // make sure custodian cannot delete dataset
    DataRepoResponse<JobModel> deleteResp2 = dataRepoFixtures.deleteDatasetLaunch(custodian(), summaryModel.getId());
    assertThat("Custodian is not authorized to delete datasets", deleteResp2.getStatusCode(), equalTo(HttpStatus.UNAUTHORIZED));
// same comment as above for the reader() delete
// DataRepoResponse<JobModel> jobResp2 = dataRepoFixtures.deleteDatasetLaunch(
// custodian(), summaryModel.getId());
// assertTrue("dataset delete launch succeeded", jobResp2.getStatusCode().is2xxSuccessful());
// assertTrue("dataset delete launch response is present", jobResp2.getResponseObject().isPresent());
// DataRepoResponse<ErrorModel> deleteResp2 = dataRepoClient.waitForResponse(
// custodian(), jobResp2, ErrorModel.class);
// assertThat("Custodian is not authorized to delete datasets",
// deleteResp2.getStatusCode(),
// equalTo(HttpStatus.UNAUTHORIZED));
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) JobModel(bio.terra.model.JobModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 13 with DatasetSummaryModel

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

the class DatasetIntegrationTest method testAssetCreationUndo.

@Test
public void testAssetCreationUndo() throws Exception {
    // create a dataset
    DatasetSummaryModel summaryModel = dataRepoFixtures.createDataset(steward(), "it-dataset-omop.json");
    datasetId = summaryModel.getId();
    DatasetModel datasetModel = dataRepoFixtures.getDataset(steward(), summaryModel.getId());
    List<AssetModel> originalAssetList = datasetModel.getSchema().getAssets();
    assertThat("Asset specification is as originally expected", originalAssetList.size(), equalTo(1));
    AssetModel assetModel = new AssetModel().name("assetName").rootTable("person").rootColumn("person_id").tables(Arrays.asList(DatasetFixtures.buildAssetParticipantTable(), DatasetFixtures.buildAssetSampleTable())).follow(Collections.singletonList("fpk_visit_person"));
    // have the asset creation fail
    // by calling the fault insertion
    dataRepoFixtures.setFault(steward(), ConfigEnum.CREATE_ASSET_FAULT.name(), true);
    // add an asset spec
    dataRepoFixtures.addDatasetAsset(steward(), datasetModel.getId(), assetModel);
    // make sure undo is completed successfully
    DatasetModel datasetModelWAsset = dataRepoFixtures.getDataset(steward(), datasetModel.getId());
    DatasetSpecificationModel datasetSpecificationModel = datasetModelWAsset.getSchema();
    List<AssetModel> assetList = datasetSpecificationModel.getAssets();
    // assert that the asset isn't there
    assertThat("Additional asset specification has never been added", assetList.size(), equalTo(1));
}
Also used : DatasetSpecificationModel(bio.terra.model.DatasetSpecificationModel) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) AssetModel(bio.terra.model.AssetModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 14 with DatasetSummaryModel

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

the class DatasetIntegrationTest method datasetHappyPath.

@Test
public void datasetHappyPath() throws Exception {
    DatasetSummaryModel summaryModel = dataRepoFixtures.createDataset(steward(), "it-dataset-omop.json");
    datasetId = summaryModel.getId();
    logger.info("dataset id is " + summaryModel.getId());
    assertThat(summaryModel.getName(), startsWith(omopDatasetName));
    assertThat(summaryModel.getDescription(), equalTo(omopDatasetDesc));
    DatasetModel datasetModel = dataRepoFixtures.getDataset(steward(), summaryModel.getId());
    assertThat(datasetModel.getName(), startsWith(omopDatasetName));
    assertThat(datasetModel.getDescription(), equalTo(omopDatasetDesc));
    // There is a delay from when a resource is created in SAM to when it is available in an enumerate call.
    boolean metExpectation = TestUtils.eventualExpect(5, 60, true, () -> {
        EnumerateDatasetModel enumerateDatasetModel = dataRepoFixtures.enumerateDatasets(steward());
        boolean found = false;
        for (DatasetSummaryModel oneDataset : enumerateDatasetModel.getItems()) {
            if (oneDataset.getId().equals(datasetModel.getId())) {
                assertThat(oneDataset.getName(), startsWith(omopDatasetName));
                assertThat(oneDataset.getDescription(), equalTo(omopDatasetDesc));
                found = true;
                break;
            }
        }
        return found;
    });
    assertTrue("dataset was found in enumeration", metExpectation);
    // test allowable permissions
    dataRepoFixtures.addDatasetPolicyMember(steward(), summaryModel.getId(), IamRole.CUSTODIAN, custodian().getEmail());
    DataRepoResponse<EnumerateDatasetModel> enumDatasets = dataRepoFixtures.enumerateDatasetsRaw(custodian());
    assertThat("Custodian is authorized to enumerate datasets", enumDatasets.getStatusCode(), equalTo(HttpStatus.OK));
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) DatasetModel(bio.terra.model.DatasetModel) EnumerateDatasetModel(bio.terra.model.EnumerateDatasetModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with DatasetSummaryModel

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

the class OneProjectPerProfileIdSelectorTest method shouldGetCorrectIdForSnapshot.

@Test
public void shouldGetCorrectIdForSnapshot() throws Exception {
    String coreBillingAccountId = resourceConfiguration.getCoreBillingAccount();
    String profileName = ProfileFixtures.randomHex(16);
    BillingProfileRequestModel billingProfileRequestModel = ProfileFixtures.randomBillingProfileRequest().billingAccountId(coreBillingAccountId).profileName(profileName);
    BillingProfileModel profile = profileService.createProfile(billingProfileRequestModel);
    DatasetSummaryModel datasetSummaryModel = connectedOperations.createDataset(profile, "snapshot-test-dataset.json");
    SnapshotSummaryModel snapshotSummaryModel = connectedOperations.createSnapshot(datasetSummaryModel, "snapshot-test-snapshot.json", "");
    SnapshotModel snapshotModel = connectedOperations.getSnapshot(snapshotSummaryModel.getId());
    Snapshot snapshot = snapshotService.retrieve(UUID.fromString(snapshotModel.getId()));
    // TODO: we can test this once configuring firestore is programatic
    String projectId = oneProjectPerProfileIdSelector.projectIdForSnapshot(snapshot);
    String expectedProfileId = resourceConfiguration.getProjectId() + "-" + profileName;
    assertThat("Project ID is what we expect", projectId, equalTo(expectedProfileId));
}
Also used : Snapshot(bio.terra.service.snapshot.Snapshot) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) BillingProfileRequestModel(bio.terra.model.BillingProfileRequestModel) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) BillingProfileModel(bio.terra.model.BillingProfileModel) SnapshotModel(bio.terra.model.SnapshotModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)28 Test (org.junit.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 IngestRequestModel (bio.terra.model.IngestRequestModel)11 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)9 MvcResult (org.springframework.test.web.servlet.MvcResult)8 Dataset (bio.terra.service.dataset.Dataset)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 SnapshotModel (bio.terra.model.SnapshotModel)6 BillingProfileModel (bio.terra.model.BillingProfileModel)5 EnumerateDatasetModel (bio.terra.model.EnumerateDatasetModel)5 BlobInfo (com.google.cloud.storage.BlobInfo)5 DatasetModel (bio.terra.model.DatasetModel)4 ErrorModel (bio.terra.model.ErrorModel)4 Blob (com.google.cloud.storage.Blob)4 BillingProfileRequestModel (bio.terra.model.BillingProfileRequestModel)3 DRSObject (bio.terra.model.DRSObject)3 DeleteResponseModel (bio.terra.model.DeleteResponseModel)3 FileModel (bio.terra.model.FileModel)3