Search in sources :

Example 6 with ErrorModel

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

the class DatasetValidationsTest method testArrayPrimaryKeyColumn.

@Test
public void testArrayPrimaryKeyColumn() throws Exception {
    ColumnModel column = new ColumnModel().name("array_column").datatype("string").arrayOf(true);
    TableModel table = new TableModel().name("table").columns(Collections.singletonList(column)).primaryKey(Collections.singletonList(column.getName()));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Collections.singletonList(table)).relationships(Collections.emptyList()).assets(Collections.emptyList());
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "PrimaryKeyArrayColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) ColumnModel(bio.terra.model.ColumnModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ErrorModel

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

the class DatasetValidationsTest method testMissingPrimaryKeyColumn.

@Test
public void testMissingPrimaryKeyColumn() throws Exception {
    TableModel table = new TableModel().name("table").columns(Collections.emptyList()).primaryKey(Collections.singletonList("not_a_column"));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Collections.singletonList(table)).relationships(Collections.emptyList()).assets(Collections.emptyList());
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "MissingPrimaryKeyColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) 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)

Example 8 with ErrorModel

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

the class DatasetValidationsTest method expectBadDatasetCreateRequest.

private ErrorModel expectBadDatasetCreateRequest(DatasetRequestModel datasetRequest) throws Exception {
    MvcResult result = mvc.perform(post("/api/repository/v1/datasets").contentType(MediaType.APPLICATION_JSON).content(TestUtils.mapToJson(datasetRequest))).andExpect(status().is4xxClientError()).andReturn();
    MockHttpServletResponse response = result.getResponse();
    String responseBody = response.getContentAsString();
    assertTrue("Error model was returned on failure", StringUtils.contains(responseBody, "message"));
    ErrorModel errorModel = TestUtils.mapFromJson(responseBody, ErrorModel.class);
    return errorModel;
}
Also used : ErrorModel(bio.terra.model.ErrorModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 9 with ErrorModel

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

the class DatasetValidationsTest method testDuplicateTableNames.

@Test
public void testDuplicateTableNames() throws Exception {
    ColumnModel column = new ColumnModel().name("id").datatype("string");
    TableModel table = new TableModel().name("duplicate").columns(Collections.singletonList(column));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().tables(Arrays.asList(table, table));
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "DuplicateTableNames", "InvalidRelationshipTermTableColumn", "InvalidRelationshipTermTableColumn", "InvalidAssetTable", "InvalidAssetTableColumn", "InvalidAssetTableColumn", "InvalidRootColumn" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) ColumnModel(bio.terra.model.ColumnModel) TableModel(bio.terra.model.TableModel) AssetTableModel(bio.terra.model.AssetTableModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ErrorModel

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

the class DatasetValidationsTest method testNoRootTable.

@Test
public void testNoRootTable() throws Exception {
    AssetModel noRoot = new AssetModel().name("bad").tables(Collections.singletonList(buildAssetParticipantTable())).follow(Collections.singletonList("participant_sample"));
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().assets(Collections.singletonList(noRoot));
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "NotNull", "NotNull", "NoRootTable" });
}
Also used : DatasetRequestModel(bio.terra.model.DatasetRequestModel) ErrorModel(bio.terra.model.ErrorModel) AssetModel(bio.terra.model.AssetModel) 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