Search in sources :

Example 1 with AssessmentConfig

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);
}
Also used : AssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig) Assessment(org.sagebionetworks.bridge.models.assessments.Assessment) Test(org.testng.annotations.Test) AssessmentTest(org.sagebionetworks.bridge.models.assessments.AssessmentTest)

Example 2 with AssessmentConfig

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);
}
Also used : AssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig) Test(org.testng.annotations.Test) AssessmentTest(org.sagebionetworks.bridge.models.assessments.AssessmentTest)

Example 3 with AssessmentConfig

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);
}
Also used : AssessmentConfigValidator(org.sagebionetworks.bridge.validators.AssessmentConfigValidator) AbstractValidator(org.sagebionetworks.bridge.validators.AbstractValidator) HashMap(java.util.HashMap) Assessment(org.sagebionetworks.bridge.models.assessments.Assessment) JsonNode(com.fasterxml.jackson.databind.JsonNode) AssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig) Errors(org.springframework.validation.Errors) PropertyInfo(org.sagebionetworks.bridge.models.assessments.config.PropertyInfo) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test) AssessmentTest(org.sagebionetworks.bridge.models.assessments.AssessmentTest)

Example 4 with AssessmentConfig

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());
}
Also used : AssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig) HashMap(java.util.HashMap) Assessment(org.sagebionetworks.bridge.models.assessments.Assessment) PropertyInfo(org.sagebionetworks.bridge.models.assessments.config.PropertyInfo) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test) AssessmentTest(org.sagebionetworks.bridge.models.assessments.AssessmentTest)

Example 5 with AssessmentConfig

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);
}
Also used : AssessmentConfig(org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig) HashMap(java.util.HashMap) Assessment(org.sagebionetworks.bridge.models.assessments.Assessment) PropertyInfo(org.sagebionetworks.bridge.models.assessments.config.PropertyInfo) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test) AssessmentTest(org.sagebionetworks.bridge.models.assessments.AssessmentTest)

Aggregations

AssessmentConfig (org.sagebionetworks.bridge.models.assessments.config.AssessmentConfig)40 Test (org.testng.annotations.Test)32 Assessment (org.sagebionetworks.bridge.models.assessments.Assessment)22 AssessmentTest (org.sagebionetworks.bridge.models.assessments.AssessmentTest)18 HibernateAssessmentConfig (org.sagebionetworks.bridge.models.assessments.config.HibernateAssessmentConfig)8 HibernateAssessment (org.sagebionetworks.bridge.models.assessments.HibernateAssessment)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)3 PropertyInfo (org.sagebionetworks.bridge.models.assessments.config.PropertyInfo)3 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)2 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)2 Errors (org.springframework.validation.Errors)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Set (java.util.Set)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 SessionFactory (org.hibernate.SessionFactory)1 DateTime (org.joda.time.DateTime)1