use of org.motechproject.server.web.dto.BundleIcon in project motech by motech.
the class BundleIconServiceImplTest method shouldReturnDefaultIconWhenBundleNotFound.
@Test
public void shouldReturnDefaultIconWhenBundleNotFound() {
setupBundleRetrieval();
BundleIcon bundleIcon = bundleIconService.getBundleIconById(BUNDLE_ID_2, null);
byte[] expectedIcon = readDefaultIcon(DEFAULT_PATH + DEFAULT_ICON);
assertArrayEquals(expectedIcon, bundleIcon.getIcon());
assertEquals(ICON_MIME, bundleIcon.getMime());
}
use of org.motechproject.server.web.dto.BundleIcon in project motech by motech.
the class BundleIconServiceImplTest method shouldReturnIcon.
@Test
public void shouldReturnIcon() throws IOException {
setupBundleRetrieval();
byte[] expectedIcon = readDefaultIcon(DEFAULT_PATH + DEFAULT_ICON);
when(bundle.getResource("icon.gif")).thenReturn(getDefaultIconUrl(DEFAULT_PATH + DEFAULT_ICON));
BundleIcon bundleIcon = bundleIconService.getBundleIconById(BUNDLE_ID, null);
assertArrayEquals(expectedIcon, bundleIcon.getIcon());
assertEquals(expectedIcon.length, bundleIcon.getContentLength());
assertEquals(ICON_MIME, bundleIcon.getMime());
verify(bundleContext).getBundle(BUNDLE_ID);
verify(bundle).getResource("icon.gif");
}
use of org.motechproject.server.web.dto.BundleIcon in project motech by motech.
the class ModuleControllerTest method shouldGetBundleIcon.
@Test
public void shouldGetBundleIcon() throws IOException {
BundleIcon bundleIcon = new BundleIcon(new byte[] { 1, 2, 3, 4 }, ICON_MIME);
when(bundleIconService.getBundleIconById(BUNDLE_ID, null)).thenReturn(bundleIcon);
when(response.getOutputStream()).thenReturn(outputStream);
moduleController.getBundleIcon(BUNDLE_ID, null, null, response);
verify(response).setStatus(HttpServletResponse.SC_OK);
verify(response).setContentLength(bundleIcon.getContentLength());
verify(response).setContentType(bundleIcon.getMime());
verify(response).getOutputStream();
verify(outputStream).write(bundleIcon.getIcon());
}
use of org.motechproject.server.web.dto.BundleIcon in project motech by motech.
the class ModuleController method getBundleIcon.
/**
* Returns the icon associated with the given bundle. Bundles that do not have their own icons will
* get a default icon.
* @param bundleId the id of the bundle for which the icon should be retrieved
* @param bundleName the name of the bundle for which the icon should be retrieved
* @param defaultIcon the name of the default icon which be provided if any standard icon couldn't be searched
* @param response the HttpServletResponse, used for writing the icon in its output
* @throws IOException if there were failures writing the icon to the output
*/
@RequestMapping(value = "/module/icon", method = RequestMethod.GET)
public void getBundleIcon(@RequestParam(required = false) Long bundleId, @RequestParam(required = false) String bundleName, @RequestParam(required = false) String defaultIcon, HttpServletResponse response) throws IOException {
BundleIcon bundleIcon;
if (bundleId != null) {
bundleIcon = bundleIconService.getBundleIconById(bundleId, defaultIcon);
} else {
bundleIcon = bundleIconService.getBundleIconByName(bundleName, defaultIcon);
}
response.setStatus(HttpServletResponse.SC_OK);
response.setContentLength(bundleIcon.getContentLength());
response.setContentType(bundleIcon.getMime());
response.getOutputStream().write(bundleIcon.getIcon());
}
use of org.motechproject.server.web.dto.BundleIcon in project motech by motech.
the class BundleIconServiceImplTest method shouldReturnGivenDefaultIconWhenBundleDoesNotContainIcon.
@Test
public void shouldReturnGivenDefaultIconWhenBundleDoesNotContainIcon() {
setupBundleRetrieval();
BundleIcon bundleIcon = bundleIconService.getBundleIconById(BUNDLE_ID, DEFAULT_ICON_2);
byte[] expectedIcon = readDefaultIcon(DEFAULT_PATH + DEFAULT_ICON_2);
assertArrayEquals(expectedIcon, bundleIcon.getIcon());
assertEquals(ICON_MIME, bundleIcon.getMime());
}
Aggregations