use of org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentConfigServiceTest method updateAssessmentConfigInvalid.
@Test(expectedExceptions = InvalidEntityException.class, expectedExceptionsMessageRegExp = ".*config is required.*")
public void updateAssessmentConfigInvalid() {
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(STUDY_DESIGNER)).withCallerOrgMembership(TEST_OWNER_ID).build());
Assessment assessment = AssessmentTest.createAssessment();
assessment.setOriginGuid(GUID);
when(mockAssessmentService.getAssessmentByGuid(TEST_APP_ID, TEST_OWNER_ID, GUID)).thenReturn(assessment);
AssessmentConfig existing = new AssessmentConfig();
existing.setCreatedOn(CREATED_ON);
when(mockDao.getAssessmentConfig(GUID)).thenReturn(Optional.of(existing));
AssessmentConfig config = new AssessmentConfig();
config.setConfig(null);
config.setVersion(3L);
service.updateAssessmentConfig(TEST_APP_ID, TEST_OWNER_ID, GUID, config);
}
use of org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentConfigServiceTest method getSharedAssessmentConfig.
@Test
public void getSharedAssessmentConfig() {
AssessmentConfig existing = new AssessmentConfig();
when(mockDao.getAssessmentConfig(GUID)).thenReturn(Optional.of(existing));
AssessmentConfig retValue = service.getSharedAssessmentConfig(TEST_APP_ID, GUID);
assertSame(retValue, existing);
verify(mockDao).getAssessmentConfig(GUID);
}
use of org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentConfigServiceTest method customizeAssessmentConfigInvalid.
@Test(expectedExceptions = InvalidEntityException.class, expectedExceptionsMessageRegExp = ".*identifier is missing.*")
public void customizeAssessmentConfigInvalid() {
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(STUDY_DESIGNER)).withCallerOrgMembership(TEST_OWNER_ID).build());
AssessmentConfigValidator val = new AssessmentConfigValidator.Builder().addValidator("*", new AbstractValidator() {
public void validate(Object target, Errors errors) {
JsonNode node = (JsonNode) target;
if (!node.has("identifier")) {
errors.reject("identifier is missing");
}
}
}).build();
doReturn(val).when(service).getValidator();
Assessment assessment = AssessmentTest.createAssessment();
assessment.setOwnerId(TEST_OWNER_ID);
assessment.setCustomizationFields(ImmutableMap.of("anIdentifier", ImmutableSet.of(new PropertyInfo.Builder().withPropName("stringValue").build(), new PropertyInfo.Builder().withPropName("intValue").build(), new PropertyInfo.Builder().withPropName("identifier").build())));
when(mockAssessmentService.getAssessmentByGuid(TEST_APP_ID, TEST_OWNER_ID, GUID)).thenReturn(assessment);
AssessmentConfig existing = new AssessmentConfig();
existing.setConfig(createValidConfig());
when(mockDao.getAssessmentConfig(GUID)).thenReturn(Optional.of(existing));
when(mockDao.customizeAssessmentConfig(GUID, existing)).thenReturn(existing);
Map<String, Map<String, JsonNode>> updates = new HashMap<>();
HashMap<String, JsonNode> nodeUpdates = new HashMap<>();
// Note that we need to persist this kind of null and we generally don't
// with our default serialization. But the controller for this customization call
// uses a differently configured ObjectMapper to persist these.
nodeUpdates.put("identifier", null);
updates.put("anIdentifier", nodeUpdates);
service.customizeAssessmentConfig(TEST_APP_ID, TEST_OWNER_ID, GUID, updates);
}
use of org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentConfigServiceTest method customizeAssessmentConfigUnchanged.
@Test
public void customizeAssessmentConfigUnchanged() {
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(STUDY_DESIGNER)).withCallerOrgMembership(TEST_OWNER_ID).build());
Assessment assessment = AssessmentTest.createAssessment();
assessment.setOwnerId(TEST_OWNER_ID);
assessment.setCustomizationFields(ImmutableMap.of("anIdentifier", ImmutableSet.of(new PropertyInfo.Builder().withPropName("stringValue").build())));
when(mockAssessmentService.getAssessmentByGuid(TEST_APP_ID, TEST_OWNER_ID, GUID)).thenReturn(assessment);
AssessmentConfig existing = new AssessmentConfig();
existing.setConfig(createValidConfig());
when(mockDao.getAssessmentConfig(GUID)).thenReturn(Optional.of(existing));
Map<String, Map<String, JsonNode>> updates = new HashMap<>();
updates.put("anIdentifier", ImmutableMap.of("booleanFlag", JsonNodeFactory.instance.booleanNode(false), "intValue", JsonNodeFactory.instance.numberNode(10)));
updates.put("nonExistentIdentifier", ImmutableMap.of("stringValue", JsonNodeFactory.instance.textNode("some value")));
AssessmentConfig retValue = service.customizeAssessmentConfig(TEST_APP_ID, TEST_OWNER_ID, GUID, updates);
assertSame(retValue, existing);
verify(mockDao, never()).customizeAssessmentConfig(any(), any());
}
use of org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentConfigServiceTest method customizeAssessmentConfig.
@Test
public void customizeAssessmentConfig() {
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(STUDY_DESIGNER)).withCallerOrgMembership(TEST_OWNER_ID).build());
Assessment assessment = AssessmentTest.createAssessment();
assessment.setOwnerId(TEST_OWNER_ID);
assessment.setCustomizationFields(ImmutableMap.of("anIdentifier", ImmutableSet.of(new PropertyInfo.Builder().withPropName("stringValue").build(), new PropertyInfo.Builder().withPropName("intValue").build(), new PropertyInfo.Builder().withPropName("identifier").build())));
when(mockAssessmentService.getAssessmentByGuid(TEST_APP_ID, TEST_OWNER_ID, GUID)).thenReturn(assessment);
AssessmentConfig existing = new AssessmentConfig();
existing.setConfig(createValidConfig());
when(mockDao.getAssessmentConfig(GUID)).thenReturn(Optional.of(existing));
when(mockDao.customizeAssessmentConfig(GUID, existing)).thenReturn(existing);
Map<String, Map<String, JsonNode>> updates = new HashMap<>();
updates.put("anIdentifier", ImmutableMap.of("stringValue", JsonNodeFactory.instance.textNode("updatedValue"), "booleanFlag", JsonNodeFactory.instance.booleanNode(false), "intValue", JsonNodeFactory.instance.numberNode(10)));
AssessmentConfig retValue = service.customizeAssessmentConfig(TEST_APP_ID, TEST_OWNER_ID, GUID, updates);
assertSame(retValue, existing);
// Not changed... it's not in the list of allowable fields to customize.
assertTrue(existing.getConfig().get("booleanFlag").booleanValue());
// Changed because it's allowable
assertEquals(existing.getConfig().get("stringValue").textValue(), "updatedValue");
assertEquals(existing.getConfig().get("intValue").intValue(), 10);
// Unchanged because no update was submitted
assertEquals(existing.getConfig().get("identifier").textValue(), "anIdentifier");
assertEquals(assessment.getModifiedOn(), MODIFIED_ON);
}
Aggregations