use of org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl in project BridgeServer2 by Sage-Bionetworks.
the class SurveyServiceTest method checkConstraintsBeforePhysicalDelete.
@Test(expectedExceptions = ConstraintViolationException.class, expectedExceptionsMessageRegExp = "Cannot delete survey: it is referenced by a schedule plan that is still accessible through the API")
public void checkConstraintsBeforePhysicalDelete() {
GuidCreatedOnVersionHolder surveyKeys = new GuidCreatedOnVersionHolderImpl(SURVEY_GUID, SURVEY_CREATED_ON.getMillis());
Survey existing = Survey.create();
existing.setPublished(true);
existing.setAppId(TEST_APP_ID);
when(mockSurveyDao.getSurvey(TEST_APP_ID, surveyKeys, false)).thenReturn(existing);
// Now create a schedule that points to this survey
List<SchedulePlan> plans = createSchedulePlanListWithSurveyReference(false);
when(mockSchedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, true)).thenReturn(plans);
service.deleteSurveyPermanently(TEST_APP_ID, surveyKeys);
}
use of org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl in project BridgeServer2 by Sage-Bionetworks.
the class GenericUploadFormatHandlerGetSchemaTest method surveySchemaNotFound.
@Test
public void surveySchemaNotFound() {
// Mock survey service.
Survey survey = Survey.create();
survey.setIdentifier("missing-schema");
survey.setSchemaRevision(SCHEMA_REV);
when(mockSurveyService.getSurvey(TEST_APP_ID, new GuidCreatedOnVersionHolderImpl(SURVEY_GUID, SURVEY_CREATED_ON_MILLIS), false, true)).thenReturn(survey);
// Make info.json.
ObjectNode infoJsonNode = BridgeObjectMapper.get().createObjectNode();
infoJsonNode.put(UploadUtil.FIELD_SURVEY_GUID, SURVEY_GUID);
infoJsonNode.put(UploadUtil.FIELD_SURVEY_CREATED_ON, SURVEY_CREATED_ON_STRING);
// Execute. Returns null.
UploadSchema retVal = handler.getUploadSchema(TEST_APP_ID, infoJsonNode);
assertNull(retVal);
}
use of org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl in project BridgeServer2 by Sage-Bionetworks.
the class GenericUploadFormatHandlerGetSchemaTest method schemaFromSurvey.
@Test
public void schemaFromSurvey() {
// mock survey service
Survey survey = Survey.create();
survey.setIdentifier(SCHEMA_ID);
survey.setSchemaRevision(SCHEMA_REV);
when(mockSurveyService.getSurvey(TEST_APP_ID, new GuidCreatedOnVersionHolderImpl(SURVEY_GUID, SURVEY_CREATED_ON_MILLIS), false, true)).thenReturn(survey);
// make info.json
ObjectNode infoJsonNode = BridgeObjectMapper.get().createObjectNode();
infoJsonNode.put(UploadUtil.FIELD_SURVEY_GUID, SURVEY_GUID);
infoJsonNode.put(UploadUtil.FIELD_SURVEY_CREATED_ON, SURVEY_CREATED_ON_STRING);
// execute and validate
UploadSchema retVal = handler.getUploadSchema(TEST_APP_ID, infoJsonNode);
assertSame(retVal, DUMMY_SCHEMA);
}
use of org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl in project BridgeServer2 by Sage-Bionetworks.
the class SurveyControllerTest method versionSurvey.
// There's no such thing as not being able to create an app from another app. If
// you create a survey, it's in your app.
@Test
public void versionSurvey() throws Exception {
Survey survey = getSurvey(false);
setupContext(TEST_APP_ID, UNCONSENTED, DEVELOPER);
mockRequestBody(mockRequest, survey);
doReturn(session).when(controller).getAuthenticatedSession(DEVELOPER);
when(mockSurveyService.versionSurvey(eq(TEST_APP_ID), any(GuidCreatedOnVersionHolder.class))).thenReturn(survey);
GuidCreatedOnVersionHolder result = controller.versionSurvey(SURVEY_GUID, CREATED_ON.toString());
assertEquals(result.getGuid(), SURVEY_GUID);
assertEquals(result.getCreatedOn(), CREATED_ON.getMillis());
assertEquals(result.getVersion(), SURVEY_VERSION);
GuidCreatedOnVersionHolder keys = new GuidCreatedOnVersionHolderImpl(SURVEY_GUID, CREATED_ON.getMillis());
verify(mockSurveyService).versionSurvey(TEST_APP_ID, keys);
verifyNoMoreInteractions(mockSurveyService);
}
use of org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl in project BridgeServer2 by Sage-Bionetworks.
the class IosSchemaValidationHandler2GetSchemaTest method surveyWithNoSchemaRev.
@Test
public void surveyWithNoSchemaRev() {
// mock survey service
DynamoSurvey survey = new DynamoSurvey();
survey.setIdentifier("test-survey");
SurveyService mockSurveyService = mock(SurveyService.class);
when(mockSurveyService.getSurvey(eq(TEST_APP_ID), eq(new GuidCreatedOnVersionHolderImpl("test-guid", TEST_SURVEY_CREATED_ON_MILLIS)), eq(false), eq(true))).thenReturn(survey);
// set up test handler
IosSchemaValidationHandler2 handler = new IosSchemaValidationHandler2();
handler.setDefaultSchemaRevisionMap(DEFAULT_SCHEMA_REV_MAP);
handler.setSurveyService(mockSurveyService);
// make input
ObjectNode infoJson = BridgeObjectMapper.get().createObjectNode();
infoJson.put("surveyGuid", "test-guid");
infoJson.put("surveyCreatedOn", TEST_SURVEY_CREATED_ON_STRING);
// Execute. Returns null.
UploadSchema retVal = handler.getUploadSchema(TEST_APP_ID, infoJson);
assertNull(retVal);
}
Aggregations