Search in sources :

Example 1 with SnapshotRequestModel

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

the class SnapshotValidationTest method makeSnapshotRowIdsRequest.

// Generate a valid snapshot-by-rowId request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotRowIdsRequest() {
    SnapshotRequestRowIdTableModel snapshotRequestTableModel = new SnapshotRequestRowIdTableModel().tableName("snapshot").columns(Arrays.asList("col1", "col2", "col3")).rowIds(Arrays.asList("row1", "row2", "row3"));
    SnapshotRequestRowIdModel rowIdSpec = new SnapshotRequestRowIdModel().tables(Collections.singletonList(snapshotRequestTableModel));
    SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYROWID).rowIdSpec(rowIdSpec);
    return new SnapshotRequestModel().contents(Collections.singletonList(snapshotRequestContentsModel));
}
Also used : SnapshotRequestRowIdTableModel(bio.terra.model.SnapshotRequestRowIdTableModel) SnapshotRequestRowIdModel(bio.terra.model.SnapshotRequestRowIdModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

Example 2 with SnapshotRequestModel

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

the class SnapshotValidationTest method makeSnapshotByQueryRequest.

// Generate a valid snapshot-by-query request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotByQueryRequest() {
    SnapshotRequestQueryModel querySpec = new SnapshotRequestQueryModel().assetName("asset").query("SELECT * FROM dataset");
    SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYQUERY).querySpec(querySpec);
    return new SnapshotRequestModel().contents(Collections.singletonList(snapshotRequestContentsModel));
}
Also used : SnapshotRequestQueryModel(bio.terra.model.SnapshotRequestQueryModel) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

Example 3 with SnapshotRequestModel

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

the class SnapshotValidationTest method testSnapshotByQuery.

@Test
public void testSnapshotByQuery() throws Exception {
    SnapshotRequestModel querySpec = this.snapshotByQueryRequestModel;
    querySpec.getContents().get(0).getQuerySpec().setQuery(null);
    expectBadSnapshotCreateRequest(snapshotByQueryRequestModel);
}
Also used : SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SnapshotRequestModel

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

the class SnapshotTest method snapshotRowIdsHappyPathTest.

@Test
public void snapshotRowIdsHappyPathTest() throws Exception {
    // fetch rowIds from the ingested dataset by querying the participant table
    DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
    String datasetProject = dataset.getDataProject();
    String bqDatasetName = PdaoConstant.PDAO_PREFIX + dataset.getName();
    String participantTable = "participant";
    String sampleTable = "sample";
    BigQuery bigQuery = BigQueryFixtures.getBigQuery(dataset.getDataProject(), stewardToken);
    String sql = String.format("SELECT %s FROM `%s.%s.%s`", PdaoConstant.PDAO_ROW_ID_COLUMN, datasetProject, bqDatasetName, participantTable);
    TableResult participantIds = BigQueryFixtures.query(sql, bigQuery);
    List<String> participantIdList = StreamSupport.stream(participantIds.getValues().spliterator(), false).map(v -> v.get(0).getStringValue()).collect(Collectors.toList());
    sql = String.format("SELECT %s FROM `%s.%s.%s`", PdaoConstant.PDAO_ROW_ID_COLUMN, datasetProject, bqDatasetName, sampleTable);
    TableResult sampleIds = BigQueryFixtures.query(sql, bigQuery);
    List<String> sampleIdList = StreamSupport.stream(sampleIds.getValues().spliterator(), false).map(v -> v.get(0).getStringValue()).collect(Collectors.toList());
    // swap in these row ids in the request
    SnapshotRequestModel requestModel = jsonLoader.loadObject("ingest-test-snapshot-row-ids-test.json", SnapshotRequestModel.class);
    requestModel.getContents().get(0).getRowIdSpec().getTables().get(0).setRowIds(participantIdList);
    requestModel.getContents().get(0).getRowIdSpec().getTables().get(1).setRowIds(sampleIdList);
    SnapshotSummaryModel snapshotSummary = dataRepoFixtures.createSnapshotWithRequest(steward(), dataset.getName(), requestModel);
    TimeUnit.SECONDS.sleep(10);
    createdSnapshotIds.add(snapshotSummary.getId());
    SnapshotModel snapshot = dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId());
    assertEquals("new snapshot has been created", snapshot.getName(), requestModel.getName());
    assertEquals("new snapshot has the correct number of tables", requestModel.getContents().get(0).getRowIdSpec().getTables().size(), snapshot.getTables().size());
    // TODO: get the snapshot and make sure the number of rows matches with the row ids input
    assertThat("one relationship comes through", snapshot.getRelationships().size(), equalTo(1));
    assertThat("the right relationship comes through", snapshot.getRelationships().get(0).getName(), equalTo("sample_participants"));
}
Also used : SnapshotModel(bio.terra.model.SnapshotModel) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) BigQuery(com.google.cloud.bigquery.BigQuery) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) DataRepoResponse(bio.terra.integration.DataRepoResponse) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) After(org.junit.After) JsonLoader(bio.terra.common.fixtures.JsonLoader) StreamSupport(java.util.stream.StreamSupport) TableResult(com.google.cloud.bigquery.TableResult) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Before(org.junit.Before) Logger(org.slf4j.Logger) AuthService(bio.terra.common.auth.AuthService) Test(org.junit.Test) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) IamRole(bio.terra.service.iam.IamRole) TimeUnit(java.util.concurrent.TimeUnit) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) UsersBase(bio.terra.integration.UsersBase) IngestRequestModel(bio.terra.model.IngestRequestModel) AutoConfigureMockMvc(org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) BigQueryFixtures(bio.terra.integration.BigQueryFixtures) JobModel(bio.terra.model.JobModel) DataRepoClient(bio.terra.integration.DataRepoClient) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PdaoConstant(bio.terra.common.PdaoConstant) Integration(bio.terra.common.category.Integration) DataRepoFixtures(bio.terra.integration.DataRepoFixtures) DatasetModel(bio.terra.model.DatasetModel) Assert.assertEquals(org.junit.Assert.assertEquals) BigQuery(com.google.cloud.bigquery.BigQuery) TableResult(com.google.cloud.bigquery.TableResult) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) DatasetModel(bio.terra.model.DatasetModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SnapshotRequestModel

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

the class SnapshotTest method snapshotByQueryHappyPathTest.

@Test
public void snapshotByQueryHappyPathTest() throws Exception {
    DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
    String datasetName = dataset.getName();
    SnapshotRequestModel requestModel = jsonLoader.loadObject("ingest-test-snapshot-query.json", SnapshotRequestModel.class);
    // swap in the correct dataset name (with the id at the end)
    requestModel.getContents().get(0).setDatasetName(datasetName);
    requestModel.getContents().get(0).getQuerySpec().setQuery("SELECT " + datasetName + ".sample.datarepo_row_id FROM " + datasetName + ".sample WHERE " + datasetName + ".sample.id ='sample6'");
    SnapshotSummaryModel snapshotSummary = dataRepoFixtures.createSnapshotWithRequest(steward(), datasetName, requestModel);
    TimeUnit.SECONDS.sleep(10);
    createdSnapshotIds.add(snapshotSummary.getId());
    SnapshotModel snapshot = dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId());
    assertEquals("new snapshot has been created", snapshot.getName(), requestModel.getName());
}
Also used : SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) DatasetModel(bio.terra.model.DatasetModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SnapshotRequestModel (bio.terra.model.SnapshotRequestModel)18 Test (org.junit.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)9 SnapshotModel (bio.terra.model.SnapshotModel)8 EnumerateSnapshotModel (bio.terra.model.EnumerateSnapshotModel)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 SnapshotRequestContentsModel (bio.terra.model.SnapshotRequestContentsModel)6 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 DatasetModel (bio.terra.model.DatasetModel)4 ErrorModel (bio.terra.model.ErrorModel)4 BigQuery (com.google.cloud.bigquery.BigQuery)4 JsonLoader (bio.terra.common.fixtures.JsonLoader)3 IngestRequestModel (bio.terra.model.IngestRequestModel)3 BigQueryProject (bio.terra.service.tabulardata.google.BigQueryProject)3 ConnectedTestConfiguration (bio.terra.app.configuration.ConnectedTestConfiguration)2 PDAO_PREFIX (bio.terra.common.PdaoConstant.PDAO_PREFIX)2 TestUtils (bio.terra.common.TestUtils)2 Connected (bio.terra.common.category.Connected)2