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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations