Search in sources :

Example 1 with PortletLifecycleEntryImpl

use of org.apereo.portal.portlet.dao.jpa.PortletLifecycleEntryImpl in project uPortal by Jasig.

the class ExternalPortletDefinitionUnmarshallerTest method testUnmarshallLifecycle.

@Test
public void testUnmarshallLifecycle() {
    final long currentTimeMillis = System.currentTimeMillis();
    final String createdUser = "createdUser";
    final String approvedUser = "approvedUser";
    final String publishedUser = "publishedUser";
    final String expiredUser = "expiredUser";
    final String maintenanceUser = "maintenanceUser";
    final Calendar createdCalendar = getCalendarForMillis(currentTimeMillis - (5L * MILLIS_IN_ONE_DAY));
    final Calendar approvedCalendar = getCalendarForMillis(currentTimeMillis - (4L * MILLIS_IN_ONE_DAY));
    final Calendar publishedCalendar = getCalendarForMillis(currentTimeMillis - (3L * MILLIS_IN_ONE_DAY));
    final Calendar expiredCalendar = getCalendarForMillis(currentTimeMillis + MILLIS_IN_ONE_DAY);
    final Calendar maintenanceCalendar = getCalendarForMillis(currentTimeMillis - (2L * MILLIS_IN_ONE_DAY));
    // Created 5 days in the past
    final LifecycleEntry created = new LifecycleEntry();
    created.setName("CREATED");
    created.setUser(createdUser);
    created.setValue(createdCalendar);
    // Approved 4 days in the past
    final LifecycleEntry approved = new LifecycleEntry();
    approved.setName("APPROVED");
    approved.setUser(approvedUser);
    approved.setValue(approvedCalendar);
    // Published 3 days in the past
    final LifecycleEntry published = new LifecycleEntry();
    published.setName("PUBLISHED");
    published.setUser(publishedUser);
    published.setValue(publishedCalendar);
    // Expired 1 day in the future
    final LifecycleEntry expired = new LifecycleEntry();
    expired.setName("EXPIRED");
    expired.setUser(expiredUser);
    expired.setValue(expiredCalendar);
    // Maintenance mode 2 days in the past
    final LifecycleEntry maintenance = new LifecycleEntry();
    maintenance.setName("MAINTENANCE");
    maintenance.setUser(maintenanceUser);
    maintenance.setValue(maintenanceCalendar);
    final Lifecycle lifecycle1 = new Lifecycle();
    lifecycle1.getEntries().add(created);
    final Lifecycle lifecycle2 = new Lifecycle();
    lifecycle2.getEntries().add(created);
    lifecycle2.getEntries().add(approved);
    final Lifecycle lifecycle3 = new Lifecycle();
    lifecycle3.getEntries().add(published);
    lifecycle3.getEntries().add(expired);
    final Lifecycle lifecycle4 = new Lifecycle();
    lifecycle4.getEntries().add(created);
    lifecycle4.getEntries().add(approved);
    lifecycle4.getEntries().add(published);
    lifecycle4.getEntries().add(maintenance);
    lifecycle4.getEntries().add(expired);
    final Lifecycle[] lifecyclesToTest = new Lifecycle[] { lifecycle1, lifecycle2, lifecycle3, lifecycle4 };
    final IPortletLifecycleEntry[][] expectedPortletLifecycles = new IPortletLifecycleEntry[][] { // 1
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()) }, // 2
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl(approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()) }, // 3
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl(expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) }, // 4
    new IPortletLifecycleEntry[] { new PortletLifecycleEntryImpl(createdUser.hashCode(), PortletLifecycleState.CREATED, createdCalendar.getTime()), new PortletLifecycleEntryImpl(approvedUser.hashCode(), PortletLifecycleState.APPROVED, approvedCalendar.getTime()), new PortletLifecycleEntryImpl(publishedUser.hashCode(), PortletLifecycleState.PUBLISHED, publishedCalendar.getTime()), new PortletLifecycleEntryImpl(maintenanceUser.hashCode(), PortletLifecycleState.MAINTENANCE, maintenanceCalendar.getTime()), new PortletLifecycleEntryImpl(expiredUser.hashCode(), PortletLifecycleState.EXPIRED, expiredCalendar.getTime()) } };
    final ExternalPortletDefinitionUnmarshaller unmarshaller = new ExternalPortletDefinitionUnmarshaller();
    unmarshaller.setUserIdentityStore(new MockUserIdentityStore());
    final IPortletType portletType = new PortletTypeImpl("FakePortletType", "http://not/a/real/uri");
    for (int i = 0; i < lifecyclesToTest.length; i++) {
        final Lifecycle lifecycle = lifecyclesToTest[i];
        final IPortletDefinition pDef = new PortletDefinitionImpl(portletType, "fake-portlet", "Fake Portlet", "Fake Portlet", "FakePortletApp", "fake-portlet-def", false);
        unmarshaller.unmarshallLifecycle(lifecycle, pDef);
        final IPortletLifecycleEntry[] expectedLifecycle = expectedPortletLifecycles[i];
        for (IPortletLifecycleEntry y : pDef.getLifecycle()) {
            System.out.println(" ## ");
            System.out.println(" ## y.getLifecycleState()=" + y.getLifecycleState());
        }
        assertArrayEquals(pDef.getLifecycle().toArray(), expectedLifecycle);
    }
}
Also used : IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) PortletTypeImpl(org.apereo.portal.portlet.dao.jpa.PortletTypeImpl) Calendar(java.util.Calendar) PortletLifecycleEntryImpl(org.apereo.portal.portlet.dao.jpa.PortletLifecycleEntryImpl) IPortletLifecycleEntry(org.apereo.portal.portlet.om.IPortletLifecycleEntry) IPortletType(org.apereo.portal.portlet.om.IPortletType) PortletDefinitionImpl(org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Aggregations

Calendar (java.util.Calendar)1 PortletDefinitionImpl (org.apereo.portal.portlet.dao.jpa.PortletDefinitionImpl)1 PortletLifecycleEntryImpl (org.apereo.portal.portlet.dao.jpa.PortletLifecycleEntryImpl)1 PortletTypeImpl (org.apereo.portal.portlet.dao.jpa.PortletTypeImpl)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IPortletLifecycleEntry (org.apereo.portal.portlet.om.IPortletLifecycleEntry)1 IPortletType (org.apereo.portal.portlet.om.IPortletType)1 Test (org.junit.Test)1