Search in sources :

Example 6 with Cohort

use of org.pmiops.workbench.model.Cohort in project workbench by all-of-us.

the class CohortsControllerTest method testMaterializeCohortWithSpec.

@Test
public void testMaterializeCohortWithSpec() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortSpec(cohort.getCriteria());
    MaterializeCohortResponse response = new MaterializeCohortResponse();
    when(cohortMaterializationService.materializeCohort(null, searchRequest, request)).thenReturn(response);
    assertThat(cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request).getBody()).isEqualTo(response);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 7 with Cohort

use of org.pmiops.workbench.model.Cohort in project workbench by all-of-us.

the class CohortsControllerTest method testUpdateCohortStaleThrows.

@Test(expected = ConflictException.class)
public void testUpdateCohortStaleThrows() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    cohortsController.updateCohort(workspace.getNamespace(), workspace.getId(), cohort.getId(), new Cohort().name("updated-name").etag(cohort.getEtag())).getBody();
    // Still using the initial etag.
    cohortsController.updateCohort(workspace.getNamespace(), workspace.getId(), cohort.getId(), new Cohort().name("updated-name2").etag(cohort.getEtag())).getBody();
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 8 with Cohort

use of org.pmiops.workbench.model.Cohort in project workbench by all-of-us.

the class CohortsControllerTest method testMaterializeCohortCohortNotFound.

@Test(expected = NotFoundException.class)
public void testMaterializeCohortCohortNotFound() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortName("badCohort");
    cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 9 with Cohort

use of org.pmiops.workbench.model.Cohort in project workbench by all-of-us.

the class CohortsControllerTest method testMaterializeCohortPageSizeTooLarge.

public void testMaterializeCohortPageSizeTooLarge() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    request.setPageSize(CohortsController.MAX_PAGE_SIZE + 1);
    MaterializeCohortRequest adjustedRequest = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    request.setPageSize(CohortsController.MAX_PAGE_SIZE);
    MaterializeCohortResponse response = new MaterializeCohortResponse();
    when(cohortMaterializationService.materializeCohort(null, searchRequest, adjustedRequest)).thenReturn(response);
    assertThat(cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request).getBody()).isEqualTo(response);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse)

Example 10 with Cohort

use of org.pmiops.workbench.model.Cohort in project workbench by all-of-us.

the class CohortsControllerTest method testMaterializeCohortPageSizeTooSmall.

@Test(expected = BadRequestException.class)
public void testMaterializeCohortPageSizeTooSmall() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    request.setPageSize(-1);
    cohortsController.materializeCohort(WORKSPACE_NAMESPACE, WORKSPACE_NAME, request);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Aggregations

Cohort (org.pmiops.workbench.model.Cohort)19 Test (org.junit.Test)15 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)15 MaterializeCohortRequest (org.pmiops.workbench.model.MaterializeCohortRequest)12 MaterializeCohortResponse (org.pmiops.workbench.model.MaterializeCohortResponse)6 Gson (com.google.gson.Gson)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)2 FieldValue (com.google.cloud.bigquery.FieldValue)1 QueryResult (com.google.cloud.bigquery.QueryResult)1 Blob (com.google.cloud.storage.Blob)1 BlobId (com.google.cloud.storage.BlobId)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 Timestamp (java.sql.Timestamp)1