use of org.sagebionetworks.bridge.models.CreatedOnHolder in project BridgeServer2 by Sage-Bionetworks.
the class TemplateRevisionControllerTest method createTemplateRevision.
@Test
public void createTemplateRevision() throws Exception {
TemplateRevision revision = TemplateRevision.create();
revision.setMimeType(TEXT);
revision.setSubject(SUBJECT);
revision.setDocumentContent(DOCUMENT_CONTENT);
mockRequestBody(request, revision);
CreatedOnHolder holder = new CreatedOnHolder(CREATED_ON);
when(mockRevisionService.createTemplateRevision(eq(TEST_APP_ID), eq(TEMPLATE_GUID), any())).thenReturn(holder);
controller.createTemplateRevision(TEMPLATE_GUID);
verify(mockRevisionService).createTemplateRevision(eq(TEST_APP_ID), eq(TEMPLATE_GUID), revisionCaptor.capture());
TemplateRevision captured = revisionCaptor.getValue();
assertEquals(captured.getMimeType(), TEXT);
assertEquals(captured.getSubject(), SUBJECT);
assertEquals(captured.getDocumentContent(), DOCUMENT_CONTENT);
}
use of org.sagebionetworks.bridge.models.CreatedOnHolder in project BridgeServer2 by Sage-Bionetworks.
the class TemplateRevisionServiceTest method createTemplateRevision.
@Test
public void createTemplateRevision() throws Exception {
mockGetTemplate();
TemplateRevision revision = TemplateRevision.create();
revision.setMimeType(TEXT);
revision.setSubject(SUBJECT);
revision.setDocumentContent(DOCUMENT_CONTENT);
CreatedOnHolder holder = service.createTemplateRevision(TEST_APP_ID, TEMPLATE_GUID, revision);
assertEquals(holder.getCreatedOn(), CREATED_ON);
verify(mockTemplateRevisionDao).createTemplateRevision(revisionCaptor.capture());
TemplateRevision captured = revisionCaptor.getValue();
assertEquals(captured.getTemplateGuid(), TEMPLATE_GUID);
assertEquals(captured.getCreatedOn(), CREATED_ON);
assertEquals(captured.getCreatedBy(), TEST_USER_ID);
assertEquals(captured.getStoragePath(), STORAGE_PATH);
assertEquals(captured.getDocumentContent(), DOCUMENT_CONTENT);
assertEquals(captured.getMimeType(), TEXT);
assertEquals(captured.getSubject(), SUBJECT);
}
use of org.sagebionetworks.bridge.models.CreatedOnHolder in project BridgeServer2 by Sage-Bionetworks.
the class TemplateRevisionService method createTemplateRevision.
public CreatedOnHolder createTemplateRevision(String appId, String templateGuid, TemplateRevision revision) {
checkNotNull(appId);
checkNotNull(templateGuid);
checkNotNull(revision);
DateTime createdOn = getDateTime();
String storagePath = templateGuid + "." + createdOn.getMillis();
// verify the template GUID is in the user's app.
Template template = templateDao.getTemplate(appId, templateGuid).orElseThrow(() -> new EntityNotFoundException(Template.class));
revision.setCreatedOn(createdOn);
revision.setTemplateGuid(templateGuid);
revision.setCreatedBy(getUserId());
revision.setStoragePath(storagePath);
TemplateRevisionValidator validator = new TemplateRevisionValidator(template.getTemplateType());
Validate.entityThrowingException(validator, revision);
templateRevisionDao.createTemplateRevision(revision);
return new CreatedOnHolder(createdOn);
}
Aggregations