use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class ProjectScreenServiceImplTest method testSaveClashingGAVChangeToGAV.
@Test()
public void testSaveClashingGAVChangeToGAV() {
when(pathToPom.toURI()).thenReturn("default://p0/pom.xml");
final ProjectScreenModel model = new ProjectScreenModel();
model.setPOM(new POM(new GAV("groupId", "artifactId", "2.0.0")));
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";
try {
service.save(pathToPom, model, comment);
} catch (GAVAlreadyExistsException e) {
// This is expected! We catch here rather than let JUnit handle it with
// @Test(expected = GAVAlreadyExistsException.class) so we can verify
// that only the expected methods have been invoked.
} catch (Exception e) {
fail(e.getMessage());
}
verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module), any(MavenRepositoryMetadata.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));
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class ProjectScreenServiceImplTest method testSaveClashingGAVNoChangeToGAV.
@Test()
public void testSaveClashingGAVNoChangeToGAV() {
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";
try {
service.save(pathToPom, model, comment);
} catch (GAVAlreadyExistsException e) {
fail(e.getMessage());
}
verify(repositoryResolver, never()).getRepositoriesResolvingArtifact(eq(model.getPOM().getGav()), eq(module));
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 AddProjectPopUpPresenter method getErrorCallback.
private ErrorCallback<?> getErrorCallback() {
Map<Class<? extends Throwable>, CommandWithThrowableDrivenErrorCallback.CommandWithThrowable> errors = new HashMap<Class<? extends Throwable>, CommandWithThrowableDrivenErrorCallback.CommandWithThrowable>() {
{
put(GAVAlreadyExistsException.class, parameter -> {
GAVAlreadyExistsException exception = (GAVAlreadyExistsException) parameter;
view.hideBusyIndicator();
conflictingRepositoriesPopup.setContent(exception.getGAV(), ((GAVAlreadyExistsException) parameter).getRepositories(), () -> {
conflictingRepositoriesPopup.hide();
createProject(DeploymentMode.FORCED);
});
conflictingRepositoriesPopup.show();
});
put(FileAlreadyExistsException.class, parameter -> {
view.hideBusyIndicator();
view.showError(view.getDuplicatedProjectMessage());
});
}
};
return createErrorCallback(errors);
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class SettingsPresenterTest method testHandleSaveProjectScreenModelGavAlreadyExistsException.
@Test
public void testHandleSaveProjectScreenModelGavAlreadyExistsException() {
doReturn(promises.resolve()).when(settingsPresenter).defaultErrorResolution(any());
doReturn(promises.resolve()).when(settingsPresenter).handlePomConcurrentUpdate(any(), any(), any());
final GAVAlreadyExistsException testException = new GAVAlreadyExistsException();
settingsPresenter.handleSaveProjectScreenModelError("Test comment", null, testException);
verify(settingsPresenter, never()).defaultErrorResolution(any());
verify(settingsPresenter).handlePomConcurrentUpdate(eq("Test comment"), any(), eq(testException));
}
use of org.guvnor.common.services.project.service.GAVAlreadyExistsException in project kie-wb-common by kiegroup.
the class PomEditorServiceImplTest method testSaveClashingGAVNoChangeToGAV.
@Test
public void testSaveClashingGAVNoChangeToGAV() {
when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.1"));
try {
service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
} catch (GAVAlreadyExistsException e) {
// This is should not be thrown if the GAV has not changed.
fail(e.getMessage());
}
verify(moduleService, times(1)).resolveModule(pomPath);
verify(moduleRepositoriesService, never()).load(moduleRepositoriesPath);
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();
}
Aggregations