Search in sources :

Example 16 with Location

use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.

the class LocationResolverTest method resolveIfExistsFileSystemLocation.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} resolves the loacation in a file
 * system context correctly.
 */
@Test
public void resolveIfExistsFileSystemLocation() throws IOException {
    final Path ruleSetFile = Files.createTempFile(LocationResolverTest.class.getSimpleName(), ".xml");
    try {
        final Location location = new Location(ruleSetFile.toString(), LocationContext.FILE_SYSTEM);
        final IProject project = mock(IProject.class);
        final Optional<String> result = LocationResolver.resolveIfExists(location, project);
        assertTrue("A valid file system location should resolve", result.isPresent());
        assertEquals("The resolved location in a file system context should be the provided location", ruleSetFile.toString(), result.get());
    } finally {
        Files.deleteIfExists(ruleSetFile);
    }
}
Also used : Path(java.nio.file.Path) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 17 with Location

use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.

the class LocationResolverTest method resolveIfExistsWorkspaceLocationWithoutPath.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
 * workspace context if the path is empty.
 */
@Test
public void resolveIfExistsWorkspaceLocationWithoutPath() throws URISyntaxException {
    final Location location = new Location("", LocationContext.WORKSPACE);
    final IProject project = mock(IProject.class);
    final IWorkspace workspace = mock(IWorkspace.class);
    final IWorkspaceRoot workspaceRoot = mock(IWorkspaceRoot.class);
    when(project.getWorkspace()).thenReturn(workspace);
    when(workspace.getRoot()).thenReturn(workspaceRoot);
    when(workspaceRoot.getProject("project")).thenReturn(project);
    when(project.getLocationURI()).thenReturn(new URI("file:///workspace/project/"));
    final Optional<String> result = LocationResolver.resolveIfExists(location, project);
    assertFalse("The location should not resolve", result.isPresent());
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 18 with Location

use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.

the class LocationResolverTest method resolveIfExistsRemoteLocationWithInvalidURI.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
 * remote context if the URI is invalid.
 */
@Test
public void resolveIfExistsRemoteLocationWithInvalidURI() {
    final Location location = new Location("http:#", LocationContext.REMOTE);
    final IProject project = mock(IProject.class);
    final Optional<String> result = LocationResolver.resolveIfExists(location, project);
    assertFalse("The location should not resolve", result.isPresent());
}
Also used : IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 19 with Location

use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.

the class LocationResolverTest method resolveIfExistsRemoteLocation.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} resolves the location in a remote
 * context correctly.
 */
@Test
public void resolveIfExistsRemoteLocation() throws IOException {
    final Path ruleSetFile = Files.createTempFile(LocationResolverTest.class.getSimpleName(), ".xml");
    try {
        final Location location = new Location(ruleSetFile.toUri().toString(), LocationContext.REMOTE);
        final IProject project = mock(IProject.class);
        final Optional<String> result = LocationResolver.resolveIfExists(location, project);
        assertTrue("A valid remote location should resolve", result.isPresent());
        assertEquals("The resolved location in a remote context should be the provided location", ruleSetFile.toUri().toString(), result.get());
    } finally {
        Files.deleteIfExists(ruleSetFile);
    }
}
Also used : Path(java.nio.file.Path) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 20 with Location

use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.

the class LocationResolverTest method resolveIfExistsProjectLocationWithMissingFile.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not resolve the location in a
 * project context when the rule set file does not exist.
 */
@Test
public void resolveIfExistsProjectLocationWithMissingFile() throws URISyntaxException {
    final Location location = new Location("pmd.xml", LocationContext.PROJECT);
    final IProject project = mock(IProject.class);
    when(project.getLocationURI()).thenReturn(new URI("file:///workspace/project/"));
    final Optional<String> result = LocationResolver.resolveIfExists(location, project);
    assertFalse("The location should not resolve", result.isPresent());
}
Also used : URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Aggregations

Location (ch.acanda.eclipse.pmd.domain.Location)28 Test (org.junit.Test)24 IProject (org.eclipse.core.resources.IProject)19 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)10 URI (java.net.URI)8 IWorkspace (org.eclipse.core.resources.IWorkspace)7 RuleSetModel (ch.acanda.eclipse.pmd.domain.RuleSetModel)5 Path (java.nio.file.Path)4 LocationContext (ch.acanda.eclipse.pmd.domain.LocationContext)3 ProjectModel (ch.acanda.eclipse.pmd.domain.ProjectModel)2 WorkspaceModel (ch.acanda.eclipse.pmd.domain.WorkspaceModel)2 RuleSets (net.sourceforge.pmd.RuleSets)2 ArrayList (java.util.ArrayList)1