Search in sources :

Example 1 with TextHandler

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

the class TextHandlerTest method shouldReturnSupportedViews.

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

Example 2 with TextHandler

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

the class TextHandlerTest method shouldNotSupportOtherViews.

@Test
public void shouldNotSupportOtherViews() {
    TextHandler handler = new TextHandler();
    assertFalse(handler.supportsView(ComplexObsHandler.HTML_VIEW));
    assertFalse(handler.supportsView(ComplexObsHandler.PREVIEW_VIEW));
    assertFalse(handler.supportsView(ComplexObsHandler.TITLE_VIEW));
    assertFalse(handler.supportsView(""));
    assertFalse(handler.supportsView((String) null));
}
Also used : TextHandler(org.openmrs.obs.handler.TextHandler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TextHandler

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

the class TextHandlerTest method shouldRetrieveCorrectMimetype.

@Test
public void shouldRetrieveCorrectMimetype() {
    final String mimetype = "text/plain";
    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);
    TextHandler handler = new TextHandler();
    // 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 = TextHandler.getComplexDataFile(obs1);
    File obsFile2 = TextHandler.getComplexDataFile(obs2);
    obsFile1.delete();
    obsFile2.delete();
}
Also used : Obs(org.openmrs.Obs) TextHandler(org.openmrs.obs.handler.TextHandler) File(java.io.File) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with TextHandler

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

the class TextHandlerTest method shouldSupportRawView.

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

Example 5 with TextHandler

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

the class ObsServiceTest method setHandlers_shouldAddNewHandlersWithNewKeys.

/**
 * @see ObsService#setHandlers(Map<QString;QComplexObsHandler;>)}
 */
@Test
public void setHandlers_shouldAddNewHandlersWithNewKeys() {
    ObsService os = Context.getObsService();
    Map<String, ComplexObsHandler> handlers = new HashMap<>();
    handlers.put("DummyHandler4", new ImageHandler());
    handlers.put("DummyHandler5", new BinaryDataHandler());
    handlers.put("DummyHandler6", new TextHandler());
    // set the handlers and make sure they're there
    os.setHandlers(handlers);
    ComplexObsHandler dummyHandler4 = os.getHandler("DummyHandler4");
    Assert.assertNotNull(dummyHandler4);
    ComplexObsHandler dummyHandler5 = os.getHandler("DummyHandler5");
    Assert.assertNotNull(dummyHandler5);
    ComplexObsHandler dummyHandler6 = os.getHandler("DummyHandler6");
    Assert.assertNotNull(dummyHandler6);
}
Also used : ImageHandler(org.openmrs.obs.handler.ImageHandler) BinaryDataHandler(org.openmrs.obs.handler.BinaryDataHandler) HashMap(java.util.HashMap) TextHandler(org.openmrs.obs.handler.TextHandler) ComplexObsHandler(org.openmrs.obs.ComplexObsHandler) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

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