Search in sources :

Example 1 with GuidCreatedOnVersionHolderImpl

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);
}
Also used : GuidCreatedOnVersionHolderImpl(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl) TestSurvey(org.sagebionetworks.bridge.models.surveys.TestSurvey) Survey(org.sagebionetworks.bridge.models.surveys.Survey) DynamoSurvey(org.sagebionetworks.bridge.dynamodb.DynamoSurvey) GuidCreatedOnVersionHolder(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolder) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) Test(org.testng.annotations.Test)

Example 2 with GuidCreatedOnVersionHolderImpl

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);
}
Also used : GuidCreatedOnVersionHolderImpl(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl) Survey(org.sagebionetworks.bridge.models.surveys.Survey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) Test(org.testng.annotations.Test)

Example 3 with GuidCreatedOnVersionHolderImpl

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);
}
Also used : GuidCreatedOnVersionHolderImpl(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl) Survey(org.sagebionetworks.bridge.models.surveys.Survey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) Test(org.testng.annotations.Test)

Example 4 with GuidCreatedOnVersionHolderImpl

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);
}
Also used : GuidCreatedOnVersionHolderImpl(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl) TestSurvey(org.sagebionetworks.bridge.TestSurvey) Survey(org.sagebionetworks.bridge.models.surveys.Survey) DynamoSurvey(org.sagebionetworks.bridge.dynamodb.DynamoSurvey) GuidCreatedOnVersionHolder(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolder) Test(org.testng.annotations.Test)

Example 5 with GuidCreatedOnVersionHolderImpl

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);
}
Also used : GuidCreatedOnVersionHolderImpl(org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DynamoSurvey(org.sagebionetworks.bridge.dynamodb.DynamoSurvey) UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) SurveyService(org.sagebionetworks.bridge.services.SurveyService) Test(org.testng.annotations.Test)

Aggregations

GuidCreatedOnVersionHolderImpl (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl)29 Survey (org.sagebionetworks.bridge.models.surveys.Survey)18 GuidCreatedOnVersionHolder (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolder)16 Test (org.testng.annotations.Test)13 UploadSchema (org.sagebionetworks.bridge.models.upload.UploadSchema)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 DynamoSurvey (org.sagebionetworks.bridge.dynamodb.DynamoSurvey)6 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)5 SurveyService (org.sagebionetworks.bridge.services.SurveyService)5 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)3 SurveyReference (org.sagebionetworks.bridge.models.schedules.SurveyReference)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 HealthDataRecord (org.sagebionetworks.bridge.models.healthdata.HealthDataRecord)2 SharedModuleType (org.sagebionetworks.bridge.models.sharedmodules.SharedModuleType)2 UploadSchemaService (org.sagebionetworks.bridge.services.UploadSchemaService)2 UploadValidationContext (org.sagebionetworks.bridge.upload.UploadValidationContext)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 InputStream (java.io.InputStream)1