use of org.openmrs.obs.handler.BinaryDataHandler in project openmrs-core by openmrs.
the class BinaryDataHandlerTest method shouldRetrieveCorrectMimetype.
@Test
public void shouldRetrieveCorrectMimetype() {
final String mimetype = "application/octet-stream";
ComplexData complexData = new ComplexData(FILENAME, CONTENT);
// Construct 2 Obs to also cover the case where the filename exists already
Obs obs1 = new Obs();
obs1.setComplexData(complexData);
Obs obs2 = new Obs();
obs2.setComplexData(complexData);
// Mocked methods
mockStatic(Context.class);
when(Context.getAdministrationService()).thenReturn(administrationService);
when(administrationService.getGlobalProperty(any())).thenReturn(filepath);
BinaryDataHandler handler = new BinaryDataHandler();
// Execute save
handler.saveObs(obs1);
handler.saveObs(obs2);
// Get observation
Obs complexObs = handler.getObs(obs1, "RAW_VIEW");
Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW");
assertTrue(complexObs.getComplexData().getMimeType().equals(mimetype));
assertTrue(complexObs2.getComplexData().getMimeType().equals(mimetype));
// Delete created files to avoid cluttering with new versions of the file!
File obsFile1 = BinaryDataHandler.getComplexDataFile(obs1);
File obsFile2 = BinaryDataHandler.getComplexDataFile(obs2);
obsFile1.delete();
obsFile2.delete();
}
use of org.openmrs.obs.handler.BinaryDataHandler in project openmrs-core by openmrs.
the class ObsServiceTest method setHandlers_shouldOverrideHandlersWithSameKey.
/**
* @see ObsService#setHandlers(Map<QString;QComplexObsHandler;>)}
*/
@Test
public void setHandlers_shouldOverrideHandlersWithSameKey() {
ObsService os = Context.getObsService();
Map<String, ComplexObsHandler> handlers = new HashMap<>();
handlers.put("DummyHandlerToOverride", new ImageHandler());
// set the handlers and make sure they're there
os.setHandlers(handlers);
ComplexObsHandler dummyHandlerToOverride = os.getHandler("DummyHandlerToOverride");
Assert.assertTrue(dummyHandlerToOverride instanceof ImageHandler);
// now override that key and make sure the new class is stored
Map<String, ComplexObsHandler> handlersAgain = new HashMap<>();
handlersAgain.put("DummyHandlerToOverride", new BinaryDataHandler());
os.setHandlers(handlersAgain);
ComplexObsHandler dummyHandlerToOverrideAgain = os.getHandler("DummyHandlerToOverride");
Assert.assertTrue(dummyHandlerToOverrideAgain instanceof BinaryDataHandler);
}
use of org.openmrs.obs.handler.BinaryDataHandler in project openmrs-core by openmrs.
the class BinaryDataHandlerTest method shouldReturnSupportedViews.
@Test
public void shouldReturnSupportedViews() {
BinaryDataHandler handler = new BinaryDataHandler();
String[] actualViews = handler.getSupportedViews();
String[] expectedViews = { ComplexObsHandler.RAW_VIEW };
assertArrayEquals(actualViews, expectedViews);
}
use of org.openmrs.obs.handler.BinaryDataHandler in project openmrs-core by openmrs.
the class BinaryDataHandlerTest method shouldSupportRawView.
@Test
public void shouldSupportRawView() {
BinaryDataHandler handler = new BinaryDataHandler();
assertTrue(handler.supportsView(ComplexObsHandler.RAW_VIEW));
}
use of org.openmrs.obs.handler.BinaryDataHandler in project openmrs-core by openmrs.
the class BinaryDataHandlerTest method shouldNotSupportOtherViews.
@Test
public void shouldNotSupportOtherViews() {
BinaryDataHandler handler = new BinaryDataHandler();
assertFalse(handler.supportsView(ComplexObsHandler.HTML_VIEW));
assertFalse(handler.supportsView(ComplexObsHandler.PREVIEW_VIEW));
assertFalse(handler.supportsView(ComplexObsHandler.TEXT_VIEW));
assertFalse(handler.supportsView(ComplexObsHandler.TITLE_VIEW));
assertFalse(handler.supportsView(ComplexObsHandler.URI_VIEW));
assertFalse(handler.supportsView(""));
assertFalse(handler.supportsView((String) null));
}
Aggregations