Search in sources :

Example 1 with ValidationService

use of org.eclipse.sapphire.services.ValidationService in project liferay-ide by liferay.

the class NewLiferayPluginProjectMavenTests method testLocationValidation.

@Test
@Ignore
public void testLocationValidation() throws Exception {
    final NewLiferayPluginProjectOp op = newProjectOp("test-location-validation-service");
    op.setProjectProvider("maven");
    op.setPluginType("portlet");
    op.setUseDefaultLocation(false);
    final ValidationService vs = op.getLocation().service(ValidationService.class);
    String invalidLocation = null;
    invalidLocation = "not-absolute-location";
    op.setLocation(invalidLocation);
    final String expected = "\"" + invalidLocation + "\"" + " is not an absolute path.";
    assertEquals(normalize(expected), normalize(vs.validation().message()));
    assertEquals(normalize(expected), normalize(op.getLocation().validation().message()));
    if (CoreUtil.isWindows()) {
        invalidLocation = "Z:\\test-location-validation-service";
    } else {
        invalidLocation = "/test-location-validation-service";
    }
    op.setLocation(invalidLocation);
    final String expected2 = "Cannot create project content at " + "\"" + invalidLocation + "\"";
    assertEquals(expected2, vs.validation().message());
    assertEquals(expected2, op.getLocation().validation().message());
    if (CoreUtil.isWindows()) {
        invalidLocation = CoreUtil.getWorkspaceRoot().getLocation().getDevice() + "\\";
    } else {
        invalidLocation = "/";
    }
    op.setLocation(invalidLocation);
    final String expected3 = "Project location is not empty or a parent pom.";
    assertEquals(expected3, vs.validation().message());
    // assertEquals( expected3, op.getLocation().validation().message() );
    // IDE-2069
    invalidLocation = getLiferayRuntimeDir().removeLastSegments(2).toOSString();
    op.setLocation(invalidLocation);
    final String expected5 = "Project location is not empty or a parent pom.";
    assertEquals(expected5, vs.validation().message());
    op.setLocation("");
    final String expected4 = "Location must be specified.";
    assertEquals(expected4, vs.validation().message());
    assertEquals(expected4, op.getLocation().validation().message());
}
Also used : ValidationService(org.eclipse.sapphire.services.ValidationService) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ValidationService

use of org.eclipse.sapphire.services.ValidationService in project liferay-ide by liferay.

the class LayoutTplTestsBootstrap method testPorteltColumnWeightValidationService.

@Test
public void testPorteltColumnWeightValidationService() {
    final LayoutTplElement layoutTpl = LayoutTplElement.TYPE.instantiate();
    layoutTpl.setBootstrapStyle(true);
    final PortletLayoutElement row = layoutTpl.getPortletLayouts().insert();
    final PortletColumnElement column = row.getPortletColumns().insert();
    final ValidationService validationService = column.getWeight().service(ValidationService.class);
    column.setWeight(0);
    assertEquals("The weight value is invalid, should be in (0, 12]", validationService.validation().message());
    column.setWeight(-1);
    assertEquals("The weight value is invalid, should be in (0, 12]", validationService.validation().message());
    column.setWeight(13);
    assertEquals("The weight value is invalid, should be in (0, 12]", validationService.validation().message());
    column.setWeight(6);
    assertEquals("ok", validationService.validation().message());
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) ValidationService(org.eclipse.sapphire.services.ValidationService) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement) Test(org.junit.Test)

Example 3 with ValidationService

use of org.eclipse.sapphire.services.ValidationService in project liferay-ide by liferay.

the class LayoutTplTestsBootstrap method testPortletColumnsValidationSerive.

// test sum of column weights
@Test
public void testPortletColumnsValidationSerive() {
    final LayoutTplElement layoutTpl = LayoutTplElement.TYPE.instantiate();
    layoutTpl.setBootstrapStyle(true);
    final PortletLayoutElement row = layoutTpl.getPortletLayouts().insert();
    final ElementList<PortletColumnElement> columns = row.getPortletColumns();
    final PortletColumnElement column = columns.insert();
    final ValidationService validationService = columns.service(ValidationService.class);
    assertEquals("ok", validationService.validation().message());
    column.setWeight(0);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(-1);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(6);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(13);
    assertEquals("The sum of weight of columns should be: 12", validationService.validation().message());
    column.setWeight(12);
    assertEquals("ok", validationService.validation().message());
}
Also used : PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) ValidationService(org.eclipse.sapphire.services.ValidationService) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement) Test(org.junit.Test)

Example 4 with ValidationService

use of org.eclipse.sapphire.services.ValidationService 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)

Example 5 with ValidationService

use of org.eclipse.sapphire.services.ValidationService in project liferay-ide by liferay.

the class NewLiferayPluginProjectOpBase method testProjectNameValidation.

protected void testProjectNameValidation(final String initialProjectName) throws Exception {
    final NewLiferayPluginProjectOp op1 = newProjectOp("");
    op1.setUseDefaultLocation(true);
    ValidationService vs = op1.getProjectName().service(ValidationService.class);
    final String validProjectName = initialProjectName;
    op1.setProjectName(validProjectName);
    assertEquals("ok", vs.validation().message());
    assertEquals("ok", op1.getProjectName().validation().message());
    op1.setProjectName(validProjectName + "-portlet");
    assertEquals("ok", vs.validation().message());
    assertEquals("ok", op1.getProjectName().validation().message());
    final IProject proj = createProject(op1);
    op1.dispose();
    final NewLiferayPluginProjectOp op2 = newProjectOp("");
    vs = op2.getProjectName().service(ValidationService.class);
    op2.setProjectName(validProjectName + "-portlet");
    assertEquals("A project with that name already exists.", vs.validation().message());
    assertEquals("A project with that name already exists.", op2.getProjectName().validation().message());
    op2.setProjectName(validProjectName);
    assertEquals("A project with that name already exists.", vs.validation().message());
    assertEquals("A project with that name already exists.", op2.getProjectName().validation().message());
    final IPath dotProjectLocation = proj.getLocation().append(".project");
    if (dotProjectLocation.toFile().exists()) {
        dotProjectLocation.toFile().delete();
    }
    op2.dispose();
    final NewLiferayPluginProjectOp op3 = newProjectOp("");
    vs = op3.getProjectName().service(ValidationService.class);
    op3.setProjectName(validProjectName);
    assertEquals("A project with that name already exists.", vs.validation().message());
    assertEquals("A project with that name already exists.", op3.getProjectName().validation().message());
    String invalidProjectName = validProjectName + "/";
    op3.setProjectName(invalidProjectName);
    assertEquals("/ is an invalid character in resource name '" + invalidProjectName + "'.", vs.validation().message());
    op3.dispose();
// invalidProjectName = validProjectName + ".";
// op3.setProjectName( invalidProjectName );
// assertEquals( "'" + invalidProjectName + "' is an invalid name on this platform.", vs.validation().message() );
// assertEquals(
// "'" + invalidProjectName + "' is an invalid name on this platform.",
// op3.getProjectName().validation().message() );
}
Also used : IPath(org.eclipse.core.runtime.IPath) ValidationService(org.eclipse.sapphire.services.ValidationService) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) IProject(org.eclipse.core.resources.IProject)

Aggregations

ValidationService (org.eclipse.sapphire.services.ValidationService)8 Test (org.junit.Test)7 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)6 LayoutTplElement (com.liferay.ide.layouttpl.core.model.LayoutTplElement)2 PortletColumnElement (com.liferay.ide.layouttpl.core.model.PortletColumnElement)2 PortletLayoutElement (com.liferay.ide.layouttpl.core.model.PortletLayoutElement)2 IProject (org.eclipse.core.resources.IProject)2 Ignore (org.junit.Ignore)2 LiferayPortlet (com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet)1 LiferayPortletXml (com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml)1 NumberValueValidationService (com.liferay.ide.portlet.core.lfportlet.model.internal.NumberValueValidationService)1 IPortletFramework (com.liferay.ide.project.core.IPortletFramework)1 SDK (com.liferay.ide.sdk.core.SDK)1 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1