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);
}
}
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());
}
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());
}
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);
}
}
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());
}
Aggregations