Search in sources :

Example 21 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.

the class PortletEntityRegistryImplTest method testPersistentWithPrefsNotInDb.

//persistent with prefs & not in db - create new & update
@Test
public void testPersistentWithPrefsNotInDb() throws Throwable {
    final IPortletDefinitionId portDefId1 = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    //Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portDefId1.getStringId());
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            //T1 - Create the entity
            final IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portDefId1, nodeId, 12);
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            return portletEntity.getPortletEntityId();
        }
    });
    /*
         * T1 create entity
         * T1 add preference, making persistent
         * T2 delete preference, making interim
         * T1 add preference 2 to persistent, stays persistent
         */
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            //Add a preference
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
            preferences.add(portletPreference);
            //Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //T1 - Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(1, preferences.size());
            //T2 - get the entity and add preferences
            final IPortletEntityId localPortletEntityId = executeInThread("T2.1", new Callable<IPortletEntityId>() {

                @Override
                public IPortletEntityId call() throws Exception {
                    //T2 - Get entity
                    final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId.getStringId());
                    assertEquals(portletEntity, portletEntity);
                    //T2 - add preference
                    final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
                    preferences.clear();
                    //T2 - Store the entity
                    portletEntityRegistry.storePortletEntity(request, portletEntity);
                    return portletEntity.getPortletEntityId();
                }
            });
            //T2 - verify entity was made persistent
            executeInThread("T2.2", new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    //T2 - Verify it was converted from persistent to interim
                    final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, localPortletEntityId);
                    assertNotNull(portletEntity);
                    assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
                    final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
                    assertEquals(0, preferences.size());
                    return null;
                }
            });
            //T1 - add preference 2
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref2", false, "value");
            preferences.add(portletPreference);
            //T1 - Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //T1 - Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(2, preferences.size());
            return null;
        }
    });
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Callable(java.util.concurrent.Callable) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 22 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.

the class PortletEntityRegistryImplTest method testPersistentUpdatingPrefs.

//persistent with prefs & in db - update
@Test
public void testPersistentUpdatingPrefs() throws Exception {
    final IPortletDefinitionId portletDefId = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    //Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portletDefId.getStringId());
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            //Create the entity
            IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portletDefId, nodeId, 12);
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            return portletEntity.getPortletEntityId();
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            //Add a preference
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
            preferences.add(portletPreference);
            //Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(1, preferences.size());
            //add another preference
            final PortletPreferenceImpl portletPreference = new PortletPreferenceImpl("pref2", false, "valuea");
            preferences.add(portletPreference);
            //Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(2, preferences.size());
            return null;
        }
    });
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 23 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.

the class PortletEntityRegistryImplTest method testPersistentNoPrefsNotInDb.

//persistent with no prefs & not in db - noop
@Test
public void testPersistentNoPrefsNotInDb() throws Throwable {
    final IPortletDefinitionId portDefId1 = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    //Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portDefId1.getStringId());
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            //T1 - Create the entity
            final IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portDefId1, nodeId, 12);
            ;
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            return portletEntity.getPortletEntityId();
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            //Add a preference
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
            preferences.add(portletPreference);
            //Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //T1 - Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(1, preferences.size());
            //T2 - get the entity and add preferences
            final IPortletEntityId localPortletEntityId = executeInThread("T2.1", new Callable<IPortletEntityId>() {

                @Override
                public IPortletEntityId call() throws Exception {
                    //T2 - Get entity
                    final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId.getStringId());
                    assertEquals(portletEntity, portletEntity);
                    //T2 - remove preferences
                    final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
                    preferences.clear();
                    //T2 - Store the entity
                    portletEntityRegistry.storePortletEntity(request, portletEntity);
                    return portletEntity.getPortletEntityId();
                }
            });
            //T2 - verify entity was made persistent
            executeInThread("T2.2", new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    //T2 - Verify it was converted from persistent to interim
                    IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, localPortletEntityId);
                    assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
                    List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
                    assertEquals(0, preferences.size());
                    return null;
                }
            });
            //T1 - remove all preferences
            preferences.clear();
            //T1 - Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //T1 - Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(0, preferences.size());
            return null;
        }
    });
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Callable(java.util.concurrent.Callable) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 24 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.

the class PortletEntityRegistryImplTest method testInterimAddingPrefsAlreadyPersistent.

//interim with prefs & in db - get db version & update
@Test
public void testInterimAddingPrefsAlreadyPersistent() throws Throwable {
    final IPortletDefinitionId portDefId1 = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    //Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portDefId1.getStringId());
    /*
         * T1 - create ientity
         * T2 - get ientity
         * T2 - add pref and store ientity converting it to pentity
         * T1 - add pref to ientity and store
         */
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            //T1 - Create the entity
            final IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portDefId1, nodeId, 12);
            ;
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            //T2 - get the entity and add preferences
            final IPortletEntityId portletEntityId = executeInThread("T2.1", new Callable<IPortletEntityId>() {

                @Override
                public IPortletEntityId call() throws Exception {
                    //T2 - Get entity
                    final IPortletEntity localPortletEntity = portletEntityRegistry.getPortletEntity(request, portletEntity.getPortletEntityId().getStringId());
                    assertEquals(portletEntity, localPortletEntity);
                    //T2 - Add a preference
                    final List<IPortletPreference> preferences = localPortletEntity.getPortletPreferences();
                    final IPortletPreference portletPreference = new PortletPreferenceImpl("pref2", false, "value");
                    preferences.add(portletPreference);
                    //T2 - Store the entity
                    portletEntityRegistry.storePortletEntity(request, localPortletEntity);
                    return localPortletEntity.getPortletEntityId();
                }
            });
            //T2 - verify entity was made persistent
            executeInThread("T2.2", new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    //T2 - Verify it was converted from interim to persistent
                    IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
                    assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
                    List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
                    assertEquals(1, preferences.size());
                    return null;
                }
            });
            //T1 - Add a preference
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref1", false, "value");
            preferences.add(portletPreference);
            //T1 - Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return portletEntity.getPortletEntityId();
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //T1 - Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(1, preferences.size());
            return null;
        }
    });
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Callable(java.util.concurrent.Callable) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 25 with IPortletDefinitionId

use of org.apereo.portal.portlet.om.IPortletDefinitionId in project uPortal by Jasig.

the class PortletEntityRegistryImplTest method testInterimAddingPrefs.

//interim with prefs & not in db - create new & update, delete interim
@Test
public void testInterimAddingPrefs() throws Exception {
    final IPortletDefinitionId portletDefId = this.createDefaultPorltetDefinition();
    final String nodeId = "u1l1n1";
    //Mock setup
    final MockHttpServletRequest request = new MockHttpServletRequest();
    when(portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(portalRequestUtils.getOriginalPortletOrPortalRequest(request)).thenReturn(request);
    when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
    when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
    when(userInstance.getPerson()).thenReturn(person);
    when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
    when(userLayoutManager.getNode(nodeId)).thenReturn(node);
    when(node.getType()).thenReturn(LayoutNodeType.PORTLET);
    when(node.getChannelPublishId()).thenReturn(portletDefId.getStringId());
    final IPortletEntityId portletEntityId = this.execute(new Callable<IPortletEntityId>() {

        @Override
        public IPortletEntityId call() throws Exception {
            //Create the entity
            IPortletEntity portletEntity = portletEntityRegistry.getOrCreatePortletEntity(request, portletDefId, nodeId, 12);
            assertEquals(SessionPortletEntityImpl.class, portletEntity.getClass());
            return portletEntity.getPortletEntityId();
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            //Add a preference
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            final IPortletPreference portletPreference = new PortletPreferenceImpl("pref", false, "value");
            preferences.add(portletPreference);
            //Store the entity
            portletEntityRegistry.storePortletEntity(request, portletEntity);
            return null;
        }
    });
    this.execute(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            //Verify it was converted from interim to persistent
            final IPortletEntity portletEntity = portletEntityRegistry.getPortletEntity(request, portletEntityId);
            assertEquals(PersistentPortletEntityWrapper.class, portletEntity.getClass());
            final List<IPortletPreference> preferences = portletEntity.getPortletPreferences();
            assertEquals(1, preferences.size());
            return null;
        }
    });
}
Also used : IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) PortletPreferenceImpl(org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Aggregations

IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)28 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)15 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)14 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)12 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)11 Test (org.junit.Test)11 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)10 List (java.util.List)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 Callable (java.util.concurrent.Callable)4 Preference (org.apache.pluto.container.om.portlet.Preference)3 Preferences (org.apache.pluto.container.om.portlet.Preferences)3 IUserInstance (org.apereo.portal.user.IUserInstance)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 Element (net.sf.ehcache.Element)2