Search in sources :

Example 6 with SnapshotRequestModel

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

the class SnapshotConnectedTest method testBadData.

@Test
public void testBadData() throws Exception {
    SnapshotRequestModel badDataRequest = makeSnapshotTestRequest(datasetSummary, "snapshot-test-snapshot-baddata.json");
    MockHttpServletResponse response = performCreateSnapshot(badDataRequest, "_baddata_");
    ErrorModel errorModel = handleCreateSnapshotFailureCase(response);
    assertThat(errorModel.getMessage(), containsString("Fred"));
}
Also used : ErrorModel(bio.terra.model.ErrorModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with SnapshotRequestModel

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

the class SnapshotConnectedTest method testMinimalBadAsset.

@Test
public void testMinimalBadAsset() throws Exception {
    DatasetSummaryModel datasetMinimalSummary = setupMinimalDataset();
    SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetMinimalSummary, "dataset-minimal-snapshot-bad-asset.json");
    MvcResult result = launchCreateSnapshot(snapshotRequest, "");
    MockHttpServletResponse response = connectedOperations.validateJobModelAndWait(result);
    assertThat(response.getStatus(), equalTo(HttpStatus.NOT_FOUND.value()));
}
Also used : DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) MvcResult(org.springframework.test.web.servlet.MvcResult) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 8 with SnapshotRequestModel

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

the class SnapshotConnectedTest method testEnumeration.

@Test
public void testEnumeration() throws Exception {
    SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetSummary, "snapshot-test-snapshot.json");
    // Other unit tests exercise the array bounds, so here we don't fuss with that here.
    // Just make sure we get the same snapshot summary that we made.
    List<SnapshotSummaryModel> snapshotList = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "_en_");
        SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
        snapshotList.add(summaryModel);
    }
    List<UUID> snapshotIds = snapshotList.stream().map(snapshot -> UUID.fromString(snapshot.getId())).collect(Collectors.toList());
    when(samService.listAuthorizedResources(any(), any())).thenReturn(snapshotIds);
    EnumerateSnapshotModel enumResponse = enumerateTestSnapshots();
    List<SnapshotSummaryModel> enumeratedArray = enumResponse.getItems();
    assertThat("total is correct", enumResponse.getTotal(), equalTo(5));
    // The enumeratedArray may contain more snapshots than just the set we created,
    // but ours should be in order in the enumeration. So we do a merge waiting until we match
    // by id and then comparing contents.
    int compareIndex = 0;
    for (SnapshotSummaryModel anEnumeratedSnapshot : enumeratedArray) {
        if (anEnumeratedSnapshot.getId().equals(snapshotList.get(compareIndex).getId())) {
            assertThat("MetadataEnumeration summary matches create summary", anEnumeratedSnapshot, equalTo(snapshotList.get(compareIndex)));
            compareIndex++;
        }
    }
    assertThat("we found all snapshots", compareIndex, equalTo(5));
    for (int i = 0; i < 5; i++) {
        connectedOperations.deleteTestSnapshot(enumeratedArray.get(i).getId());
    }
}
Also used : BillingProfileModel(bio.terra.model.BillingProfileModel) FieldValue(com.google.cloud.bigquery.FieldValue) CoreMatchers(org.hamcrest.CoreMatchers) SnapshotModel(bio.terra.model.SnapshotModel) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) StorageOptions(com.google.cloud.storage.StorageOptions) StringUtils(org.apache.commons.lang3.StringUtils) BigQuery(com.google.cloud.bigquery.BigQuery) Assert.assertThat(org.junit.Assert.assertThat) RelationshipModel(bio.terra.model.RelationshipModel) FieldValueList(com.google.cloud.bigquery.FieldValueList) After(org.junit.After) DrsId(bio.terra.service.filedata.DrsId) TableResult(com.google.cloud.bigquery.TableResult) SpringRunner(org.springframework.test.context.junit4.SpringRunner) URI(java.net.URI) DataLocationService(bio.terra.service.resourcemanagement.DataLocationService) MockBean(org.springframework.boot.test.mock.mockito.MockBean) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PDAO_PREFIX(bio.terra.common.PdaoConstant.PDAO_PREFIX) MediaType(org.springframework.http.MediaType) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) Collectors(java.util.stream.Collectors) DatasetSummaryModel(bio.terra.model.DatasetSummaryModel) StandardCharsets(java.nio.charset.StandardCharsets) ConfigEnum(bio.terra.service.configuration.ConfigEnum) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ST(org.stringtemplate.v4.ST) Assert.assertFalse(org.junit.Assert.assertFalse) TestUtils(bio.terra.common.TestUtils) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Storage(com.google.cloud.storage.Storage) ConfigurationService(bio.terra.service.configuration.ConfigurationService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) GoogleResourceConfiguration(bio.terra.service.resourcemanagement.google.GoogleResourceConfiguration) ConnectedOperations(bio.terra.common.fixtures.ConnectedOperations) Names(bio.terra.common.fixtures.Names) DRSObject(bio.terra.model.DRSObject) RunWith(org.junit.runner.RunWith) BigQueryProject(bio.terra.service.tabulardata.google.BigQueryProject) DrsIdService(bio.terra.service.filedata.DrsIdService) TableModel(bio.terra.model.TableModel) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ArrayList(java.util.ArrayList) MockMvc(org.springframework.test.web.servlet.MockMvc) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) MockMvcRequestBuilders.delete(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) MvcResult(org.springframework.test.web.servlet.MvcResult) JsonLoader(bio.terra.common.fixtures.JsonLoader) ProfileDao(bio.terra.service.resourcemanagement.ProfileDao) ConnectedTestConfiguration(bio.terra.app.configuration.ConnectedTestConfiguration) StringStartsWith.startsWith(org.hamcrest.core.StringStartsWith.startsWith) Before(org.junit.Before) BlobInfo(com.google.cloud.storage.BlobInfo) FileLoadModel(bio.terra.model.FileLoadModel) FileModel(bio.terra.model.FileModel) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Connected(bio.terra.common.category.Connected) Assert.assertTrue(org.junit.Assert.assertTrue) DeleteResponseModel(bio.terra.model.DeleteResponseModel) Test(org.junit.Test) IamProviderInterface(bio.terra.service.iam.IamProviderInterface) Mockito.when(org.mockito.Mockito.when) SnapshotSourceModel(bio.terra.model.SnapshotSourceModel) DatasetDao(bio.terra.service.dataset.DatasetDao) TimeUnit(java.util.concurrent.TimeUnit) ErrorModel(bio.terra.model.ErrorModel) HttpStatus(org.springframework.http.HttpStatus) IngestRequestModel(bio.terra.model.IngestRequestModel) AutoConfigureMockMvc(org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc) Assert.assertNull(org.junit.Assert.assertNull) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) Assert.assertEquals(org.junit.Assert.assertEquals) SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) ArrayList(java.util.ArrayList) UUID(java.util.UUID) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with SnapshotRequestModel

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

the class SnapshotConnectedTest method snapshotHappyPathTestingHelper.

private void snapshotHappyPathTestingHelper(String path) throws Exception {
    SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetSummary, path);
    MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "_thp_");
    SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
    SnapshotModel snapshotModel = getTestSnapshot(summaryModel.getId(), snapshotRequest, datasetSummary);
    connectedOperations.deleteTestSnapshot(snapshotModel.getId());
    // Duplicate delete should work
    connectedOperations.deleteTestSnapshot(snapshotModel.getId());
    connectedOperations.getSnapshotExpectError(snapshotModel.getId(), HttpStatus.NOT_FOUND);
}
Also used : SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 10 with SnapshotRequestModel

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

the class SnapshotConnectedTest method makeSnapshotTestRequest.

private SnapshotRequestModel makeSnapshotTestRequest(DatasetSummaryModel datasetSummaryModel, String resourcePath) throws Exception {
    SnapshotRequestModel snapshotRequest = jsonLoader.loadObject(resourcePath, SnapshotRequestModel.class);
    SnapshotRequestContentsModel content = snapshotRequest.getContents().get(0);
    // TODO SingleDatasetSnapshot
    String newDatasetName = datasetSummaryModel.getName();
    String origDatasetName = content.getDatasetName();
    // swap in the correct dataset name (with the id at the end)
    content.setDatasetName(newDatasetName);
    snapshotRequest.profileId(datasetSummaryModel.getDefaultProfileId());
    if (content.getMode().equals(SnapshotRequestContentsModel.ModeEnum.BYQUERY)) {
        // if its by query, also set swap in the correct dataset name in the query
        String query = content.getQuerySpec().getQuery();
        content.getQuerySpec().setQuery(query.replace(origDatasetName, newDatasetName));
    }
    return snapshotRequest;
}
Also used : SnapshotRequestContentsModel(bio.terra.model.SnapshotRequestContentsModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel)

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