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.document.library.service.test.PDFProcessorTest.java
License:Open Source License
@Test public void testShouldCreateNewPreviewOnUpdateWithContent() throws Exception { AtomicInteger count = registerPDFProcessorMessageListener(EventType.GENERATE_NEW); 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.updateFileEntry(fileEntry.getFileEntryId(), StringUtil.randomString() + ".pdf", ContentTypes.APPLICATION_PDF, StringUtil.randomString(), StringUtil.randomString(), StringUtil.randomString(), true, FileUtil.getBytes(getClass(), "dependencies/test.pdf"), _serviceContext);/*from w w w . j a v a 2s . c o m*/ Assert.assertEquals(2, count.get()); }
From source file:com.liferay.document.library.verify.test.DLServiceVerifyProcessTest.java
License:Open Source License
protected DLFileEntry addDLFileEntry() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, TestPropsValues.getUserId()); byte[] bytes = FileUtil.getBytes(getClass(), "/com/liferay/document/library/service/test/dependencies" + "/ddmstructure.xml"); com.liferay.dynamic.data.mapping.model.DDMForm ddmForm = _ddmFormXSDDeserializer .deserialize(new String(bytes)); serviceContext.setAttribute("ddmForm", DDMBeanTranslatorUtil.translate(ddmForm)); User user = TestPropsValues.getUser(); serviceContext.setLanguageId(LocaleUtil.toLanguageId(user.getLocale())); DLFileEntryType 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();// w w w .j a v a2 s .co m com.liferay.dynamic.data.mapping.kernel.DDMStructure ddmStructure = ddmStructures.get(0); Map<String, DDMFormValues> ddmFormValuesMap = getDDMFormValuesMap(ddmStructure.getStructureKey(), user.getLocale()); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE)); return 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.webdav.test.WebDAVOSXTest.java
License:Open Source License
@Before public void setUp() throws Exception { Class<?> clazz = getClass(); _testFileBytes = FileUtil.getBytes(clazz, _OFFICE_TEST_DOCX); _testMetaBytes = FileUtil.getBytes(clazz, _OFFICE_TEST_META_DOCX); _testDeltaBytes = FileUtil.getBytes(clazz, _OFFICE_TEST_DELTA_DOCX); servicePut(_TEST_FILE_NAME, _testFileBytes, getLock(_TEST_FILE_NAME)); }
From source file:com.liferay.dynamic.data.lists.internal.exportimport.data.handler.test.DDLRecordStagedModelDataHandlerTest.java
License:Open Source License
protected DDMFormFieldValue createDocumentLibraryDDMFormFieldValue(Locale locale, String fieldName) throws Exception { String fileName = "attachment.txt"; ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId(), TestPropsValues.getUserId()); FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), stagingGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, fileName, ContentTypes.TEXT_PLAIN, FileUtil.getBytes(getClass(), "dependencies/" + fileName), serviceContext); DDMFormFieldValue ddmFormFieldValue = createEmptyDocumentLibraryDDMFormFieldValue(locale, fieldName); JSONObject fieldValueJSONObject = JSONFactoryUtil.createJSONObject(); fieldValueJSONObject.put("groupId", String.valueOf(fileEntry.getGroupId())); fieldValueJSONObject.put("uuid", fileEntry.getUuid()); Value value = ddmFormFieldValue.getValue(); value.addString(locale, fieldValueJSONObject.toJSONString()); return ddmFormFieldValue; }
From source file:com.liferay.message.boards.service.test.MBMessageLocalServiceTest.java
License:Open Source License
@Test public void testAddMessageAttachment() throws Exception { MBMessage message = addMessage(null, false); byte[] fileBytes = FileUtil.getBytes(getClass(), "dependencies/company_logo.png"); File file = FileUtil.createTempFile(fileBytes); MBMessageLocalServiceUtil.addMessageAttachment(TestPropsValues.getUserId(), message.getMessageId(), "test", file, "image/png"); Assert.assertEquals(1, message.getAttachmentsFileEntriesCount()); }
From source file:com.liferay.message.boards.service.test.MBMessageLocalServiceTest.java
License:Open Source License
@Test public void testDeleteMessageAttachment() throws Exception { MBMessage message = addMessage(null, false); byte[] fileBytes = FileUtil.getBytes(getClass(), "dependencies/company_logo.png"); File file = FileUtil.createTempFile(fileBytes); MBMessageLocalServiceUtil.addMessageAttachment(TestPropsValues.getUserId(), message.getMessageId(), "test", file, "image/png"); Assert.assertEquals(1, message.getAttachmentsFileEntriesCount()); MBMessageLocalServiceUtil.deleteMessageAttachment(message.getMessageId(), "test"); Assert.assertEquals(0, message.getAttachmentsFileEntriesCount()); }
From source file:com.liferay.social.activity.service.test.BaseSocialActivityTestCase.java
License:Open Source License
@BeforeClass public static void setUpClass() throws Exception { userClassNameId = PortalUtil.getClassNameId(User.class.getName()); Class<?> clazz = SocialActivitySettingLocalServiceTest.class; String xml = new String(FileUtil.getBytes(clazz, "dependencies/liferay-social.xml")); SocialConfigurationUtil.read(clazz.getClassLoader(), new String[] { xml }); }
From source file:com.liferay.wiki.service.test.WikiNodeLocalServiceTest.java
License:Open Source License
@Test public void testImportPages() throws Exception { _node = WikiTestUtil.addNode(TestPropsValues.getGroupId()); ProgressTracker progressTracker = new ProgressTracker(StringUtil.randomString()); ProgressTrackerThreadLocal.setProgressTracker(progressTracker); byte[] bytes = FileUtil.getBytes(getClass(), "/com/liferay/wiki/service/test/dependencies" + "/liferay_media_wiki.xml"); InputStream is = new ByteArrayInputStream(bytes); WikiNodeLocalServiceUtil.importPages(TestPropsValues.getUserId(), _node.getNodeId(), "MediaWiki", new InputStream[] { is, null, null }, Collections.<String, String[]>emptyMap()); WikiPage importedPage = WikiPageLocalServiceUtil.fetchPage(_node.getNodeId(), "Liferay"); Assert.assertNotNull(importedPage);/*from w ww . jav a 2s . co m*/ }
From source file:com.liferay.wiki.util.test.WikiTestUtil.java
License:Open Source License
public static File addWikiAttachment(long userId, long nodeId, String title, String fileName, Class<?> clazz) throws Exception { byte[] fileBytes = FileUtil.getBytes(clazz, "dependencies/OSX_Test.docx"); File file = null;//from w w w .ja v a 2s .com if (ArrayUtil.isNotEmpty(fileBytes)) { file = FileUtil.createTempFile(fileBytes); } String mimeType = MimeTypesUtil.getExtensionContentType("docx"); WikiPageLocalServiceUtil.addPageAttachment(userId, nodeId, title, fileName, file, mimeType); return file; }