Search in sources :

Example 1 with InvalidEntityException

use of org.sagebionetworks.bridge.exceptions.InvalidEntityException in project BridgeServer2 by Sage-Bionetworks.

the class MasterSchedulerServiceTest method testCreateSchedulerConfigValidates.

@Test
public void testCreateSchedulerConfigValidates() {
    MasterSchedulerConfig mockConfig = TestUtils.getMasterSchedulerConfig();
    mockConfig.setScheduleId(null);
    try {
        schedulerService.createSchedulerConfig(mockConfig);
        fail("expected exception");
    } catch (InvalidEntityException ex) {
    // expected exception
    }
    verify(configDao, never()).createSchedulerConfig(any());
}
Also used : MasterSchedulerConfig(org.sagebionetworks.bridge.models.schedules.MasterSchedulerConfig) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Example 2 with InvalidEntityException

use of org.sagebionetworks.bridge.exceptions.InvalidEntityException in project BridgeServer2 by Sage-Bionetworks.

the class ConsentServiceTest method noConsentIfTooYoung.

@Test
public void noConsentIfTooYoung() {
    ConsentSignature consentSignature = new ConsentSignature.Builder().withConsentSignature(CONSENT_SIGNATURE).withBirthdate("2018-05-12").build();
    try {
        consentService.consentToResearch(app, SUBPOP_GUID, PARTICIPANT, consentSignature, SharingScope.NO_SHARING, false);
        fail("Exception expected.");
    } catch (InvalidEntityException e) {
        verifyNoMoreInteractions(accountService);
    }
}
Also used : ConsentSignature(org.sagebionetworks.bridge.models.subpopulations.ConsentSignature) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Example 3 with InvalidEntityException

use of org.sagebionetworks.bridge.exceptions.InvalidEntityException in project BridgeServer2 by Sage-Bionetworks.

the class StudyParticipantValidatorTest method validatesUpdate.

// Password, email address, and externalId (if being validated) cannot be updated, so these don't need to be validated.
@Test
public void validatesUpdate() {
    validator = makeValidator(false);
    Map<String, String> attrs = Maps.newHashMap();
    attrs.put("badValue", "value");
    StudyParticipant participant = new StudyParticipant.Builder().withDataGroups(Sets.newHashSet("badGroup")).withAttributes(attrs).withPassword("bad").build();
    try {
        Validate.entityThrowingException(validator, participant);
    } catch (InvalidEntityException e) {
        assertNull(e.getErrors().get("email"));
        assertNull(e.getErrors().get("externalId"));
        assertNull(e.getErrors().get("password"));
    }
    assertValidatorMessage(validator, participant, "dataGroups", "'badGroup' is not defined for app (use group1, group2, bluebell)");
    assertValidatorMessage(validator, participant, "attributes", "'badValue' is not defined for app (use attr1, attr2, phone)");
}
Also used : StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Example 4 with InvalidEntityException

use of org.sagebionetworks.bridge.exceptions.InvalidEntityException in project BridgeServer2 by Sage-Bionetworks.

the class SubpopulationValidatorTest method testValidation.

@Test
public void testValidation() {
    Subpopulation subpop = Subpopulation.create();
    Criteria criteria = TestUtils.createCriteria(-10, -2, null, ImmutableSet.of("wrongGroup"));
    criteria.setAllOfStudyIds(ImmutableSet.of("studyC"));
    criteria.setNoneOfStudyIds(ImmutableSet.of("studyD"));
    subpop.setCriteria(criteria);
    subpop.setDataGroupsAssignedWhileConsented(ImmutableSet.of("group1", "dataGroup3"));
    subpop.setStudyIdsAssignedOnConsent(ImmutableSet.of("studyC"));
    try {
        Validate.entityThrowingException(validator, subpop);
        fail("Should have thrown an exception");
    } catch (InvalidEntityException e) {
        assertValidatorMessage(validator, subpop, "criteria.minAppVersions.iphone_os", " cannot be negative");
        assertValidatorMessage(validator, subpop, "criteria.maxAppVersions.iphone_os", " cannot be negative");
        assertValidatorMessage(validator, subpop, "appId", CANNOT_BE_NULL);
        assertValidatorMessage(validator, subpop, "name", CANNOT_BE_NULL);
        assertValidatorMessage(validator, subpop, "guid", CANNOT_BE_NULL);
        assertValidatorMessage(validator, subpop, "criteria.noneOfGroups", " 'wrongGroup' is not in enumeration: group1, group2");
        assertValidatorMessage(validator, subpop, "criteria.allOfStudyIds", " 'studyC' is not in enumeration: studyA, studyB");
        assertValidatorMessage(validator, subpop, "criteria.noneOfStudyIds", " 'studyD' is not in enumeration: studyA, studyB");
        assertValidatorMessage(validator, subpop, "dataGroupsAssignedWhileConsented", " 'dataGroup3' is not in enumeration: group1, group2");
        assertValidatorMessage(validator, subpop, "studyIdsAssignedOnConsent", " 'studyC' is not in enumeration: studyA, studyB");
    }
}
Also used : Subpopulation(org.sagebionetworks.bridge.models.subpopulations.Subpopulation) Criteria(org.sagebionetworks.bridge.models.Criteria) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Example 5 with InvalidEntityException

use of org.sagebionetworks.bridge.exceptions.InvalidEntityException in project BridgeServer2 by Sage-Bionetworks.

the class CompoundActivityDefinitionServiceTest method createInvalidDef.

@Test
public void createInvalidDef() {
    // make invalid def by having it have no task ID
    CompoundActivityDefinition def = makeValidDef();
    def.setTaskId(null);
    // execute, will throw
    try {
        service.createCompoundActivityDefinition(TEST_APP_ID, def);
        fail("expected exception");
    } catch (InvalidEntityException ex) {
    // expected exception
    }
    // verify dao is never called
    verifyZeroInteractions(dao);
}
Also used : CompoundActivityDefinition(org.sagebionetworks.bridge.models.schedules.CompoundActivityDefinition) InvalidEntityException(org.sagebionetworks.bridge.exceptions.InvalidEntityException) Test(org.testng.annotations.Test)

Aggregations

InvalidEntityException (org.sagebionetworks.bridge.exceptions.InvalidEntityException)40 Test (org.testng.annotations.Test)35 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 CompoundActivityDefinition (org.sagebionetworks.bridge.models.schedules.CompoundActivityDefinition)5 ConsentSignature (org.sagebionetworks.bridge.models.subpopulations.ConsentSignature)5 DynamoCompoundActivityDefinition (org.sagebionetworks.bridge.dynamodb.DynamoCompoundActivityDefinition)3 Criteria (org.sagebionetworks.bridge.models.Criteria)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 TestUtils.getNotificationTopic (org.sagebionetworks.bridge.TestUtils.getNotificationTopic)2 DynamoSchedulePlan (org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)2 NotificationTopic (org.sagebionetworks.bridge.models.notifications.NotificationTopic)2 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)2 SchedulePlan (org.sagebionetworks.bridge.models.schedules.SchedulePlan)2 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)2 Schedule2Test (org.sagebionetworks.bridge.models.schedules2.Schedule2Test)2 SessionTest (org.sagebionetworks.bridge.models.schedules2.SessionTest)2 Study (org.sagebionetworks.bridge.models.studies.Study)2 AssessmentConfigValidatorTest (org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1