List of usage examples for com.liferay.portal.kernel.model Portlet clone
public Object clone();
From source file:com.liferay.layout.type.controller.test.LayoutTypePortletTest.java
License:Open Source License
@Test public void testGetAllPortlets() throws Exception { Layout layout = _layoutTypePortlet.getLayout(); _user = UserTestUtil.addUser(layout.getGroupId()); List<Portlet> initialPortlets = _layoutTypePortlet.getAllPortlets(); int initialPortletsSize = initialPortlets.size(); final String portletId = _layoutTypePortlet.addPortletId(_user.getUserId(), PortletKeys.TEST); List<Portlet> portlets = _layoutTypePortlet.getAllPortlets(); Assert.assertEquals(portlets.toString(), initialPortletsSize + 1, portlets.size()); final long companyId = TestPropsValues.getCompanyId(); final PortletLocalService portletLocalService = PortletLocalServiceUtil.getService(); final Method getPortletByIdMethod = PortletLocalService.class.getMethod("getPortletById", long.class, String.class); ReflectionTestUtil.setFieldValue(PortletLocalServiceUtil.class, "_service", ProxyUtil.newProxyInstance(PortletLocalService.class.getClassLoader(), new Class<?>[] { PortletLocalService.class }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (getPortletByIdMethod.equals(method)) { Portlet portlet = (Portlet) method.invoke(portletLocalService, args); if ((companyId == (long) args[0]) && portletId.equals(args[1])) { portlet = (Portlet) portlet.clone(); portlet.setUndeployedPortlet(true); }//from w w w . j a va 2 s . c o m return portlet; } return method.invoke(portletLocalService, args); } })); try { portlets = _layoutTypePortlet.getAllPortlets(); Assert.assertEquals(portlets.toString(), initialPortletsSize + 1, portlets.size()); } finally { ReflectionTestUtil.setFieldValue(PortletLocalServiceUtil.class, "_service", portletLocalService); } }