Search in sources :

Example 1 with ImageHandler

use of org.openmrs.obs.handler.ImageHandler 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);
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) BinaryDataHandler(org.openmrs.obs.handler.BinaryDataHandler) HashMap(java.util.HashMap) ComplexObsHandler(org.openmrs.obs.ComplexObsHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 2 with ImageHandler

use of org.openmrs.obs.handler.ImageHandler in project openmrs-core by openmrs.

the class ImageHandlerTest method shouldNotSupportOtherViews.

@Test
public void shouldNotSupportOtherViews() {
    ImageHandler handler = new ImageHandler();
    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));
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ImageHandler

use of org.openmrs.obs.handler.ImageHandler in project openmrs-core by openmrs.

the class ImageHandlerTest method shouldRetrieveCorrectMimetype.

@Test
public void shouldRetrieveCorrectMimetype() throws IOException {
    final String mimetype = "image/png";
    BufferedImage img = ImageIO.read(sourceFile);
    ComplexData complexData = new ComplexData(FILENAME, img);
    // 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);
    ImageHandler handler = new ImageHandler();
    // 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
    File obsFile1 = ImageHandler.getComplexDataFile(obs1);
    File obsFile2 = ImageHandler.getComplexDataFile(obs2);
    obsFile1.delete();
    obsFile2.delete();
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) Obs(org.openmrs.Obs) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ImageHandler

use of org.openmrs.obs.handler.ImageHandler in project openmrs-core by openmrs.

the class ImageHandlerTest method shouldSupportRawView.

@Test
public void shouldSupportRawView() {
    ImageHandler handler = new ImageHandler();
    assertTrue(handler.supportsView(ComplexObsHandler.RAW_VIEW));
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ImageHandler

use of org.openmrs.obs.handler.ImageHandler in project openmrs-core by openmrs.

the class ImageHandlerTest method shouldReturnSupportedViews.

@Test
public void shouldReturnSupportedViews() {
    ImageHandler handler = new ImageHandler();
    String[] actualViews = handler.getSupportedViews();
    String[] expectedViews = { ComplexObsHandler.RAW_VIEW };
    assertArrayEquals(actualViews, expectedViews);
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)8 ImageHandler (org.openmrs.obs.handler.ImageHandler)8 ComplexObsHandler (org.openmrs.obs.ComplexObsHandler)4 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)2 BinaryDataHandler (org.openmrs.obs.handler.BinaryDataHandler)2 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 Obs (org.openmrs.Obs)1 TextHandler (org.openmrs.obs.handler.TextHandler)1