Search in sources :

Example 1 with LiferayPortletXml

use of com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml in project liferay-ide by liferay.

the class LiferayPortletXmlTest method testLiferayScriptPossibleValuesService.

@Test
public void testLiferayScriptPossibleValuesService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp newProjectOp = NewLiferayPluginProjectOp.TYPE.instantiate();
    newProjectOp.setProjectName("test-script");
    newProjectOp.setPluginType(PluginType.portlet);
    newProjectOp.setIncludeSampleCode(true);
    newProjectOp.setPortletFramework("mvc");
    newProjectOp.setPortletName("testPortlet");
    final IProject testProject = createAntProject(newProjectOp);
    LiferayPortletXml liferayPortletApp = op(testProject);
    for (LiferayPortlet liferayPortlet : liferayPortletApp.getPortlets()) {
        ElementList<PortletStyleElement> portletCsses = liferayPortlet.getHeaderPortletCsses();
        {
            for (PortletStyleElement portletCss : portletCsses) {
                final PossibleValuesService scriptService = portletCss.getValue().service(PossibleValuesService.class);
                assertEquals(true, scriptService.values().contains("/css/main.css"));
            }
        }
    }
}
Also used : PossibleValuesService(org.eclipse.sapphire.PossibleValuesService) LiferayPortletXml(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) PortletStyleElement(com.liferay.ide.portlet.core.lfportlet.model.PortletStyleElement) LiferayPortlet(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 2 with LiferayPortletXml

use of com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml in project liferay-ide by liferay.

the class LiferayPortletXmlTest method testPortletXmlRead.

@Test
public void testPortletXmlRead() throws Exception {
    final LiferayPortletXml portletApp = op(PORTLET_XML);
    assertNotNull(portletApp);
    final ElementList<LiferayPortlet> portlets = portletApp.getPortlets();
    assertNotNull(portlets);
    assertEquals(1, portlets.size());
    final LiferayPortlet portlet = portlets.get(0);
    assertNotNull(portlet);
    assertEquals("new", portlet.getPortletName().content());
    assertEquals("/icon.png", portlet.getIcon().content().toPortableString());
    assertEquals("/testStrutsPath", portlet.getStrutsPath().content());
    assertEquals("com.test.configuration.Test", portlet.getConfigurationActionClass().content().toString());
    String[] indexerClassNames = { "com.test.index.Test1", "com.test.index.Test2", "com.test.index.Test3" };
    final ElementList<IndexerClass> indexerClasses = portlet.getIndexerClasses();
    assertNotNull(indexerClasses);
    for (IndexerClass indexer : indexerClasses) {
        assertEquals(true, Arrays.asList(indexerClassNames).contains(indexer.getValue().toString()));
    }
    String[] schedulerEntryDescriptions = { "scheduler cron entry test", "scheduler simple entry test" };
    String[] schedulerEntryClasses = { "com.test.schedulerEntry.TestScheduler1", "com.test.schedulerEntry.TestScheduler2" };
    final ElementList<SchedulerEntry> schedulerEntris = portlet.getSchedulerEntries();
    assertNotNull(schedulerEntris);
    for (SchedulerEntry schedulerEntry : schedulerEntris) {
        assertEquals(true, Arrays.asList(schedulerEntryDescriptions).contains(schedulerEntry.getSchedulerDescription().content()));
        assertEquals(true, Arrays.asList(schedulerEntryClasses).contains(schedulerEntry.getSchedulerEventListenerClass().toString()));
        ElementHandle<ITrigger> trigger = schedulerEntry.getPortletTrigger();
        if (trigger.content() instanceof CronTrigger) {
            CronTrigger cronTrigger = (CronTrigger) (trigger.content());
            ElementHandle<ICronTrigger> cronTriggerDetail = cronTrigger.getCronTrigger();
            if (cronTriggerDetail.content() instanceof PropertyCronTrigger) {
                PropertyCronTrigger propertyTrigger = (PropertyCronTrigger) cronTriggerDetail.content();
                assertEquals("cron", propertyTrigger.getPropertyKey().content());
            } else if (cronTriggerDetail.content() instanceof CronTriggerValueTrigger) {
                CronTriggerValueTrigger valueTrigger = (CronTriggerValueTrigger) cronTriggerDetail.content();
                assertEquals("15", valueTrigger.getCronTriggerValue().content());
            }
        } else {
            SimpleTrigger simpleTrigger = (SimpleTrigger) (trigger.content());
            ElementHandle<ISimpleTrigger> simpleTriggerDetail = simpleTrigger.getSimpleTrigger();
            if (simpleTriggerDetail.content() instanceof PropertySimpleTrigger) {
                PropertySimpleTrigger propertyTrigger = (PropertySimpleTrigger) simpleTriggerDetail.content();
                assertEquals("simple", propertyTrigger.getPropertyKey().content());
            } else if (simpleTriggerDetail.content() instanceof SimpleTriggerValueTrigger) {
                SimpleTriggerValueTrigger valueTrigger = (SimpleTriggerValueTrigger) simpleTriggerDetail.content();
                assertEquals("15", valueTrigger.getSimpleTriggerValue().content());
            }
            assertEquals("minute", simpleTrigger.getTimeUnit().content());
        }
    }
    assertEquals("com.test.friendUrlMapper.Test", portlet.getFriendlyURLMapperClass().content().toString());
    assertEquals("test", portlet.getFriendlyURLMapping().toString());
    assertEquals("test", portlet.getFriendlyURLRoutes().toString());
    assertEquals("com.test.portletDataHandler.Test", portlet.getPortletDataHandlerClass().content().toString());
    final ElementList<StagedModelDataHandlerClass> stageHandlers = portlet.getStagedModelDataHandlerClasses();
    assertNotNull(stageHandlers);
    String[] stageHandlersValue = { "com.test.stagedModelDataHandler.Test1", "com.test.stagedModelDataHandler.Test2", "com.test.stagedModelDataHandler.Test3" };
    for (StagedModelDataHandlerClass stageHandler : stageHandlers) {
        assertEquals(true, Arrays.asList(stageHandlersValue).contains(stageHandler.getValue().content().toString()));
    }
    final ElementList<SocialActivityInterpreterClass> socialActivities = portlet.getSocialActivityInterpreterClasses();
    assertNotNull(socialActivities);
    String[] socialActivityValues = { "com.test.socialActivityListener.Test1", "com.test.socialActivityListener.Test2", "com.test.socialActivityListener.Test3" };
    for (SocialActivityInterpreterClass socialActivity : socialActivities) {
        assertEquals(true, Arrays.asList(socialActivityValues).contains(socialActivity.getValue().content().toString()));
    }
    assertEquals("my", portlet.getControlPanelEntryCategory().content());
    assertEquals(new Double(1.5), portlet.getControlPanelEntryWeight().content());
    assertEquals("com.test.NewPortletControlPanelEntry", portlet.getControlPanelEntryClass().content().toString());
    final ElementList<AssetRendererFactory> assetHandlers = portlet.getAssetRendererFactories();
    assertNotNull(assetHandlers);
    String[] assetHandlersValues = { "com.test.assetRenderFactory.Test1", "com.test.assetRenderFactory.Test2", "com.test.assetRenderFactory.Test3" };
    for (AssetRendererFactory assetHandler : assetHandlers) {
        assertEquals(true, Arrays.asList(assetHandlersValues).contains(assetHandler.getValue().content().toString()));
    }
    final ElementList<TrashHandler> trashHanlders = portlet.getTrashHandlers();
    assertNotNull(trashHanlders);
    String[] trashHanldersValues = { "com.test.trashHandler.Test1", "com.test.trashHandler.Test2", "com.test.trashHandler.Test3" };
    for (TrashHandler trashHanlder : trashHanlders) {
        assertEquals(true, Arrays.asList(trashHanldersValues).contains(trashHanlder.getValue().content().toString()));
    }
    // workflow test
    final ElementList<PortletStyleElement> headerPortletCsses = portlet.getHeaderPortletCsses();
    assertNotNull(headerPortletCsses);
    String[] headerPortletCssesValues = { "/css/portlet1.css", "/css/portlet2.css", "/css/portlet3.css" };
    for (PortletStyleElement headerPortalCss : headerPortletCsses) {
        assertEquals(true, Arrays.asList(headerPortletCssesValues).contains(headerPortalCss.getValue().content().toPortableString()));
    }
    final ElementList<PortletStyleElement> headerPortletJses = portlet.getHeaderPortletJavascripts();
    assertNotNull(headerPortletJses);
    String[] headerPortletJsesValues = { "/js/portlet1.js", "/js/portlet2.js", "/js/portlet3.js" };
    for (PortletStyleElement headerPortletJs : headerPortletJses) {
        assertEquals(true, Arrays.asList(headerPortletJsesValues).contains(headerPortletJs.getValue().content().toPortableString()));
    }
    final ElementList<PortletStyleElement> footerPortletJses = portlet.getFooterPortletJavascripts();
    assertNotNull(footerPortletJses);
    String[] footerPortletJsesValues = { "/js/portlet1.js", "/js/portlet2.js", "/js/portlet3.js" };
    for (PortletStyleElement footerPortletJs : footerPortletJses) {
        assertEquals(true, Arrays.asList(footerPortletJsesValues).contains(footerPortletJs.getValue().content().toPortableString()));
    }
    assertEquals("test", portlet.getCssClassWrapper().toString());
    assertEquals("test", portlet.getCssClassWrapper().content());
    final ElementList<SecurityRoleRef> roleMappers = portletApp.getRoleMappers();
    assertNotNull(roleMappers);
    String[] roleMapperNameValues = { "administrator", "guest", "power-user", "user" };
    String[] roleMapperLinkValues = { "Administrator", "Guest", "Power User", "User" };
    for (SecurityRoleRef roleMapper : roleMappers) {
        assertEquals(true, Arrays.asList(roleMapperNameValues).contains(roleMapper.getRoleName().content()));
        assertEquals(true, Arrays.asList(roleMapperLinkValues).contains(roleMapper.getRoleLink().content()));
    }
    final ElementList<CustomUserAttribute> userAttributes = portletApp.getCustomUserAttributes();
    assertNotNull(userAttributes);
    String[] attributeNameValues = { "tag1", "tag2", "tag3" };
    String[] attributeClassValues = { "com.test.customUserAttribute.Test1" };
    for (CustomUserAttribute attribute : userAttributes) {
        ElementList<CutomUserAttributeName> attributeNames = attribute.getCustomUserAttributeNames();
        assertNotNull(attributeNames);
        for (CutomUserAttributeName attributeName : attributeNames) {
            assertEquals(true, Arrays.asList(attributeNameValues).contains(attributeName.getValue().content()));
        }
        assertEquals(true, Arrays.asList(attributeClassValues).contains(attribute.getCustomClass().toString()));
    }
}
Also used : ISimpleTrigger(com.liferay.ide.portlet.core.lfportlet.model.ISimpleTrigger) SimpleTriggerValueTrigger(com.liferay.ide.portlet.core.lfportlet.model.SimpleTriggerValueTrigger) SecurityRoleRef(com.liferay.ide.portlet.core.model.SecurityRoleRef) LiferayPortlet(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet) AssetRendererFactory(com.liferay.ide.portlet.core.lfportlet.model.AssetRendererFactory) LiferayPortletXml(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml) SocialActivityInterpreterClass(com.liferay.ide.portlet.core.lfportlet.model.SocialActivityInterpreterClass) PropertySimpleTrigger(com.liferay.ide.portlet.core.lfportlet.model.PropertySimpleTrigger) SchedulerEntry(com.liferay.ide.portlet.core.lfportlet.model.SchedulerEntry) StagedModelDataHandlerClass(com.liferay.ide.portlet.core.lfportlet.model.StagedModelDataHandlerClass) ISimpleTrigger(com.liferay.ide.portlet.core.lfportlet.model.ISimpleTrigger) SimpleTrigger(com.liferay.ide.portlet.core.lfportlet.model.SimpleTrigger) PropertySimpleTrigger(com.liferay.ide.portlet.core.lfportlet.model.PropertySimpleTrigger) CronTrigger(com.liferay.ide.portlet.core.lfportlet.model.CronTrigger) ICronTrigger(com.liferay.ide.portlet.core.lfportlet.model.ICronTrigger) PropertyCronTrigger(com.liferay.ide.portlet.core.lfportlet.model.PropertyCronTrigger) TrashHandler(com.liferay.ide.portlet.core.lfportlet.model.TrashHandler) CutomUserAttributeName(com.liferay.ide.portlet.core.lfportlet.model.CutomUserAttributeName) CronTriggerValueTrigger(com.liferay.ide.portlet.core.lfportlet.model.CronTriggerValueTrigger) PortletStyleElement(com.liferay.ide.portlet.core.lfportlet.model.PortletStyleElement) ITrigger(com.liferay.ide.portlet.core.lfportlet.model.ITrigger) ICronTrigger(com.liferay.ide.portlet.core.lfportlet.model.ICronTrigger) IndexerClass(com.liferay.ide.portlet.core.lfportlet.model.IndexerClass) CustomUserAttribute(com.liferay.ide.portlet.core.lfportlet.model.CustomUserAttribute) PropertyCronTrigger(com.liferay.ide.portlet.core.lfportlet.model.PropertyCronTrigger) Test(org.junit.Test)

Example 3 with LiferayPortletXml

use of com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml in project liferay-ide by liferay.

the class LiferayPortletXmlTest method testIconRelativePathService.

@Test
public void testIconRelativePathService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp newProjectOp = NewLiferayPluginProjectOp.TYPE.instantiate();
    newProjectOp.setProjectName("test-path");
    newProjectOp.setPluginType(PluginType.portlet);
    newProjectOp.setIncludeSampleCode(true);
    newProjectOp.setPortletFramework("mvc");
    newProjectOp.setPortletName("testPortlet");
    final IProject testProject = createAntProject(newProjectOp);
    LiferayPortletXml liferayPortletApp = op(testProject);
    for (LiferayPortlet liferayPortlet : liferayPortletApp.getPortlets()) {
        final RelativePathService pathService = liferayPortlet.getIcon().service(RelativePathService.class);
        List<Path> iconPaths = pathService.roots();
        assertEquals(true, iconPaths.size() > 0);
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) LiferayPortletXml(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml) RelativePathService(org.eclipse.sapphire.services.RelativePathService) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) LiferayPortlet(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 4 with LiferayPortletXml

use of com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml in project liferay-ide by liferay.

the class LiferayPortletXmlTest method testNumberValidationService.

@Test
public void testNumberValidationService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    LiferayPortletXml liferayPortletApp = LiferayPortletXml.TYPE.instantiate();
    LiferayPortlet liferayPortlet = liferayPortletApp.getPortlets().insert();
    SchedulerEntry schedulerEntry = liferayPortlet.getSchedulerEntries().insert();
    ElementHandle<ITrigger> cronTrigger = ((ElementHandle<ITrigger>) (schedulerEntry.getPortletTrigger()));
    ElementHandle<ICronTrigger> cronTriggerValueTrigger = cronTrigger.content(true, CronTrigger.class).getCronTrigger();
    CronTriggerValueTrigger cronTriggerValue = cronTriggerValueTrigger.content(true, CronTriggerValueTrigger.class);
    NumberValueValidationService vs = cronTriggerValue.getCronTriggerValue().service(NumberValueValidationService.class);
    cronTriggerValue.setCronTriggerValue("-1");
    assertEquals(false, "ok".equals(vs.validation().message()));
    cronTriggerValue.setCronTriggerValue("150");
    assertEquals(true, "ok".equals(vs.validation().message()));
}
Also used : ICronTrigger(com.liferay.ide.portlet.core.lfportlet.model.ICronTrigger) CronTrigger(com.liferay.ide.portlet.core.lfportlet.model.CronTrigger) ICronTrigger(com.liferay.ide.portlet.core.lfportlet.model.ICronTrigger) PropertyCronTrigger(com.liferay.ide.portlet.core.lfportlet.model.PropertyCronTrigger) LiferayPortletXml(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml) NumberValueValidationService(com.liferay.ide.portlet.core.lfportlet.model.internal.NumberValueValidationService) SchedulerEntry(com.liferay.ide.portlet.core.lfportlet.model.SchedulerEntry) CronTriggerValueTrigger(com.liferay.ide.portlet.core.lfportlet.model.CronTriggerValueTrigger) LiferayPortlet(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet) ITrigger(com.liferay.ide.portlet.core.lfportlet.model.ITrigger) Test(org.junit.Test)

Example 5 with LiferayPortletXml

use of com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml in project liferay-ide by liferay.

the class LiferayPortletXmlTest method testPortletNameValidationService.

@Test
public void testPortletNameValidationService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp newProjectOp = NewLiferayPluginProjectOp.TYPE.instantiate();
    newProjectOp.setProjectName("test-validation");
    newProjectOp.setPluginType(PluginType.portlet);
    newProjectOp.setIncludeSampleCode(true);
    newProjectOp.setPortletFramework("mvc");
    newProjectOp.setPortletName("testPortlet");
    final IProject testProject = createAntProject(newProjectOp);
    LiferayPortletXml liferayPortletApp = op(testProject);
    for (LiferayPortlet liferayPortlet : liferayPortletApp.getPortlets()) {
        final ValidationService vs = liferayPortlet.getPortletName().service(ValidationService.class);
        assertEquals("ok", vs.validation().message());
        assertEquals("ok", liferayPortlet.getPortletName().validation().message());
    }
    for (LiferayPortlet liferayPortlet : liferayPortletApp.getPortlets()) {
        liferayPortlet.setPortletName("test1");
        final ValidationService vs = liferayPortlet.getPortletName().service(ValidationService.class);
        assertEquals(false, "ok".equals(vs.validation().message()));
        assertEquals(false, "ok".equals(liferayPortlet.getPortletName().validation().message()));
    }
}
Also used : LiferayPortletXml(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml) NumberValueValidationService(com.liferay.ide.portlet.core.lfportlet.model.internal.NumberValueValidationService) ValidationService(org.eclipse.sapphire.services.ValidationService) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) LiferayPortlet(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

LiferayPortlet (com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet)5 LiferayPortletXml (com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml)5 Test (org.junit.Test)5 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)3 IProject (org.eclipse.core.resources.IProject)3 CronTrigger (com.liferay.ide.portlet.core.lfportlet.model.CronTrigger)2 CronTriggerValueTrigger (com.liferay.ide.portlet.core.lfportlet.model.CronTriggerValueTrigger)2 ICronTrigger (com.liferay.ide.portlet.core.lfportlet.model.ICronTrigger)2 ITrigger (com.liferay.ide.portlet.core.lfportlet.model.ITrigger)2 PortletStyleElement (com.liferay.ide.portlet.core.lfportlet.model.PortletStyleElement)2 PropertyCronTrigger (com.liferay.ide.portlet.core.lfportlet.model.PropertyCronTrigger)2 SchedulerEntry (com.liferay.ide.portlet.core.lfportlet.model.SchedulerEntry)2 NumberValueValidationService (com.liferay.ide.portlet.core.lfportlet.model.internal.NumberValueValidationService)2 AssetRendererFactory (com.liferay.ide.portlet.core.lfportlet.model.AssetRendererFactory)1 CustomUserAttribute (com.liferay.ide.portlet.core.lfportlet.model.CustomUserAttribute)1 CutomUserAttributeName (com.liferay.ide.portlet.core.lfportlet.model.CutomUserAttributeName)1 ISimpleTrigger (com.liferay.ide.portlet.core.lfportlet.model.ISimpleTrigger)1 IndexerClass (com.liferay.ide.portlet.core.lfportlet.model.IndexerClass)1 PropertySimpleTrigger (com.liferay.ide.portlet.core.lfportlet.model.PropertySimpleTrigger)1 SimpleTrigger (com.liferay.ide.portlet.core.lfportlet.model.SimpleTrigger)1