Search in sources :

Example 1 with UploadSchemaService

use of org.sagebionetworks.bridge.services.UploadSchemaService in project BridgeServer2 by Sage-Bionetworks.

the class GenericUploadFormatHandlerGetSchemaTest method setup.

@BeforeMethod
public void setup() {
    UploadSchemaService mockSchemaService = mock(UploadSchemaService.class);
    when(mockSchemaService.getUploadSchemaByIdAndRevNoThrow(TEST_APP_ID, SCHEMA_ID, SCHEMA_REV)).thenReturn(DUMMY_SCHEMA);
    mockSurveyService = mock(SurveyService.class);
    handler = new GenericUploadFormatHandler();
    handler.setSurveyService(mockSurveyService);
    handler.setUploadSchemaService(mockSchemaService);
}
Also used : UploadSchemaService(org.sagebionetworks.bridge.services.UploadSchemaService) SurveyService(org.sagebionetworks.bridge.services.SurveyService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with UploadSchemaService

use of org.sagebionetworks.bridge.services.UploadSchemaService in project BridgeServer2 by Sage-Bionetworks.

the class IosSchemaValidationHandler2Test method setup.

@BeforeMethod
public void setup() {
    DateTimeUtils.setCurrentMillisFixed(MOCK_NOW.getMillis());
    // set up common params for test context
    // For upload, we need uploadId, healthCode, and uploadDate
    DynamoUpload2 upload = new DynamoUpload2();
    upload.setUploadId(TEST_UPLOAD_ID);
    upload.setHealthCode(TEST_HEALTHCODE);
    upload.setUploadDate(LocalDate.parse(TEST_UPLOAD_DATE_STRING));
    // Create health data record with a blank data map.
    HealthDataRecord record = HealthDataRecord.create();
    record.setData(BridgeObjectMapper.get().createObjectNode());
    context = new UploadValidationContext();
    context.setAppId(TEST_APP_ID);
    context.setUpload(upload);
    context.setHealthDataRecord(record);
    // Init fileHelper and tmpDir
    inMemoryFileHelper = new InMemoryFileHelper();
    tmpDir = inMemoryFileHelper.createTempDir();
    // set up test schemas
    // To test backwards compatibility, survey schema should include both the old style fields and the new
    // "answers" field.
    UploadSchema surveySchema = UploadSchema.create();
    surveySchema.setAppId(TEST_APP_ID);
    surveySchema.setSchemaId("test-survey");
    surveySchema.setRevision(1);
    surveySchema.setName("iOS Survey");
    surveySchema.setSchemaType(UploadSchemaType.IOS_SURVEY);
    surveySchema.setFieldDefinitions(ImmutableList.of(UploadUtil.ANSWERS_FIELD_DEF, new UploadFieldDefinition.Builder().withName("foo").withType(UploadFieldType.STRING).build(), new UploadFieldDefinition.Builder().withName("bar").withType(UploadFieldType.INT).build(), new UploadFieldDefinition.Builder().withName("bar_unit").withType(UploadFieldType.STRING).build(), new UploadFieldDefinition.Builder().withName("baz").withType(UploadFieldType.ATTACHMENT_JSON_BLOB).build(), new UploadFieldDefinition.Builder().withName("calendar-date").withType(UploadFieldType.CALENDAR_DATE).build(), new UploadFieldDefinition.Builder().withName("time-without-date").withType(UploadFieldType.TIME_V2).build(), new UploadFieldDefinition.Builder().withName("legacy-date-time").withType(UploadFieldType.TIMESTAMP).build(), new UploadFieldDefinition.Builder().withName("new-date-time").withType(UploadFieldType.TIMESTAMP).build(), new UploadFieldDefinition.Builder().withName("int-as-string").withType(UploadFieldType.STRING).build(), new UploadFieldDefinition.Builder().withName("timestamp-as-date").withType(UploadFieldType.CALENDAR_DATE).build(), new UploadFieldDefinition.Builder().withName("inline-json-blob").withType(UploadFieldType.INLINE_JSON_BLOB).build(), new UploadFieldDefinition.Builder().withName("optional").withRequired(false).withType(UploadFieldType.STRING).build(), new UploadFieldDefinition.Builder().withName("optional_attachment").withRequired(false).withType(UploadFieldType.ATTACHMENT_JSON_BLOB).build()));
    UploadSchema nonSurveySchema = UploadSchema.create();
    nonSurveySchema.setAppId(TEST_APP_ID);
    nonSurveySchema.setSchemaId("non-survey");
    nonSurveySchema.setRevision(1);
    nonSurveySchema.setName("Non-Survey");
    nonSurveySchema.setSchemaType(UploadSchemaType.IOS_DATA);
    nonSurveySchema.setFieldDefinitions(ImmutableList.of(new UploadFieldDefinition.Builder().withName("sanitize____attachment.txt").withType(UploadFieldType.ATTACHMENT_V2).withFileExtension(".txt").withMimeType("text/plain").build()));
    // mock upload schema service
    UploadSchemaService mockSchemaService = mock(UploadSchemaService.class);
    when(mockSchemaService.getUploadSchemaByIdAndRevNoThrow(TEST_APP_ID, "test-survey", 1)).thenReturn(surveySchema);
    when(mockSchemaService.getUploadSchemaByIdAndRevNoThrow(TEST_APP_ID, "non-survey", 1)).thenReturn(nonSurveySchema);
    // mock upload file helper
    mockUploadFileHelper = mock(UploadFileHelper.class);
    // set up handler
    handler = new IosSchemaValidationHandler2();
    handler.setDefaultSchemaRevisionMap(DEFAULT_SCHEMA_REV_MAP);
    handler.setFileHelper(inMemoryFileHelper);
    handler.setUploadSchemaService(mockSchemaService);
    handler.setUploadFileHelper(mockUploadFileHelper);
}
Also used : UploadFieldDefinition(org.sagebionetworks.bridge.models.upload.UploadFieldDefinition) InMemoryFileHelper(org.sagebionetworks.bridge.file.InMemoryFileHelper) UploadSchemaService(org.sagebionetworks.bridge.services.UploadSchemaService) HealthDataRecord(org.sagebionetworks.bridge.models.healthdata.HealthDataRecord) UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with UploadSchemaService

use of org.sagebionetworks.bridge.services.UploadSchemaService in project BridgeServer2 by Sage-Bionetworks.

the class StrictValidationHandlerTest method schemaless.

@Test
public void schemaless() throws Exception {
    // Set up mocks.
    AppService mockAppService = mock(AppService.class);
    UploadSchemaService mockUploadSchemaService = mock(UploadSchemaService.class);
    handler.setAppService(mockAppService);
    handler.setUploadSchemaService(mockUploadSchemaService);
    // Create record with no schema.
    HealthDataRecord record = HealthDataRecord.create();
    record.setData(BridgeObjectMapper.get().createObjectNode());
    record.setSchemaId(null);
    record.setSchemaRevision(null);
    context.setHealthDataRecord(record);
    // Execute. No error messages.
    handler.handle(context);
    assertTrue(context.getMessageList().isEmpty());
    // We don't ever use the dependent services.
    verifyZeroInteractions(mockAppService, mockUploadSchemaService);
}
Also used : AppService(org.sagebionetworks.bridge.services.AppService) UploadSchemaService(org.sagebionetworks.bridge.services.UploadSchemaService) HealthDataRecord(org.sagebionetworks.bridge.models.healthdata.HealthDataRecord) Test(org.testng.annotations.Test)

Example 4 with UploadSchemaService

use of org.sagebionetworks.bridge.services.UploadSchemaService in project BridgeServer2 by Sage-Bionetworks.

the class IosSchemaValidationHandler2GetSchemaTest method itemWithLegacyMapRev.

@Test
public void itemWithLegacyMapRev() {
    // mock upload schema service
    UploadSchema dummySchema = UploadSchema.create();
    UploadSchemaService mockSchemaSvc = mock(UploadSchemaService.class);
    when(mockSchemaSvc.getUploadSchemaByIdAndRevNoThrow(TEST_APP_ID, "schema-rev-test", 2)).thenReturn(dummySchema);
    // set up test handler
    IosSchemaValidationHandler2 handler = new IosSchemaValidationHandler2();
    handler.setDefaultSchemaRevisionMap(DEFAULT_SCHEMA_REV_MAP);
    handler.setUploadSchemaService(mockSchemaSvc);
    // make input
    ObjectNode infoJson = BridgeObjectMapper.get().createObjectNode();
    infoJson.put("item", "schema-rev-test");
    // execute and validate
    UploadSchema retVal = handler.getUploadSchema(TEST_APP_ID, infoJson);
    assertSame(retVal, dummySchema);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UploadSchemaService(org.sagebionetworks.bridge.services.UploadSchemaService) UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) Test(org.testng.annotations.Test)

Example 5 with UploadSchemaService

use of org.sagebionetworks.bridge.services.UploadSchemaService in project BridgeServer2 by Sage-Bionetworks.

the class IosSchemaValidationHandler2GetSchemaTest method fallbackToIdentifier.

@Test
public void fallbackToIdentifier() {
    // mock upload schema service
    UploadSchema dummySchema = UploadSchema.create();
    UploadSchemaService mockSchemaSvc = mock(UploadSchemaService.class);
    when(mockSchemaSvc.getUploadSchemaByIdAndRevNoThrow(TEST_APP_ID, "test-schema", 1)).thenReturn(dummySchema);
    // set up test handler
    IosSchemaValidationHandler2 handler = new IosSchemaValidationHandler2();
    handler.setDefaultSchemaRevisionMap(DEFAULT_SCHEMA_REV_MAP);
    handler.setUploadSchemaService(mockSchemaSvc);
    // make input
    ObjectNode infoJson = BridgeObjectMapper.get().createObjectNode();
    infoJson.put("identifier", "test-schema");
    // execute and validate
    UploadSchema retVal = handler.getUploadSchema(TEST_APP_ID, infoJson);
    assertSame(retVal, dummySchema);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UploadSchemaService(org.sagebionetworks.bridge.services.UploadSchemaService) UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) Test(org.testng.annotations.Test)

Aggregations

UploadSchemaService (org.sagebionetworks.bridge.services.UploadSchemaService)26 Test (org.testng.annotations.Test)22 UploadSchema (org.sagebionetworks.bridge.models.upload.UploadSchema)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 HealthDataRecord (org.sagebionetworks.bridge.models.healthdata.HealthDataRecord)3 AppService (org.sagebionetworks.bridge.services.AppService)3 SurveyService (org.sagebionetworks.bridge.services.SurveyService)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 GuidCreatedOnVersionHolderImpl (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl)2 UploadFieldDefinition (org.sagebionetworks.bridge.models.upload.UploadFieldDefinition)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DigestUtils (org.apache.commons.codec.digest.DigestUtils)1 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)1