Example usage for com.liferay.portal.kernel.bean PortalBeanLocatorUtil setBeanLocator

List of usage examples for com.liferay.portal.kernel.bean PortalBeanLocatorUtil setBeanLocator

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.bean PortalBeanLocatorUtil setBeanLocator.

Prototype

public static void setBeanLocator(BeanLocator beanLocator) 

Source Link

Usage

From source file:de.fhg.fokus.odp.boxes.BlogsTest.java

License:Open Source License

@Before
public void setup() throws Exception {
    multiVMPoolUtil.setMultiVMPool(multiVMPool);
    PortalBeanLocatorUtil.setBeanLocator(beanLocatorMock);

    Mockito.when(beanLocatorMock.locate(BlogsEntryLocalService.class.getCanonicalName()))
            .thenReturn(blogsEntryLocalService);

    // reset private static field "_service"
    Field field = BlogsEntryLocalServiceUtil.class.getDeclaredField("_service");
    field.setAccessible(true);/*from   w  ww  .  j  ava  2  s  . c o m*/
    field.set(null, null);
    field.setAccessible(false);

    // return every time an empty cache
    Mockito.when(multiVMPool.getCache(CACHE_NAME)).thenAnswer(new Answer<PortalCache<String, Serializable>>() {
        @Override
        public PortalCache<String, Serializable> answer(InvocationOnMock invocation) throws Throwable {
            return portalCache;
        }
    });
}

From source file:de.seitenbau.govdata.odp.boxes.BlogsTest.java

License:Open Source License

@Before
public void setup() throws Exception {
    multiVMPoolUtil.setMultiVMPool(multiVMPool);
    PortalBeanLocatorUtil.setBeanLocator(beanLocatorMock);

    Mockito.when(beanLocatorMock.locate(BlogsEntryLocalService.class.getCanonicalName()))
            .thenReturn(blogsEntryLocalService);

    // reset private static field "_service"
    Field field = BlogsEntryLocalServiceUtil.class.getDeclaredField("_service");
    field.setAccessible(true);//from   w w  w .  j  av  a 2  s  .c o  m
    field.set(null, null);
    field.setAccessible(false);

    // return every time an empty cache
    Mockito.when(multiVMPool.getCache(BaseCache.CACHE_NAME_BOXES))
            .thenAnswer(new Answer<PortalCache<String, Serializable>>() {
                @Override
                public PortalCache<String, Serializable> answer(InvocationOnMock invocation) throws Throwable {
                    return portalCache;
                }
            });
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.portal.LiferayTestHelper.java

License:Apache License

/**
 * Einmalige Instanzierung der Mocks, Registrierung und Initialisierung
 *//*from   ww w  .j av  a2  s  .c o  m*/
private LiferayTestHelper() {
    MockitoAnnotations.initMocks(this);

    when(beanLocatorMock.locate(CompanyLocalService.class.getName())).thenReturn(companyLocalServiceMock);

    // when(beanLocatorMock.locate(PermissionCheckerFactory.class.getName()))
    // .thenReturn(permissionCheckerFactoryMock);
    // old style needed here:
    new PermissionCheckerFactoryUtil().setPermissionCheckerFactory(permissionCheckerFactoryMock);

    when(beanLocatorMock.locate(UserLocalService.class.getName())).thenReturn(userLocalServiceMock);
    when(beanLocatorMock.locate(RoleLocalService.class.getName())).thenReturn(roleLocalService);
    when(beanLocatorMock.locate(ResourceLocalService.class.getName())).thenReturn(resourceLocalService);
    when(beanLocatorMock.locate(PermissionLocalService.class.getName())).thenReturn(permissionLocalService);
    when(beanLocatorMock.locate(LayoutLocalService.class.getName())).thenReturn(layoutLocalServiceMock);

    PortalBeanLocatorUtil.setBeanLocator(beanLocatorMock);

    initializeMocks();
}