use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotConnectedTest method testMinimal.
@Test
public void testMinimal() throws Exception {
DatasetSummaryModel datasetMinimalSummary = setupMinimalDataset();
String datasetName = PDAO_PREFIX + datasetMinimalSummary.getName();
BigQueryProject bigQueryProject = TestUtils.bigQueryProjectForDatasetName(datasetDao, dataLocationService, datasetMinimalSummary.getName());
long datasetParticipants = queryForCount(datasetName, "participant", bigQueryProject);
assertThat("dataset participants loaded properly", datasetParticipants, equalTo(2L));
long datasetSamples = queryForCount(datasetName, "sample", bigQueryProject);
assertThat("dataset samples loaded properly", datasetSamples, equalTo(5L));
SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetMinimalSummary, "dataset-minimal-snapshot.json");
MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "");
SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
SnapshotModel snapshotModel = getTestSnapshot(summaryModel.getId(), snapshotRequest, datasetMinimalSummary);
List<TableModel> tables = snapshotModel.getTables();
Optional<TableModel> participantTable = tables.stream().filter(t -> t.getName().equals("participant")).findFirst();
Optional<TableModel> sampleTable = tables.stream().filter(t -> t.getName().equals("sample")).findFirst();
assertThat("participant table exists", participantTable.isPresent(), equalTo(true));
assertThat("sample table exists", sampleTable.isPresent(), equalTo(true));
long snapshotParticipants = queryForCount(summaryModel.getName(), "participant", bigQueryProject);
assertThat("dataset participants loaded properly", snapshotParticipants, equalTo(1L));
assertThat("participant row count matches expectation", participantTable.get().getRowCount(), equalTo(1));
long snapshotSamples = queryForCount(summaryModel.getName(), "sample", bigQueryProject);
assertThat("dataset samples loaded properly", snapshotSamples, equalTo(2L));
assertThat("sample row count matches expectation", sampleTable.get().getRowCount(), equalTo(2));
List<RelationshipModel> relationships = snapshotModel.getRelationships();
assertThat("a relationship comes back", relationships.size(), equalTo(1));
RelationshipModel relationshipModel = relationships.get(0);
assertThat("relationship name is right", relationshipModel.getName(), equalTo("participant_sample"));
assertThat("from table is right", relationshipModel.getFrom().getTable(), equalTo("participant"));
assertThat("from column is right", relationshipModel.getFrom().getColumn(), equalTo("id"));
assertThat("to table is right", relationshipModel.getTo().getTable(), equalTo("sample"));
assertThat("to column is right", relationshipModel.getTo().getColumn(), equalTo("participant_id"));
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotConnectedTest method testArrayStruct.
@Test
public void testArrayStruct() throws Exception {
DatasetSummaryModel datasetArraySummary = setupArrayStructDataset();
String datasetName = PDAO_PREFIX + datasetArraySummary.getName();
BigQueryProject bigQueryProject = TestUtils.bigQueryProjectForDatasetName(datasetDao, dataLocationService, datasetArraySummary.getName());
long datasetParticipants = queryForCount(datasetName, "participant", bigQueryProject);
assertThat("dataset participants loaded properly", datasetParticipants, equalTo(2L));
long datasetSamples = queryForCount(datasetName, "sample", bigQueryProject);
assertThat("dataset samples loaded properly", datasetSamples, equalTo(5L));
SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetArraySummary, "snapshot-array-struct.json");
MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "");
SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
getTestSnapshot(summaryModel.getId(), snapshotRequest, datasetArraySummary);
long snapshotParticipants = queryForCount(summaryModel.getName(), "participant", bigQueryProject);
assertThat("dataset participants loaded properly", snapshotParticipants, equalTo(2L));
long snapshotSamples = queryForCount(summaryModel.getName(), "sample", bigQueryProject);
assertThat("dataset samples loaded properly", snapshotSamples, equalTo(3L));
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotConnectedTest method testDuplicateName.
@Test
public void testDuplicateName() throws Exception {
// create a snapshot
SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetSummary, "snapshot-test-snapshot.json");
MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "_dup_");
SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
// fetch the snapshot and confirm the metadata matches the request
SnapshotModel snapshotModel = getTestSnapshot(summaryModel.getId(), snapshotRequest, datasetSummary);
assertNotNull("fetched snapshot successfully after creation", snapshotModel);
// check that the snapshot metadata row is unlocked
String exclusiveLock = snapshotDao.getExclusiveLockState(UUID.fromString(snapshotModel.getId()));
assertNull("snapshot row is unlocked", exclusiveLock);
// try to create the same snapshot again and check that it fails
snapshotRequest.setName(snapshotModel.getName());
response = performCreateSnapshot(snapshotRequest, null);
ErrorModel errorModel = handleCreateSnapshotFailureCase(response);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST.value()));
assertThat("error message includes name conflict", errorModel.getMessage(), containsString("Snapshot name already exists"));
// delete and confirm deleted
connectedOperations.deleteTestSnapshot(snapshotModel.getId());
connectedOperations.getSnapshotExpectError(snapshotModel.getId(), HttpStatus.NOT_FOUND);
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotTest method snapshotByFullViewHappyPathTest.
@Test
public void snapshotByFullViewHappyPathTest() throws Exception {
DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
String datasetName = dataset.getName();
SnapshotRequestModel requestModel = jsonLoader.loadObject("ingest-test-snapshot-fullviews.json", SnapshotRequestModel.class);
// swap in the correct dataset name (with the id at the end)
requestModel.getContents().get(0).setDatasetName(datasetName);
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());
assertEquals("all 5 relationships come through", snapshot.getRelationships().size(), 5);
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotRequestValidator method validate.
@Override
public void validate(@NotNull Object target, Errors errors) {
if (target != null && target instanceof SnapshotRequestModel) {
SnapshotRequestModel snapshotRequestModel = (SnapshotRequestModel) target;
validateSnapshotName(snapshotRequestModel.getName(), errors);
validateSnapshotProfileId(snapshotRequestModel.getProfileId(), errors);
validateSnapshotDescription(snapshotRequestModel.getDescription(), errors);
validateSnapshotContents(snapshotRequestModel.getContents(), errors);
}
}
Aggregations