Search in sources :

Example 56 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class MVCPortletClassInPortletXMLAutoCorrectTest method testAutoCorrectPortletXmlSingle.

@Test
public void testAutoCorrectPortletXmlSingle() throws Exception {
    assertNotNull(autoMigrator);
    FileMigrator fileMigrator = (FileMigrator) autoMigrator;
    File testfile = new File("generated/test/MVCPortletClassInPortletXMLAutoCorrectTest/portlet.xml");
    if (testfile.exists()) {
        assertTrue(testfile.delete());
    }
    testfile.getParentFile().mkdirs();
    Files.copy(new File("projects/test-portlet/docroot/WEB-INF/portlet.xml").toPath(), testfile.toPath());
    List<Problem> problems = fileMigrator.analyze(testfile);
    assertEquals(2, problems.size());
    int corrected = autoMigrator.correctProblems(testfile, Collections.singletonList(problems.get(0)));
    assertEquals(1, corrected);
    problems = fileMigrator.analyze(testfile);
    assertEquals(1, problems.size());
    corrected = autoMigrator.correctProblems(testfile, Collections.singletonList(problems.get(0)));
    assertEquals(1, corrected);
    problems = fileMigrator.analyze(testfile);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) Test(org.junit.Test)

Example 57 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class NavigationTagsTest method findProblems.

@Test
public void findProblems() throws Exception {
    ServiceReference<Migration> sr = context.getServiceReference(Migration.class);
    Migration m = context.getService(sr);
    List<Problem> problems = m.findProblems(new File("jsptests/navigation-tags/"), new NullProgressMonitor());
    assertEquals(1, problems.size());
    boolean found = false;
    for (Problem problem : problems) {
        if (problem.file.getName().endsWith("NavigationTagsTest.jsp")) {
            if (problem.lineNumber == 3 && problem.startOffset >= 57 && problem.endOffset >= 374) {
                found = true;
            }
        }
    }
    if (!found) {
        fail();
    }
}
Also used : NullProgressMonitor(com.liferay.blade.util.NullProgressMonitor) Migration(com.liferay.blade.api.Migration) Problem(com.liferay.blade.api.Problem) File(java.io.File) Test(org.junit.Test)

Example 58 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class PortalServiceImportsAutoCorrectTest method autoCorrectProblems.

@Test
public void autoCorrectProblems() throws Exception {
    File tempFolder = Files.createTempDirectory("autocorrect").toFile();
    File testFile = new File(tempFolder, "PortalServiceImports.java");
    tempFolder.deleteOnExit();
    File originalTestfile = new File("javatests/PortalServiceImports.java");
    Files.copy(originalTestfile.toPath(), testFile.toPath());
    List<Problem> problems = null;
    FileMigrator migrator = null;
    Collection<ServiceReference<FileMigrator>> mrefs = context.getServiceReferences(FileMigrator.class, null);
    for (ServiceReference<FileMigrator> mref : mrefs) {
        migrator = context.getService(mref);
        if (migrator.getClass().getName().contains("PortalServiceImports")) {
            problems = migrator.analyze(testFile);
            break;
        }
    }
    assertEquals(2, problems.size());
    int problemsFixed = ((AutoMigrator) migrator).correctProblems(testFile, problems);
    assertEquals(2, problemsFixed);
    File dest = new File(tempFolder, "Updated.java");
    assertTrue(testFile.renameTo(dest));
    problems = migrator.analyze(dest);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) AutoMigrator(com.liferay.blade.api.AutoMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 59 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class RenamePortalKernelImportAutoCorrectTest method autoCorrectProblems.

@Test
public void autoCorrectProblems() throws Exception {
    File tempFolder = Files.createTempDirectory("autocorrect").toFile();
    File testFile = new File(tempFolder, "TasksEntryLocalServiceImpl.java");
    tempFolder.deleteOnExit();
    File originalTestfile = new File("javatests/TasksEntryLocalServiceImpl.java");
    Files.copy(originalTestfile.toPath(), testFile.toPath());
    List<Problem> problems = null;
    FileMigrator migrator = null;
    Collection<ServiceReference<FileMigrator>> mrefs = context.getServiceReferences(FileMigrator.class, null);
    for (ServiceReference<FileMigrator> mref : mrefs) {
        migrator = context.getService(mref);
        if (migrator.getClass().getName().contains("RenamePortalKernelImport")) {
            problems = migrator.analyze(testFile);
            break;
        }
    }
    assertEquals(10, problems.size());
    int problemsFixed = ((AutoMigrator) migrator).correctProblems(testFile, problems);
    assertEquals(10, problemsFixed);
    File dest = new File(tempFolder, "Updated.java");
    assertTrue(testFile.renameTo(dest));
    problems = migrator.analyze(dest);
    assertEquals(0, problems.size());
}
Also used : FileMigrator(com.liferay.blade.api.FileMigrator) AutoMigrator(com.liferay.blade.api.AutoMigrator) Problem(com.liferay.blade.api.Problem) File(java.io.File) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 60 with Problem

use of com.liferay.blade.api.Problem in project liferay-ide by liferay.

the class RepositoryServiceUtilTest method repositoryServiceUtilTest.

@Test
public void repositoryServiceUtilTest() throws Exception {
    ServiceReference<Migration> sr = context.getServiceReference(Migration.class);
    Migration m = context.getService(sr);
    List<Problem> problems = m.findProblems(new File("jsptests/repository-service-util"), new NullProgressMonitor());
    assertEquals(1, problems.size());
    boolean found = false;
    for (Problem problem : problems) {
        if (problem.file.getName().endsWith("RepositoryServiceUtilTest.jsp")) {
            if (problem.lineNumber == 9 && problem.startOffset >= 104 && problem.endOffset >= 171) {
                found = true;
            }
        }
    }
    if (!found) {
        fail();
    }
}
Also used : NullProgressMonitor(com.liferay.blade.util.NullProgressMonitor) Migration(com.liferay.blade.api.Migration) Problem(com.liferay.blade.api.Problem) File(java.io.File) Test(org.junit.Test)

Aggregations

Problem (com.liferay.blade.api.Problem)92 Test (org.junit.Test)58 File (java.io.File)42 FileMigrator (com.liferay.blade.api.FileMigrator)31 Migration (com.liferay.blade.api.Migration)29 NullProgressMonitor (com.liferay.blade.util.NullProgressMonitor)26 ArrayList (java.util.ArrayList)16 FileProblems (com.liferay.ide.project.core.upgrade.FileProblems)9 IOException (java.io.IOException)9 ServiceReference (org.osgi.framework.ServiceReference)9 AutoMigrator (com.liferay.blade.api.AutoMigrator)8 IFile (org.eclipse.core.resources.IFile)8 List (java.util.List)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 AutoMigrateException (com.liferay.blade.api.AutoMigrateException)5 SearchResult (com.liferay.blade.api.SearchResult)5 MigrationProblems (com.liferay.ide.project.core.upgrade.MigrationProblems)5 MigrationProblemsContainer (com.liferay.ide.project.core.upgrade.MigrationProblemsContainer)5 HashSet (java.util.HashSet)5 CoreException (org.eclipse.core.runtime.CoreException)5