Search in sources :

Example 6 with CohortAnnotationEnumValue

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

the class CohortAnnotationDefinitionDaoTest method save_WithEnumValues.

@Test
public void save_WithEnumValues() throws Exception {
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition();
    CohortAnnotationEnumValue enumValue1 = new CohortAnnotationEnumValue().name("z").order(0).cohortAnnotationDefinition(cohortAnnotationDefinition);
    CohortAnnotationEnumValue enumValue2 = new CohortAnnotationEnumValue().name("r").order(1).cohortAnnotationDefinition(cohortAnnotationDefinition);
    CohortAnnotationEnumValue enumValue3 = new CohortAnnotationEnumValue().name("a").order(2).cohortAnnotationDefinition(cohortAnnotationDefinition);
    cohortAnnotationDefinition.getEnumValues().add(enumValue1);
    cohortAnnotationDefinition.getEnumValues().add(enumValue2);
    cohortAnnotationDefinition.getEnumValues().add(enumValue3);
    cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    String sql = "select count(*) from cohort_annotation_definition where cohort_annotation_definition_id = ?";
    Object[] sqlParams = { cohortAnnotationDefinition.getCohortAnnotationDefinitionId() };
    Integer expectedCount = new Integer("1");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
    sql = "select count(*) from cohort_annotation_enum_value where cohort_annotation_definition_id = ?";
    sqlParams = new Object[] { cohortAnnotationDefinition.getCohortAnnotationDefinitionId() };
    expectedCount = new Integer("3");
    assertEquals(expectedCount, jdbcTemplate.queryForObject(sql, sqlParams, Integer.class));
    List<CohortAnnotationDefinition> cad = cohortAnnotationDefinitionDao.findByCohortId(cohortAnnotationDefinition.getCohortId());
    assertEquals(cohortAnnotationDefinition, cad.get(0));
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

CohortAnnotationEnumValue (org.pmiops.workbench.db.model.CohortAnnotationEnumValue)6 CohortAnnotationDefinition (org.pmiops.workbench.db.model.CohortAnnotationDefinition)4 ParticipantCohortAnnotation (org.pmiops.workbench.db.model.ParticipantCohortAnnotation)3 Date (java.sql.Date)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Test (org.junit.Test)2 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)2 Workspace (org.pmiops.workbench.db.model.Workspace)2 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)2 ParseException (java.text.ParseException)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Provider (javax.inject.Provider)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Before (org.junit.Before)1 GenderRaceEthnicityConcept (org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept)1 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)1 CohortAnnotationDefinitionDao (org.pmiops.workbench.db.dao.CohortAnnotationDefinitionDao)1