Search in sources :

Example 1 with SharedModuleImportStatus

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

the class SharedModuleServiceTest method byIdAndVersionSurveySuccess.

@Test
public void byIdAndVersionSurveySuccess() {
    // mock metadata service
    when(mockMetadataService.getMetadataByIdAndVersion(MODULE_ID, MODULE_VERSION)).thenReturn(makeValidMetadataWithSurvey());
    // mock survey service
    Survey sharedSurvey = Survey.create();
    when(mockSurveyService.getSurvey(SHARED_APP_ID, SHARED_SURVEY_KEY, true, true)).thenReturn(sharedSurvey);
    Survey localSurvey = Survey.create();
    localSurvey.setGuid(LOCAL_SURVEY_GUID);
    localSurvey.setCreatedOn(LOCAL_SURVEY_CREATED_ON);
    when(mockSurveyService.createSurvey(any())).thenReturn(localSurvey);
    // execute and validate import status
    SharedModuleImportStatus status = moduleService.importModuleByIdAndVersion(TEST_APP_ID, MODULE_ID, MODULE_VERSION);
    assertEquals(status.getModuleType(), SharedModuleType.SURVEY);
    assertEquals(status.getSurveyCreatedOn().longValue(), LOCAL_SURVEY_CREATED_ON);
    assertEquals(status.getSurveyGuid(), LOCAL_SURVEY_GUID);
    // Verify calls to create survey. Verify that we set the appId.
    ArgumentCaptor<Survey> surveyToCreateCaptor = ArgumentCaptor.forClass(Survey.class);
    verify(mockSurveyService).createSurvey(surveyToCreateCaptor.capture());
    Survey surveyToCreate = surveyToCreateCaptor.getValue();
    assertEquals(surveyToCreate.getAppId(), TEST_APP_ID);
    assertEquals(surveyToCreate.getModuleId(), MODULE_ID);
    assertEquals(surveyToCreate.getModuleVersion().intValue(), MODULE_VERSION);
    // verify call to publish survey
    verify(mockSurveyService).publishSurvey(TEST_APP_ID, LOCAL_SURVEY_KEY, true);
}
Also used : Survey(org.sagebionetworks.bridge.models.surveys.Survey) SharedModuleImportStatus(org.sagebionetworks.bridge.models.sharedmodules.SharedModuleImportStatus) Test(org.testng.annotations.Test)

Example 2 with SharedModuleImportStatus

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

the class SharedModuleServiceTest method latestPublishedSuccess.

@Test
public void latestPublishedSuccess() {
    // mock metadata service
    when(mockMetadataService.queryMetadataById(MODULE_ID, true, true, null, null, null, false)).thenReturn(ImmutableList.of(makeValidMetadataWithSchema()));
    ArgumentCaptor<UploadSchema> schemaArgumentCaptor = ArgumentCaptor.forClass(UploadSchema.class);
    when(mockSchemaService.createSchemaRevisionV4(any(), schemaArgumentCaptor.capture())).thenReturn(null);
    // mock schema service
    UploadSchema sharedSchema = UploadSchema.create();
    when(mockSchemaService.getUploadSchemaByIdAndRev(SHARED_APP_ID, SCHEMA_ID, SCHEMA_REV)).thenReturn(sharedSchema);
    // execute and validate import status
    SharedModuleImportStatus status = moduleService.importModuleByIdLatestPublishedVersion(TEST_APP_ID, MODULE_ID);
    assertEquals(status.getModuleType(), SharedModuleType.SCHEMA);
    assertEquals(status.getSchemaId(), SCHEMA_ID);
    assertEquals(status.getSchemaRevision().intValue(), SCHEMA_REV);
    UploadSchema modifiedSchema = schemaArgumentCaptor.getValue();
    assertEquals(modifiedSchema.getModuleId(), MODULE_ID);
    assertEquals(modifiedSchema.getModuleVersion().intValue(), MODULE_VERSION);
    // verify calls to create schema
    verify(mockSchemaService).createSchemaRevisionV4(TEST_APP_ID, sharedSchema);
}
Also used : UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) SharedModuleImportStatus(org.sagebionetworks.bridge.models.sharedmodules.SharedModuleImportStatus) Test(org.testng.annotations.Test)

Example 3 with SharedModuleImportStatus

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

the class SharedModuleControllerTest method byIdAndVersion.

@Test
public void byIdAndVersion() throws Exception {
    // mock service
    when(mockSvc.importModuleByIdAndVersion(TEST_APP_ID, MODULE_ID, MODULE_VERSION)).thenReturn(new SharedModuleImportStatus(SCHEMA_ID, SCHEMA_REV));
    // setup, execute, and validate
    SharedModuleImportStatus result = controller.importModuleByIdAndVersion(MODULE_ID, MODULE_VERSION);
    assertStatus(result);
    // validate permissions
    verify(controller).getAuthenticatedSession(Roles.DEVELOPER);
}
Also used : SharedModuleImportStatus(org.sagebionetworks.bridge.models.sharedmodules.SharedModuleImportStatus) Test(org.testng.annotations.Test)

Example 4 with SharedModuleImportStatus

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

the class SharedModuleControllerTest method latestPublished.

@Test
public void latestPublished() throws Exception {
    // mock service
    when(mockSvc.importModuleByIdLatestPublishedVersion(TEST_APP_ID, MODULE_ID)).thenReturn(new SharedModuleImportStatus(SCHEMA_ID, SCHEMA_REV));
    // setup, execute, and validate
    SharedModuleImportStatus result = controller.importModuleByIdLatestPublishedVersion(MODULE_ID);
    assertStatus(result);
    // validate permissions
    verify(controller).getAuthenticatedSession(Roles.DEVELOPER);
}
Also used : SharedModuleImportStatus(org.sagebionetworks.bridge.models.sharedmodules.SharedModuleImportStatus) Test(org.testng.annotations.Test)

Example 5 with SharedModuleImportStatus

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

the class SharedModuleServiceTest method byIdAndVersionSchemaSuccess.

@Test
public void byIdAndVersionSchemaSuccess() {
    // mock metadata service
    when(mockMetadataService.getMetadataByIdAndVersion(MODULE_ID, MODULE_VERSION)).thenReturn(makeValidMetadataWithSchema());
    ArgumentCaptor<UploadSchema> schemaArgumentCaptor = ArgumentCaptor.forClass(UploadSchema.class);
    when(mockSchemaService.createSchemaRevisionV4(any(), schemaArgumentCaptor.capture())).thenReturn(null);
    // mock schema service
    UploadSchema sharedSchema = UploadSchema.create();
    when(mockSchemaService.getUploadSchemaByIdAndRev(SHARED_APP_ID, SCHEMA_ID, SCHEMA_REV)).thenReturn(sharedSchema);
    // execute and validate import status
    SharedModuleImportStatus status = moduleService.importModuleByIdAndVersion(TEST_APP_ID, MODULE_ID, MODULE_VERSION);
    assertEquals(status.getModuleType(), SharedModuleType.SCHEMA);
    assertEquals(status.getSchemaId(), SCHEMA_ID);
    assertEquals(status.getSchemaRevision().intValue(), SCHEMA_REV);
    UploadSchema modifiedSchema = schemaArgumentCaptor.getValue();
    assertEquals(modifiedSchema.getModuleId(), MODULE_ID);
    assertEquals(modifiedSchema.getModuleVersion().intValue(), MODULE_VERSION);
    // verify calls to create schema
    verify(mockSchemaService).createSchemaRevisionV4(TEST_APP_ID, sharedSchema);
}
Also used : UploadSchema(org.sagebionetworks.bridge.models.upload.UploadSchema) SharedModuleImportStatus(org.sagebionetworks.bridge.models.sharedmodules.SharedModuleImportStatus) Test(org.testng.annotations.Test)

Aggregations

SharedModuleImportStatus (org.sagebionetworks.bridge.models.sharedmodules.SharedModuleImportStatus)6 Test (org.testng.annotations.Test)5 UploadSchema (org.sagebionetworks.bridge.models.upload.UploadSchema)3 Survey (org.sagebionetworks.bridge.models.surveys.Survey)2 GuidCreatedOnVersionHolder (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolder)1 GuidCreatedOnVersionHolderImpl (org.sagebionetworks.bridge.models.GuidCreatedOnVersionHolderImpl)1 SharedModuleType (org.sagebionetworks.bridge.models.sharedmodules.SharedModuleType)1