Package org.jtalks.jcommune.service.exceptions

Examples of org.jtalks.jcommune.service.exceptions.ImageFormatException


     */
    public void validateImageFormat(MultipartFile file) throws ImageFormatException {
        Validate.notNull(file, "file argument array cannot be null");
        if (!VALID_IMAGE_TYPES.contains(file.getContentType())) {
            LOGGER.debug("Wrong file extension. May be only {}", VALID_IMAGE_EXTENSIONS);
            throw new ImageFormatException(VALID_IMAGE_EXTENSIONS);
        }
    }
View Full Code Here


        InputStream input = new ByteArrayInputStream(bytes);
        try {
            String type = tika.detect(input);
            if (!VALID_IMAGE_TYPES.contains(type)) {
                LOGGER.debug("Wrong file extension. May be only {}", VALID_IMAGE_EXTENSIONS);
                throw new ImageFormatException(VALID_IMAGE_EXTENSIONS);
            }
        } catch (IOException e) {
            LOGGER.error("Failed to handle image ByteArrayInputStream", e);
        }
    }
View Full Code Here

    @Test
    public void userSetIncorrectAvatarShouldGetDefaultAvatar() throws ImageProcessException, NotFoundException {
        //ARRANGE
        byte[] avatar = new byte[10];
        doThrow(new ImageFormatException("test")).when(imageService).validateImageFormat(any(byte[].class));
        doThrow(new ImageSizeException(1)).when(imageService).validateImageSize(any(byte[].class));
        //ACT
        defaultAvatarEditor.setAsText(String.valueOf(avatar));
        //ASSERT
        verify(imageService, times(1)).getDefaultImage();
View Full Code Here

                imageUploadController.WRONG_FORMAT_RESOURCE_MESSAGE,
                new Object[]{validTypes},
                locale)
        ).thenReturn(expectedMessage);

        FailJsonResponse result = imageUploadController.handleImageFormatException(new ImageFormatException(validTypes), locale);

        assertEquals(result.getStatus(), JsonResponseStatus.FAIL, "We have an exception, so we should get false value.");
        assertEquals(result.getReason(), JsonResponseReason.VALIDATION, "Failture reason should be validation");
        assertEquals(result.getResult(), expectedMessage, "Result contains incorrect message.");
    }
View Full Code Here

TOP

Related Classes of org.jtalks.jcommune.service.exceptions.ImageFormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.