Unit tests for Liferay portlets

后端 未结 3 1584
有刺的猬
有刺的猬 2021-01-03 07:18

Does anyone know how to run unit tests for Liferay portlets? I have found a lot of posts about it (e.g. http://agile-reflections.opnworks.com/2010/06/portlet-unit-testing-wi

3条回答
  •  有刺的猬
    2021-01-03 07:48

    You need to have some third party libraries on classpath.

    THe key point is having even portal-impl.jar and other portal dependencies on classpath and having InitUtil.initWithSpring(boolean); load up core spring xml configs that you specify in spring-ext.properties in spring.congigs property, only those services you need. You may need no portal services and only the portlet ones, but this is a problem because your portlet services generated by service builder use the portal services.

    Using service builder just needs good knowledge of spring and classloading.

    But you need to understand the infrastructure before doing that. There are quite a lot of hacks needed... Like

    BeanLocator beanLocator = new BeanLocatorImpl(PortalClassLoaderUtil.getClassLoader(), ac);
    PortletBeanLocatorUtil.setBeanLocator("portlet", beanLocator);
    

提交回复
热议问题