List of usage examples for com.liferay.portal.kernel.util FileUtil getBytes
public static byte[] getBytes(InputStream is, int bufferSize) throws IOException
From source file:com.liferay.adaptive.media.image.service.impl.test.AMImageEntryLocalServiceImplTest.java
License:Open Source License
private byte[] _getImageBytes() throws Exception { return FileUtil.getBytes(AMImageEntryLocalServiceImplTest.class, "/com/liferay/adaptive/media/image/dependencies/image.jpg"); }
From source file:com.liferay.adaptive.media.image.service.impl.test.AMImageEntryLocalServiceTest.java
License:Open Source License
private byte[] _getImageBytes() throws Exception { return FileUtil.getBytes(AMImageEntryLocalServiceTest.class, "/com/liferay/adaptive/media/image/dependencies/image.jpg"); }
From source file:com.liferay.bookmarks.web.internal.social.BookmarksSocialActivityConfigurator.java
License:Open Source License
@Activate protected void activate() throws Exception { Class<?> clazz = getClass(); String xml = new String(FileUtil.getBytes(getClass(), "/META-INF/social/liferay-social.xml")); SocialConfigurationUtil.read(clazz.getClassLoader(), new String[] { xml }); }
From source file:com.liferay.document.library.convert.test.DocumentLibraryConvertProcessTest.java
License:Open Source License
protected Image addImage() throws Exception { return ImageLocalServiceUtil.updateImage(CounterLocalServiceUtil.increment(), FileUtil.getBytes(getClass(), "dependencies/liferay.jpg")); }
From source file:com.liferay.document.library.convert.test.DocumentLibraryConvertProcessTest.java
License:Open Source License
protected void testMigrateAndCheckOldRepositoryFiles(Boolean delete) throws Exception { _convertProcess.setParameterValues(new String[] { _CLASS_NAME_DB_STORE, delete.toString() }); FileEntry rootFileEntry = addFileEntry(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString() + ".txt", ContentTypes.TEXT_PLAIN, RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE)); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), TestPropsValues.getUserId()); Folder folder = DLAppServiceUtil.addFolder(_group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext); FileEntry folderFileEntry = addFileEntry(folder.getFolderId(), "liferay.jpg", ContentTypes.IMAGE_JPEG, FileUtil.getBytes(getClass(), "dependencies/liferay.jpg")); ImageProcessorUtil.generateImages(null, folderFileEntry.getFileVersion()); _convertProcess.convert();// ww w .jav a 2s. com DLFileEntry rootDLFileEntry = (DLFileEntry) rootFileEntry.getModel(); Assert.assertNotEquals(delete, _sourceStore.hasFile(rootDLFileEntry.getCompanyId(), rootDLFileEntry.getDataRepositoryId(), rootDLFileEntry.getName())); DLFileEntry folderDLFileEntry = (DLFileEntry) folderFileEntry.getModel(); DLProcessor imageProcessor = DLProcessorRegistryUtil.getDLProcessor(DLProcessorConstants.IMAGE_PROCESSOR); if (imageProcessor instanceof ImageProcessorImpl) { Assert.assertNotEquals(delete, _sourceStore.hasDirectory(folderDLFileEntry.getCompanyId(), DLPreviewableProcessor.REPOSITORY_ID, DLPreviewableProcessor.THUMBNAIL_PATH)); } Assert.assertNotEquals(delete, _sourceStore.hasFile(folderDLFileEntry.getCompanyId(), folderDLFileEntry.getDataRepositoryId(), folderDLFileEntry.getName())); DLContentLocalServiceUtil.getContent( folderDLFileEntry.getCompanyId(), DLFolderConstants .getDataRepositoryId(folderDLFileEntry.getRepositoryId(), folderDLFileEntry.getFolderId()), folderDLFileEntry.getName()); DLContentLocalServiceUtil.getContent( rootDLFileEntry.getCompanyId(), DLFolderConstants .getDataRepositoryId(rootDLFileEntry.getRepositoryId(), rootDLFileEntry.getFolderId()), rootDLFileEntry.getName()); }
From source file:com.liferay.document.library.internal.exportimport.data.handler.test.FileEntryStagedModelDataHandlerTest.java
License:Open Source License
@Test public void testExportImportFileExtension() throws Exception { String fileName = "PDF_Test.pdf"; ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId(), TestPropsValues.getUserId()); FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), stagingGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, fileName, ContentTypes.APPLICATION_PDF, FileUtil.getBytes(getClass(), "dependencies/" + fileName), serviceContext);/*from w ww .j a v a 2s . co m*/ exportImportStagedModel(fileEntry); FileEntry importedFileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId()); Assert.assertEquals("pdf", importedFileEntry.getExtension()); String title = RandomTestUtil.randomString() + ".awesome"; DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), StringPool.BLANK, ContentTypes.TEXT_PLAIN, title, StringPool.BLANK, StringPool.BLANK, false, (byte[]) null, serviceContext); exportImportStagedModel(fileEntry); importedFileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId()); Assert.assertEquals("pdf", importedFileEntry.getExtension()); }
From source file:com.liferay.document.library.service.test.DLFileEntryMetadataLocalServiceTest.java
License:Open Source License
@Before public void setUp() throws Exception { setUpDDMFormXSDDeserializer();/*from w w w . j a v a2 s . c o m*/ _group = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, TestPropsValues.getUserId()); byte[] testFileBytes = FileUtil.getBytes(getClass(), "dependencies/ddmstructure.xml"); com.liferay.dynamic.data.mapping.model.DDMForm ddmForm = _ddmFormXSDDeserializer .deserialize(new String(testFileBytes)); serviceContext.setAttribute("ddmForm", DDMBeanTranslatorUtil.translate(ddmForm)); User user = TestPropsValues.getUser(); serviceContext.setLanguageId(LocaleUtil.toLanguageId(user.getLocale())); _dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType(TestPropsValues.getUserId(), _group.getGroupId(), RandomTestUtil.randomString(), StringPool.BLANK, new long[0], serviceContext); List<com.liferay.dynamic.data.mapping.kernel.DDMStructure> ddmStructures = _dlFileEntryType .getDDMStructures(); _ddmStructure = DDMStructureLocalServiceUtil.getStructure(ddmStructures.get(0).getStructureId()); Map<String, DDMFormValues> ddmFormValuesMap = setUpDDMFormValuesMap(_ddmStructure.getStructureKey(), user.getLocale()); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE)); _dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), _group.getGroupId(), _group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(), null, RandomTestUtil.randomString(), null, null, _dlFileEntryType.getFileEntryTypeId(), ddmFormValuesMap, null, byteArrayInputStream, byteArrayInputStream.available(), serviceContext); }
From source file:com.liferay.document.library.service.test.DLFileEntryTypeServiceTest.java
License:Open Source License
@Test public void testAddFileEntryTypeWithNonemptyDDMForm() throws Exception { ServiceContext serviceContext = new ServiceContext(); byte[] testFileBytes = FileUtil.getBytes(getClass(), _TEST_DDM_STRUCTURE); DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(new String(testFileBytes)); serviceContext.setAttribute("ddmForm", DDMBeanTranslatorUtil.translate(ddmForm)); User user = TestPropsValues.getUser(); serviceContext.setLanguageId(LocaleUtil.toLanguageId(user.getLocale())); DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( TestPropsValues.getUserId(), _group.getGroupId(), "Test Structure", StringPool.BLANK, new long[0], serviceContext);//from w ww . j a v a2 s .c o m List<com.liferay.dynamic.data.mapping.kernel.DDMStructure> ddmStructures = dlFileEntryType .getDDMStructures(); Assert.assertEquals(ddmStructures.toString(), 1, ddmStructures.size()); DDMStructure ddmStructure = DDMStructureLocalServiceUtil .getStructure(ddmStructures.get(0).getStructureId()); Locale[] availableLocales = LocaleUtil.fromLanguageIds(ddmStructure.getAvailableLanguageIds()); boolean hasDefaultLocale = ArrayUtil.contains(availableLocales, LocaleUtil.getSiteDefault()); Assert.assertTrue(hasDefaultLocale); boolean hasHungarianLocale = ArrayUtil.contains(availableLocales, LocaleUtil.HUNGARY); Assert.assertTrue(hasHungarianLocale); boolean hasUserLocale = ArrayUtil.contains(availableLocales, user.getLocale()); Assert.assertTrue(hasUserLocale); DLFileEntryTypeLocalServiceUtil.deleteDLFileEntryType(dlFileEntryType); }
From source file:com.liferay.document.library.service.test.PDFProcessorTest.java
License:Open Source License
@Test public void testShouldCleanUpProcessorsOnCancelCheckOut() throws Exception { AtomicBoolean cleanUp = registerCleanUpDLProcessor(); FileEntry fileEntry = DLAppServiceUtil.addFileEntry(_serviceContext.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, StringUtil.randomString() + ".pdf", ContentTypes.APPLICATION_PDF, StringUtil.randomString(), StringUtil.randomString(), StringUtil.randomString(), FileUtil.getBytes(getClass(), "dependencies/test.pdf"), _serviceContext); DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), _serviceContext); DLAppServiceUtil.cancelCheckOut(fileEntry.getFileEntryId()); Assert.assertTrue(cleanUp.get());/*from www . j av a2s . co m*/ }
From source file:com.liferay.document.library.service.test.PDFProcessorTest.java
License:Open Source License
@Test public void testShouldCleanUpProcessorsOnDelete() throws Exception { AtomicBoolean cleanUp = registerCleanUpDLProcessor(); FileEntry fileEntry = DLAppServiceUtil.addFileEntry(_serviceContext.getScopeGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, StringUtil.randomString() + ".pdf", ContentTypes.APPLICATION_PDF, StringUtil.randomString(), StringUtil.randomString(), StringUtil.randomString(), FileUtil.getBytes(getClass(), "dependencies/test.pdf"), _serviceContext); DLAppServiceUtil.deleteFileEntry(fileEntry.getFileEntryId()); Assert.assertTrue(cleanUp.get());/* w w w . j a v a2 s . c o m*/ }