public void testClone() throws Exception { PortletContext original = PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false); PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original); ExtendedAssert.assertNotNull(clone); ExtendedAssert.assertFalse(original.equals(clone)); ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE, clone.getId()); Portlet originalPortlet = consumer.getPortlet(original); Portlet clonePortlet = consumer.getPortlet(clone); ExtendedAssert.assertNotNull(clonePortlet); ExtendedAssert.assertFalse(originalPortlet.getContext().equals(clonePortlet.getContext())); // information about the portlet should be the same MetaInfo originalInfo = originalPortlet.getInfo().getMeta(); MetaInfo cloneInfo = clonePortlet.getInfo().getMeta(); ExtendedAssert.assertEquals( originalInfo.getMetaValue(MetaInfo.TITLE), cloneInfo.getMetaValue(MetaInfo.TITLE)); ExtendedAssert.assertEquals( originalInfo.getMetaValue(MetaInfo.DESCRIPTION), cloneInfo.getMetaValue(MetaInfo.DESCRIPTION)); }
public void testDestroyClones() throws Exception { // switch the behavior for portlet management BehaviorRegistry behaviorRegistry = producer.getBehaviorRegistry(); behaviorRegistry.setPortletManagementBehavior( new DestroyClonesPortletManagementBehavior(behaviorRegistry)); PortletContext original = PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false); PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original); ExtendedAssert.assertNotNull(clone); Portlet portlet = consumer.getPortlet(clone); ExtendedAssert.assertNotNull(portlet); ExtendedAssert.assertEquals( BasicPortletManagementBehavior.CLONED_HANDLE, portlet.getContext().getId()); List clones = new ArrayList(1); clones.add(clone); List result = consumer.destroyClones(clones); ExtendedAssert.assertTrue(result.isEmpty()); try { consumer.getPortlet(clone); ExtendedAssert.fail("Should have failed: clone should not exist anymore!"); } catch (PortletInvokerException expected) { } // re-create clone and try again with an added invalid portlet context clone = consumer.createClone(PortletStateType.OPAQUE, original); PortletContext invalidContext = PortletContext.createPortletContext("invalid", false); clones.add(invalidContext); result = consumer.destroyClones(clones); ExtendedAssert.assertEquals(1, result.size()); DestroyCloneFailure failure = (DestroyCloneFailure) result.get(0); ExtendedAssert.assertEquals("invalid", failure.getPortletId()); try { consumer.getPortlet(clone); ExtendedAssert.fail("Should have failed: clone should not exist anymore!"); } catch (PortletInvokerException expected) { } }