use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class RuleSetsCacheTest method secondGetLoadsWhenLaterAddedProjectRuleSetsWereChanged.
/**
* Verifies that the second cache access loads the rule sets if the project model's rule sets have been changed
* after the first access. In this case, the project model was added after the rule sets cache was created.
*/
@Test
public void secondGetLoadsWhenLaterAddedProjectRuleSetsWereChanged() throws Exception {
final WorkspaceModel workspaceModel = getWorkspaceModel();
final RuleSetsCache cache = new RuleSetsCache(getCacheLoaderMock(), workspaceModel);
workspaceModel.add(new ProjectModel(PROJECT_NAME_2));
cache.getRuleSets(PROJECT_NAME_2);
final RuleSetModel ruleSetModel = new RuleSetModel("abc", new Location("path", LocationContext.WORKSPACE));
workspaceModel.getOrCreateProject(PROJECT_NAME_2).setRuleSets(Arrays.asList(ruleSetModel));
final RuleSets actualRuleSets = cache.getRuleSets(PROJECT_NAME_2);
assertSame("Second cache access should reload rule sets", RULE_SETS_BAR_2, actualRuleSets);
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsRemoteLocationWithMissingFile.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not resolve the location in a
* remote context when the file does not exist.
*/
@Test
public void resolveIfExistsRemoteLocationWithMissingFile() {
final Location location = new Location("http://example.org/pmd.xml", 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 resolveIfExistsProjectLocationWithInvalidPath.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
* project context if the path is invalid.
*/
@Test
public void resolveIfExistsProjectLocationWithInvalidPath() throws URISyntaxException {
final Location location = new Location("\u0000:", 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());
}
use of ch.acanda.eclipse.pmd.domain.Location in project eclipse-pmd by acanda.
the class LocationResolverTest method resolveIfExistsWorkspaceLocationWithMissingFile.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} does not throw an exception in a
* workspace context if the rule set file does not exist.
*/
@Test
public void resolveIfExistsWorkspaceLocationWithMissingFile() throws URISyntaxException {
final Location location = new Location("project/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("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 resolveIfExistsProjectLocation.
/**
* Verifies that {@link LocationResolver#resolveIfExists(Location, IProject)} resolves the location in a project
* context correctly.
*/
@Test
public void resolveIfExistsProjectLocation() throws URISyntaxException, IOException {
final Path ruleSetFile = Files.createTempFile(LocationResolverTest.class.getSimpleName(), ".xml");
try {
final Location location = new Location(ruleSetFile.getFileName().toString(), LocationContext.PROJECT);
final IProject project = mock(IProject.class);
when(project.getLocationURI()).thenReturn(ruleSetFile.getParent().toUri());
final Optional<String> result = LocationResolver.resolveIfExists(location, project);
assertTrue("A valid project location should resolve", result.isPresent());
assertEquals("The resolved location in a project context should be the provided location appended to the project location", ruleSetFile.toString(), result.get());
} finally {
Files.deleteIfExists(ruleSetFile);
}
}
Aggregations