use of org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method getSurveyExcludeElements.
@Test
public void getSurveyExcludeElements() {
DynamoSurvey survey = new DynamoSurvey();
mockSurveyMapper(survey);
// There is a question that should be retrieved.
DynamoSurveyQuestion element = new DynamoSurveyQuestion();
element.setType(SurveyElementConstants.SURVEY_QUESTION_TYPE);
element.setUiHint(UIHint.BLOODPRESSURE);
element.setConstraints(new BloodPressureConstraints());
when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of(element));
Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_KEY, false);
assertSame(result, survey);
assertEquals(result.getElements().size(), 0);
verify(mockSurveyElementMapper, never()).queryPage(eq(DynamoSurveyElement.class), any());
}
use of org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method constraintRulesShiftedToQuestionAfterRules.
@Test
public void constraintRulesShiftedToQuestionAfterRules() {
DynamoSurvey survey = new DynamoSurvey();
mockSurveyMapper(survey);
// This needs to be shifted to the after rules of the question itself
BloodPressureConstraints constraints = new BloodPressureConstraints();
constraints.getRules().add(new SurveyRule.Builder().withEndSurvey(true).build());
SurveyQuestion question = new DynamoSurveyQuestion();
question.setUiHint(UIHint.BLOODPRESSURE);
question.setType(SURVEY_QUESTION_TYPE);
question.setConstraints(constraints);
when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of((DynamoSurveyElement) question));
Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_KEY, true);
SurveyQuestion resultQuestion = result.getUnmodifiableQuestionList().get(0);
SurveyRule rule = resultQuestion.getAfterRules().get(0);
assertTrue(rule.getEndSurvey());
}
use of org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints in project BridgeServer2 by Sage-Bionetworks.
the class SurveyServiceTest method updateSurveyValidatesDataGroups.
@Test
public void updateSurveyValidatesDataGroups() {
app.setDataGroups(ImmutableSet.of("groupA", "groupB", "groupC"));
Survey existing = Survey.create();
existing.setAppId(TEST_APP_ID);
when(mockSurveyDao.getSurvey(any(), any(), eq(false))).thenReturn(existing);
when(mockSurveyDao.getSurvey(any(), any(), eq(true))).thenReturn(existing);
Survey update = Survey.create();
update.setIdentifier("surveyIdentifier");
update.setName("This is a survey name");
update.setGuid(BridgeUtils.generateGuid());
update.setAppId(TEST_APP_ID);
// Create a data group rule that includes invalid data groups
SurveyRule rule = new SurveyRule.Builder().withDataGroups(ImmutableSet.of("groupB", "groupdD")).withOperator(Operator.ALL).withEndSurvey(true).build();
SurveyQuestion element = new DynamoSurveyQuestion();
element.setIdentifier("anIdentifier");
element.setPrompt("This is a prompt.");
element.setConstraints(new BloodPressureConstraints());
element.setUiHint(UIHint.BLOODPRESSURE);
element.setAfterRules(ImmutableList.of(rule));
update.setElements(ImmutableList.of(element));
try {
service.updateSurvey(TEST_APP_ID, update);
fail("Should have thrown an exception");
} catch (InvalidEntityException e) {
assertEquals(e.getErrors().get("elements[0].afterRules[0].dataGroups").get(0), "elements[0].afterRules[0].dataGroups contains data groups 'groupB, groupdD' " + "that are not valid data groups: groupA, groupB, groupC");
}
}
use of org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method constraintRulesOnQuestionOverwriteConstraintRules.
@Test
public void constraintRulesOnQuestionOverwriteConstraintRules() {
DynamoSurvey survey = new DynamoSurvey();
mockSurveyMapper(survey);
// This needs to be shifted to the after rules of the question itself
BloodPressureConstraints constraints = new BloodPressureConstraints();
// This does not have endSurvey as a rule, but it will be replaced
constraints.getRules().add(new SurveyRule.Builder().build());
SurveyQuestion question = new DynamoSurveyQuestion();
question.setAfterRules(ImmutableList.of(new SurveyRule.Builder().withEndSurvey(true).build()));
question.setUiHint(UIHint.BLOODPRESSURE);
question.setType(SURVEY_QUESTION_TYPE);
question.setConstraints(constraints);
when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of((DynamoSurveyElement) question));
Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_KEY, true);
SurveyQuestion resultQuestion = result.getUnmodifiableQuestionList().get(0);
SurveyRule rule = resultQuestion.getConstraints().getRules().get(0);
assertTrue(rule.getEndSurvey());
}
use of org.sagebionetworks.bridge.models.surveys.BloodPressureConstraints in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method getSurveyIncludeElementsByIdentifer.
@Test
public void getSurveyIncludeElementsByIdentifer() {
DynamoSurvey survey = new DynamoSurvey();
survey.setAppId(TEST_APP_ID);
survey.setGuid(GUID);
survey.setIdentifier(SURVEY_ID);
survey.setCreatedOn(CREATED_ON);
mockSurveyMapper(survey);
// There is a question that should be retrieved.
DynamoSurveyQuestion element = new DynamoSurveyQuestion();
element.setType(SurveyElementConstants.SURVEY_QUESTION_TYPE);
element.setUiHint(UIHint.BLOODPRESSURE);
element.setConstraints(new BloodPressureConstraints());
when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of(element));
Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_IDENTIFIER_KEYS, true);
assertSame(result, survey);
assertEquals(result.getElements().size(), 1);
verify(mockSurveyMapper).queryPage(eq(DynamoSurvey.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoSurvey> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getAppId(), TEST_APP_ID);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("identifier");
assertEquals(rangeKeyCondition.getComparisonOperator(), EQ.name());
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getS(), SURVEY_ID);
assertEquals(query.getQueryFilter().size(), 1);
verifyCreatedOnQueryCondition(query);
verify(mockSurveyElementMapper).queryPage(eq(DynamoSurveyElement.class), elementQueryCaptor.capture());
DynamoDBQueryExpression<DynamoSurveyElement> elementQuery = elementQueryCaptor.getValue();
assertEquals(elementQuery.getHashKeyValues().getSurveyCompoundKey(), GUID + ":" + CREATED_ON);
}
Aggregations