use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class PomEditorServiceImplTest method testSaveClashingGAVForced.
@Test
public void testSaveClashingGAVForced() {
final Set<ModuleRepositories.ModuleRepository> moduleRepositoriesMetadata = new HashSet<ModuleRepositories.ModuleRepository>() {
{
add(new ModuleRepositories.ModuleRepository(true, new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL)));
}
};
final ModuleRepositories moduleRepositories = new ModuleRepositories(moduleRepositoriesMetadata);
when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
final Set<MavenRepositoryMetadata> clashingRepositories = new HashSet<MavenRepositoryMetadata>() {
{
add(new MavenRepositoryMetadata("local-id", "local-url", MavenRepositorySource.LOCAL));
}
};
when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class))).thenReturn(clashingRepositories);
when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.1"));
try {
service.save(pomPath, pomXml, metaData, comment, DeploymentMode.FORCED);
} catch (GAVAlreadyExistsException e) {
fail(e.getMessage());
}
verify(moduleService, never()).resolveModule(pomPath);
verify(moduleRepositoriesService, never()).load(pomPath);
verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(pomXml), any(MavenRepositoryMetadata.class));
verify(ioService, times(1)).startBatch(any(FileSystem.class));
verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), eq(pomXml), eq(attributes), any(CommentedOption.class));
verify(ioService, times(1)).endBatch();
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class ProjectScreenServiceImplTest method testSaveClashingGAVForced.
@Test()
public void testSaveClashingGAVForced() {
when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
final ProjectScreenModel model = new ProjectScreenModel();
model.setPOM(pom);
model.setPOMMetaData(pomMetaData);
model.setPathToPOM(pathToPom);
model.setKModule(kmodule);
model.setKModuleMetaData(kmoduleMetaData);
model.setPathToKModule(pathToKieModule);
model.setProjectImports(projectImports);
model.setProjectImportsMetaData(projectImportsMetaData);
model.setPathToImports(pathToModuleImports);
model.setRepositories(moduleRepositories);
model.setPathToRepositories(pathToModuleRepositories);
final MavenRepositoryMetadata repositoryMetadata = new MavenRepositoryMetadata("id", "url", MavenRepositorySource.LOCAL);
moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(true, repositoryMetadata));
when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), eq(repositoryMetadata))).thenReturn(new HashSet<MavenRepositoryMetadata>() {
{
add(repositoryMetadata);
}
});
final String comment = "comment";
final WorkspaceProject projectToBeReturned = new WorkspaceProject();
doReturn(projectToBeReturned).when(projectService).resolveProject(pathToPom);
try {
final WorkspaceProject project = service.save(pathToPom, model, comment, DeploymentMode.FORCED);
assertEquals(projectToBeReturned, project);
} catch (GAVAlreadyExistsException e) {
fail("Unexpected exception thrown: " + e.getMessage());
}
verify(pomService, times(1)).save(eq(pathToPom), eq(model.getPOM()), eq(pomMetaData), eq(comment));
verify(kModuleService, times(1)).save(eq(pathToKieModule), eq(kmodule), eq(kmoduleMetaData), eq(comment));
verify(importsService, times(1)).save(eq(pathToModuleImports), eq(projectImports), eq(projectImportsMetaData), eq(comment));
verify(repositoriesService, times(1)).save(eq(pathToModuleRepositories), eq(moduleRepositories), eq(comment));
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class ProjectScreenServiceImplTest method testSaveClashingGAVFilteredRepositoryNoChangeToGAV.
@Test()
public void testSaveClashingGAVFilteredRepositoryNoChangeToGAV() {
when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
final ProjectScreenModel model = new ProjectScreenModel();
model.setPOM(pom);
model.setPOMMetaData(pomMetaData);
model.setPathToPOM(pathToPom);
model.setKModule(kmodule);
model.setKModuleMetaData(kmoduleMetaData);
model.setPathToKModule(pathToKieModule);
model.setProjectImports(projectImports);
model.setProjectImportsMetaData(projectImportsMetaData);
model.setPathToImports(pathToModuleImports);
model.setRepositories(moduleRepositories);
model.setPathToRepositories(pathToModuleRepositories);
final MavenRepositoryMetadata repositoryMetadata = new MavenRepositoryMetadata("id", "url", MavenRepositorySource.LOCAL);
moduleRepositories.getRepositories().add(new ModuleRepositories.ModuleRepository(false, repositoryMetadata));
final ArgumentCaptor<MavenRepositoryMetadata> filterCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
when(repositoryResolver.getRepositoriesResolvingArtifact(eq(gav), eq(module), filterCaptor.capture())).thenReturn(new HashSet<MavenRepositoryMetadata>());
final String comment = "comment";
try {
service.save(pathToPom, model, comment);
} catch (GAVAlreadyExistsException e) {
// This should not be thrown if we're filtering out the Repository from the check
fail(e.getMessage());
}
final List<MavenRepositoryMetadata> filter = filterCaptor.getAllValues();
assertEquals(0, filter.size());
verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module));
verify(ioService, times(1)).startBatch(any(FileSystem.class), any(CommentedOption.class));
verify(pomService, times(1)).save(eq(pathToPom), eq(model.getPOM()), eq(pomMetaData), eq(comment));
verify(kModuleService, times(1)).save(eq(pathToKieModule), eq(kmodule), eq(kmoduleMetaData), eq(comment));
verify(importsService, times(1)).save(eq(pathToModuleImports), eq(projectImports), eq(projectImportsMetaData), eq(comment));
verify(repositoriesService, times(1)).save(eq(pathToModuleRepositories), eq(moduleRepositories), eq(comment));
verify(ioService, times(1)).endBatch();
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class DeploymentVerifier method verifyWithException.
/**
* Verifies if a given module can be deployed in current server for the given deployment mode.
* An example of when a module can't be deployed is when the deployment mode is DeploymentMode.VALIDATED and the
* module was already deployed. This case will raise a GAVAlreadyExistsException.
* @param module the module to verify.
* @param deploymentMode the deployment mode for doing the verification.
*/
public void verifyWithException(final Module module, DeploymentMode deploymentMode) {
if (DeploymentMode.VALIDATED.equals(deploymentMode)) {
// Check is the POM's GAV resolves to any pre-existing artifacts.
final GAV gav = module.getPom().getGav();
if (gav.isSnapshot()) {
return;
}
final ModuleRepositories projectRepositories = moduleRepositoriesService.load(((KieModule) module).getRepositoriesPath());
final Set<MavenRepositoryMetadata> repositories = repositoryResolver.getRepositoriesResolvingArtifact(gav, module, projectRepositories.filterByIncluded());
if (repositories.size() > 0) {
throw new GAVAlreadyExistsException(gav, repositories);
}
}
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class ModuleServiceImplNewModuleTest method testNewModuleCreationClashingGAVForced.
@Test()
public void testNewModuleCreationClashingGAVForced() throws URISyntaxException {
final Repository repository = mock(Repository.class);
final Path masterBranchRoot = mock(Path.class);
doReturn(Optional.of(new Branch("master", masterBranchRoot))).when(repository).getDefaultBranch();
final POM pom = new POM();
final String baseURL = "/";
final KieModule expected = new KieModule();
when(moduleRepositoryResolver.getRepositoriesResolvingArtifact(eq(pom.getGav()))).thenReturn(new HashSet<MavenRepositoryMetadata>() {
{
add(new MavenRepositoryMetadata("id", "url", MavenRepositorySource.SETTINGS));
}
});
when(saver.save(masterBranchRoot, pom, baseURL)).thenReturn(expected);
try {
moduleService.newModule(masterBranchRoot, pom, baseURL, DeploymentMode.FORCED);
} catch (GAVAlreadyExistsException e) {
fail("Unexpected exception thrown: " + e.getMessage());
}
}
Aggregations