Example usage for com.liferay.portal.kernel.test ReflectionTestUtil getAndSetFieldValue

List of usage examples for com.liferay.portal.kernel.test ReflectionTestUtil getAndSetFieldValue

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.test ReflectionTestUtil getAndSetFieldValue.

Prototype

public static <T> T getAndSetFieldValue(Object instance, String fieldName, T newValue) 

Source Link

Usage

From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java

License:Open Source License

@Test
public void testExportLayoutReferencesWithContext() throws Exception {
    PortalImpl portalImpl = new PortalImpl() {

        @Override/*from  w w w.j  a  va 2 s  .co m*/
        public String getPathContext() {
            return "/de";
        }

    };

    PortalUtil portalUtil = new PortalUtil();

    portalUtil.setPortal(portalImpl);

    Portal originalPortal = ReflectionTestUtil
            .getAndSetFieldValue(_layoutReferencesExportImportContentProcessor, "_portal", portalImpl);

    _oldLayoutFriendlyURLPrivateUserServletMapping = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;

    setFinalStaticField(PropsValues.class.getField("LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING"), "/en");

    Class<?> clazz = _layoutReferencesExportImportContentProcessor.getClass();

    setFinalStaticField(clazz.getDeclaredField("_PRIVATE_USER_SERVLET_MAPPING"), "/en/");

    String content = replaceParameters(getContent("layout_references.txt"), _fileEntry);

    _exportImportContentProcessor.validateContentReferences(_stagingGroup.getGroupId(), content);

    content = _exportImportContentProcessor.replaceExportContentReferences(_portletDataContextExport,
            _referrerStagedModel, content, true, true);

    Assert.assertFalse(content, content.contains(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR));
    Assert.assertFalse(content, content.contains(GroupConstants.CONTROL_PANEL_FRIENDLY_URL));
    Assert.assertFalse(content, content.contains(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL));
    Assert.assertFalse(content,
            content.contains(PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING));
    Assert.assertFalse(content, content.contains(PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING));
    Assert.assertTrue(content,
            content.contains("@data_handler_group_friendly_url@@" + _stagingGroup.getFriendlyURL() + "@"));
    Assert.assertTrue(content, content.contains("@data_handler_path_context@/en@"));
    Assert.assertFalse(content, content.contains("@data_handler_path_context@/de@"));

    setFinalStaticField(PropsValues.class.getDeclaredField("LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING"),
            _oldLayoutFriendlyURLPrivateUserServletMapping);

    setFinalStaticField(clazz.getDeclaredField("_PRIVATE_USER_SERVLET_MAPPING"),
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING + StringPool.SLASH);

    portalUtil.setPortal(new PortalImpl());

    ReflectionTestUtil.setFieldValue(_layoutReferencesExportImportContentProcessor, "_portal", originalPortal);
}