Search in sources :

Example 21 with Location

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

the class LocationResolverTest method resolveProjectLocation.

/**
 * Verifies that {@link LocationResolver#resolve(Location, IProject)} resolves the location in a project context
 * correctly.
 */
@Test
public void resolveProjectLocation() throws URISyntaxException {
    final Location location = new Location("path/pmd.xml", LocationContext.PROJECT);
    final IProject project = mock(IProject.class);
    when(project.getLocationURI()).thenReturn(new URI("file:///workspace/project/"));
    final String result = LocationResolver.resolve(location, project);
    assertEquals("The resolved location should be the project's path with the location's path appended", Paths.get("/workspace", "project", "path", "pmd.xml"), Paths.get(result));
}
Also used : URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 22 with Location

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

the class LocationResolverTest method resolveIfExistsFileSystemLocationWithMissingFile.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not resolve the loacation in a
 * file system context when the file is mossing.
 */
@Test
public void resolveIfExistsFileSystemLocationWithMissingFile() {
    final Location location = new Location("/tmp/pmd.xml", LocationContext.FILE_SYSTEM);
    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 23 with Location

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

the class LocationResolverTest method resolveIfExistsWorkspaceLocationWithMissingProject.

/**
 * Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
 * workspace context if the project does not exist.
 */
@Test
public void resolveIfExistsWorkspaceLocationWithMissingProject() {
    final Location location = new Location("MissingProject/pmd.xml", 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("MissingProject")).thenReturn(project);
    when(project.getLocationURI()).thenReturn(null);
    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) IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 24 with Location

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

the class LocationResolverTest method resolveFileSystemLocation.

/**
 * Verifies that {@link LocationResolver#resolve(Location, IProject)} resolves the location in a file system context
 * correctly.
 */
@Test
public void resolveFileSystemLocation() {
    final Location location = new Location("/some/path/pmd.xml", LocationContext.FILE_SYSTEM);
    final IProject project = mock(IProject.class);
    final String result = LocationResolver.resolve(location, project);
    assertEquals("The resolved location should just be the path", "/some/path/pmd.xml", result);
}
Also used : IProject(org.eclipse.core.resources.IProject) Location(ch.acanda.eclipse.pmd.domain.Location) Test(org.junit.Test)

Example 25 with Location

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

the class RuleSetsCacheTest method secondGetLoadsWhenProjectRuleSetsWereChanged.

/**
 * Verifies that the second cache access loads the rule sets if the project model's rule sets have been changed
 * after the first access.
 */
@Test
public void secondGetLoadsWhenProjectRuleSetsWereChanged() throws Exception {
    final WorkspaceModel workspaceModel = getWorkspaceModel();
    final RuleSetsCache cache = new RuleSetsCache(getCacheLoaderMock(), workspaceModel);
    cache.getRuleSets(PROJECT_NAME_1);
    final RuleSetModel ruleSetModel = new RuleSetModel("abc", new Location("path", LocationContext.WORKSPACE));
    workspaceModel.getOrCreateProject(PROJECT_NAME_1).setRuleSets(Arrays.asList(ruleSetModel));
    final RuleSets actualRuleSets = cache.getRuleSets(PROJECT_NAME_1);
    assertSame("Second cache access should reload rule sets", RULE_SETS_FOO_2, actualRuleSets);
}
Also used : WorkspaceModel(ch.acanda.eclipse.pmd.domain.WorkspaceModel) RuleSetModel(ch.acanda.eclipse.pmd.domain.RuleSetModel) RuleSets(net.sourceforge.pmd.RuleSets) 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