Example usage for com.liferay.portal.kernel.search IndexWriterHelperUtil isIndexReadOnly

List of usage examples for com.liferay.portal.kernel.search IndexWriterHelperUtil isIndexReadOnly

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search IndexWriterHelperUtil isIndexReadOnly.

Prototype

@Deprecated
public static boolean isIndexReadOnly() 

Source Link

Usage

From source file:com.liferay.document.library.service.test.DLFileEntryLocalServiceTest.java

License:Open Source License

@Test
public void testGetOrphanedFileEntries() throws Exception {
    DLFolder dlFolder = DLTestUtil.addDLFolder(_group.getGroupId());

    byte[] bytes = RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE);

    InputStream is = new ByteArrayInputStream(bytes);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(dlFolder.getGroupId());

    FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(),
            dlFolder.getRepositoryId(), dlFolder.getFolderId(), RandomTestUtil.randomString(),
            ContentTypes.TEXT_PLAIN, RandomTestUtil.randomString(), StringPool.BLANK, StringPool.BLANK, is,
            bytes.length, serviceContext);

    boolean indexReadOnly = IndexWriterHelperUtil.isIndexReadOnly();

    DLFileEntry dlFileEntry = null;/* w  w w  .j  a  v  a 2 s  . c  o  m*/

    try {
        IndexWriterHelperUtil.setIndexReadOnly(true);

        dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntry(fileEntry.getFileEntryId());

        dlFileEntry.setGroupId(10000L);

        DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry);

        List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getOrphanedFileEntries();

        Assert.assertEquals(dlFileEntries.toString(), 1, dlFileEntries.size());
        Assert.assertEquals(dlFileEntry, dlFileEntries.get(0));
    } finally {
        if (dlFileEntry != null) {
            DLFileEntryLocalServiceUtil.deleteDLFileEntry(dlFileEntry.getFileEntryId());
        }

        IndexWriterHelperUtil.setIndexReadOnly(indexReadOnly);
    }
}