Search in sources :

Example 1 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class DynamoAppConfigElementDaoTest method saveElementRevision.

@Test
public void saveElementRevision() {
    AppConfigElement element = AppConfigElement.create();
    element.setVersion(1L);
    VersionHolder returned = dao.saveElementRevision(element);
    assertEquals(returned.getVersion(), new Long(1));
    verify(mockMapper).save(element);
}
Also used : AppConfigElement(org.sagebionetworks.bridge.models.appconfig.AppConfigElement) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Test(org.testng.annotations.Test)

Example 2 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppController method updateAppForDeveloperOrAdmin.

@PostMapping(path = { "/v1/apps/self", "/v3/studies/self" })
public VersionHolder updateAppForDeveloperOrAdmin() {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    App appUpdate = parseJson(App.class);
    appUpdate.setIdentifier(session.getAppId());
    appUpdate = appService.updateApp(appUpdate, session.isInRole(ADMIN));
    return new VersionHolder(appUpdate.getVersion());
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class StudyServiceTest method createStudyWithSponsorship.

@Test
public void createStudyWithSponsorship() {
    RequestContext.set(new RequestContext.Builder().withCallerOrgMembership(TEST_ORG_ID).build());
    Study study = Study.create();
    study.setIdentifier(TEST_STUDY_ID);
    study.setName("oneName");
    study.setAppId("junk");
    study.setVersion(10L);
    study.setDeleted(true);
    study.setPhase(IN_FLIGHT);
    DateTime timestamp = DateTime.now().minusHours(2);
    study.setCreatedOn(timestamp);
    study.setModifiedOn(timestamp);
    when(mockStudyDao.createStudy(any())).thenReturn(VERSION_HOLDER);
    VersionHolder returnedValue = service.createStudy(TEST_APP_ID, study, true);
    assertEquals(returnedValue, VERSION_HOLDER);
    verify(mockStudyDao).createStudy(studyCaptor.capture());
    Study persisted = studyCaptor.getValue();
    assertEquals(persisted.getIdentifier(), TEST_STUDY_ID);
    assertEquals(persisted.getName(), "oneName");
    assertEquals(persisted.getAppId(), TEST_APP_ID);
    assertEquals(persisted.getPhase(), DESIGN);
    assertNull(persisted.getVersion());
    assertFalse(persisted.isDeleted());
    assertNotEquals(persisted.getCreatedOn(), timestamp);
    assertNotEquals(persisted.getModifiedOn(), timestamp);
    verify(mockSponsorService).createStudyWithSponsorship(TEST_APP_ID, TEST_STUDY_ID, TEST_ORG_ID);
}
Also used : Study(org.sagebionetworks.bridge.models.studies.Study) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) RequestContext(org.sagebionetworks.bridge.RequestContext) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementServiceTest method createElementWithArbitraryRevision.

@Test
public void createElementWithArbitraryRevision() {
    // revision = 3
    AppConfigElement element = TestUtils.getAppConfigElement();
    when(dao.saveElementRevision(element)).thenReturn(VERSION_HOLDER);
    VersionHolder returned = service.createElement(TEST_APP_ID, element);
    assertEquals(returned, VERSION_HOLDER);
    verify(dao).saveElementRevision(elementCaptor.capture());
    // Revision was maintained because it was set, and doesn't exist
    assertEquals(elementCaptor.getValue().getRevision(), new Long(3));
}
Also used : AppConfigElement(org.sagebionetworks.bridge.models.appconfig.AppConfigElement) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Test(org.testng.annotations.Test)

Example 5 with VersionHolder

use of org.sagebionetworks.bridge.models.VersionHolder in project BridgeServer2 by Sage-Bionetworks.

the class HibernateStudyDaoTest method createStudy.

@Test
public void createStudy() {
    HibernateStudy study = new HibernateStudy();
    study.setIdentifier(TEST_STUDY_ID);
    study.setAppId(TEST_APP_ID);
    study.setVersion(2L);
    VersionHolder holder = dao.createStudy(study);
    assertEquals(holder.getVersion(), new Long(2));
    verify(hibernateHelper).create(studyCaptor.capture());
    Study persisted = studyCaptor.getValue();
    assertEquals(persisted.getVersion(), new Long(2));
}
Also used : Study(org.sagebionetworks.bridge.models.studies.Study) VersionHolder(org.sagebionetworks.bridge.models.VersionHolder) Test(org.testng.annotations.Test)

Aggregations

VersionHolder (org.sagebionetworks.bridge.models.VersionHolder)25 Test (org.testng.annotations.Test)17 App (org.sagebionetworks.bridge.models.apps.App)9 AppConfigElement (org.sagebionetworks.bridge.models.appconfig.AppConfigElement)8 Study (org.sagebionetworks.bridge.models.studies.Study)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 TestUtils.getValidApp (org.sagebionetworks.bridge.TestUtils.getValidApp)5 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)5 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)3 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 DateTime (org.joda.time.DateTime)2 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)2 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)2 StudyValidator (org.sagebionetworks.bridge.validators.StudyValidator)2 RequestContext (org.sagebionetworks.bridge.RequestContext)1 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)1 EntityAlreadyExistsException (org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException)1 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)1