Example usage for org.springframework.mail.javamail ConfigurableMimeFileTypeMap afterPropertiesSet

List of usage examples for org.springframework.mail.javamail ConfigurableMimeFileTypeMap afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.mail.javamail ConfigurableMimeFileTypeMap afterPropertiesSet.

Prototype

@Override
public void afterPropertiesSet() 

Source Link

Document

Creates the final merged mapping set.

Usage

From source file:org.sventon.web.ctrl.template.ShowThumbnailsControllerTest.java

@Test
public void testSvnHandle() throws Exception {
    final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    fileTypeMap.afterPropertiesSet();

    final MultipleEntriesCommand command = new MultipleEntriesCommand();
    final ShowThumbnailsController ctrl = new ShowThumbnailsController(fileTypeMap);

    final String[] pathEntries = new String[] { "file1.gif@123", "file2.jpg@123", "file.abc@123" };

    command.setEntries(PathRevision.parse(pathEntries));

    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.CONTENT_DISPOSITION_INLINE);

    final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, req, null, null);

    final Map model = modelAndView.getModel();
    final List entries = (List) model.get("thumbnailentries");

    assertEquals(2, entries.size());/*from  w w  w .  ja  v a  2  s.co  m*/

    final PathRevision entry0 = (PathRevision) entries.get(0);
    assertEquals("file1.gif", entry0.getPath());
    assertEquals(123, entry0.getRevision().getNumber());
}

From source file:org.sventon.web.ctrl.template.ShowFileControllerTest.java

@Before
public void setUp() throws Exception {
    final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    fileTypeMap.afterPropertiesSet();
    ctrl = new ShowFileController(fileTypeMap);
    ctrl.setArchiveFileExtensionPattern("(jar|zip|war|ear)");
}

From source file:org.sventon.web.ctrl.template.ShowFileControllerTest.java

@Test
public void testConfigurableMimeFileTypeMap() {
    final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    fileTypeMap.afterPropertiesSet();

    assertEquals("application/octet-stream", fileTypeMap.getContentType("file.abc"));
    assertEquals("application/zip", fileTypeMap.getContentType("file.zip"));
    assertEquals("image/jpeg", fileTypeMap.getContentType("file.jpg"));
    assertEquals("image/jpeg", fileTypeMap.getContentType("file.jpe"));
    assertEquals("image/jpeg", fileTypeMap.getContentType("file.jpeg"));
    assertEquals("image/gif", fileTypeMap.getContentType("file.gif"));
    assertEquals("image/x-png", fileTypeMap.getContentType("file.png"));
    assertEquals("application/octet-stream", fileTypeMap.getContentType("filenamejpg"));
    assertEquals("image/gif", fileTypeMap.getContentType("/dir/file.gif"));
}

From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java

@Test
public void testSvnHandleGetFile() throws Exception {
    final BaseCommand command = new BaseCommand();
    command.setName(repositoryName);//from   w  w w . j  a  v  a2 s  .co m
    command.setPath("/testfile.txt");

    final GetFileController ctrl = new GetFileController();
    ctrl.setApplication(application);
    ctrl.setRepositoryService(mock(RepositoryService.class));

    final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap();
    mftm.afterPropertiesSet();
    ctrl.setMimeFileTypeMap(mftm);
    final ModelAndView modelAndView;

    final MockHttpServletResponse res = new MockHttpServletResponse();
    ctrl.setServletContext(mockServletContext);
    modelAndView = ctrl.svnHandle(null, command, 100, null, request, res, null);

    assertNull(modelAndView);
    assertEquals("text/plain", res.getContentType());
    assertTrue(((String) res.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).startsWith("attachment"));
}

From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java

@Test
public void testSvnHandleGetImageAsInline() throws Exception {
    final BaseCommand command = new BaseCommand();
    command.setName(repositoryName);/*from   w  w  w.j a  v  a2  s  .  c  o m*/
    command.setPath("/testimage.gif");

    final GetFileController ctrl = new GetFileController();
    ctrl.setApplication(application);
    ctrl.setRepositoryService(mock(RepositoryService.class));

    final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap();
    mftm.afterPropertiesSet();
    ctrl.setMimeFileTypeMap(mftm);
    final ModelAndView modelAndView;

    request.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER,
            GetFileController.CONTENT_DISPOSITION_INLINE);

    final MockHttpServletResponse res = new MockHttpServletResponse();
    modelAndView = ctrl.svnHandle(null, command, 100, null, request, res, null);

    assertNull(modelAndView);
    assertEquals("image/gif", res.getContentType());
    assertTrue(((String) res.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).startsWith("inline"));
}

From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java

@Test
public void testCacheNotUsed() throws Exception {
    final RepositoryService repositoryServiceMock = EasyMock.createMock(RepositoryService.class);

    final GetFileController ctrl = new GetFileController();

    repositoryConfiguration.setCacheUsed(false);

    final ImageScaler imageScaler = new ImageScaler() {
        @Override//from   w  ww. ja va2  s .  c o m
        public BufferedImage getThumbnail(BufferedImage image, int maxSize) {
            return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
        }
    };

    final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap();
    mftm.afterPropertiesSet();

    ctrl.setApplication(application);
    ctrl.setRepositoryService(repositoryServiceMock);
    ctrl.setMimeFileTypeMap(mftm);
    ctrl.setImageScaler(imageScaler);
    ctrl.setImageFormatName("jpg");

    final BaseCommand command = new BaseCommand();
    command.setName(repositoryName);
    command.setPath("/test/target.jpg");

    request.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.DISPLAY_TYPE_THUMBNAIL);

    repositoryServiceMock.getFileContents((SVNConnection) EasyMock.isNull(),
            EasyMock.matches(command.getPath()), EasyMock.eq(-1L), (OutputStream) EasyMock.anyObject());

    assertEquals(0, response.getContentAsByteArray().length);

    EasyMock.replay(repositoryServiceMock);
    ctrl.svnHandle(null, command, 100, null, request, response, null);
    EasyMock.verify(repositoryServiceMock);

    assertTrue(((String) response.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).contains("target.jpg"));
    assertEquals(622, response.getContentAsByteArray().length);
}

From source file:org.sventon.web.ctrl.template.GetFileControllerTest.java

@Test
public void testCacheUsed() throws Exception {
    final RepositoryService repositoryServiceMock = EasyMock.createMock(RepositoryService.class);

    final ObjectCacheManager objectCacheManager = new ObjectCacheManager(configDirectory, 0, false, false, 0, 0,
            false, 0) {//from   w w  w .  jav  a 2 s.c o  m
        @Override
        protected ObjectCache createCache(RepositoryName cacheName) throws CacheException {
            return new DefaultObjectCache(cacheName.toString(), null, 1000, false, false, 0, 0, false, 0);
        }
    };
    objectCacheManager.register(repositoryName);

    final GetFileController ctrl = new GetFileController();

    repositoryConfiguration.setCacheUsed(true);

    final ImageScaler imageScaler = new ImageScaler() {
        @Override
        public BufferedImage getThumbnail(BufferedImage image, int maxSize) {
            return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
        }
    };

    final ConfigurableMimeFileTypeMap mftm = new ConfigurableMimeFileTypeMap();
    mftm.afterPropertiesSet();

    ctrl.setApplication(application);
    ctrl.setRepositoryService(repositoryServiceMock);
    ctrl.setMimeFileTypeMap(mftm);
    ctrl.setImageScaler(imageScaler);
    ctrl.setImageFormatName("png");
    ctrl.setObjectCacheManager(objectCacheManager);

    final BaseCommand command = new BaseCommand();
    command.setName(repositoryName);
    command.setPath("/test/target.png");

    request.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.DISPLAY_TYPE_THUMBNAIL);

    repositoryServiceMock.getFileContents((SVNConnection) EasyMock.isNull(),
            EasyMock.matches(command.getPath()), EasyMock.eq(-1L), (OutputStream) EasyMock.anyObject());

    assertEquals(0, response.getContentAsByteArray().length);

    EasyMock.replay(repositoryServiceMock);
    ctrl.svnHandle(null, command, 100, null, request, response, null);
    EasyMock.verify(repositoryServiceMock);

    assertTrue(((String) response.getHeader(WebUtils.CONTENT_DISPOSITION_HEADER)).contains("target.png"));
    assertEquals(68, response.getContentAsByteArray().length);

    EasyMock.reset(repositoryServiceMock);

    // Thumbnail is now cached - verify that it's used
    EasyMock.replay(repositoryServiceMock);
    ctrl.svnHandle(null, command, 100, null, request, response, null);
    EasyMock.verify(repositoryServiceMock);
}

From source file:org.springframework.mail.javamail.JavaMailSenderImpl.java

/**
 * Create a new instance of the <code>JavaMailSenderImpl</code> class.
 * <p>Initializes the {@link #setDefaultFileTypeMap "defaultFileTypeMap"}
 * property with a default {@link ConfigurableMimeFileTypeMap}.
 *///from  ww  w  . ja  v  a2s.co m
public JavaMailSenderImpl() {
    ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap();
    fileTypeMap.afterPropertiesSet();
    this.defaultFileTypeMap = fileTypeMap;
}