use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel 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.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel 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.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.
the class ExamplesServiceImpl method renameIfNecessary.
private WorkspaceProject renameIfNecessary(final OrganizationalUnit ou, final WorkspaceProject project) {
String name = project.getName();
Collection<WorkspaceProject> projectsWithSameName = projectService.getAllWorkspaceProjectsByName(ou, name);
if (projectsWithSameName.size() > 1) {
name = this.projectService.createFreshProjectName(ou, project.getName());
}
if (!name.equals(project.getName())) {
final Path pomXMLPath = project.getMainModule().getPomXMLPath();
final ProjectScreenModel model = projectScreenService.load(pomXMLPath);
model.getPOM().setName(name);
projectScreenService.save(pomXMLPath, model, "");
return projectService.resolveProject(pomXMLPath);
}
return project;
}
use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.
the class ExamplesServiceImplRepositoryNamesTest method nameIsTaken.
@Test
public void nameIsTaken() {
String module1 = "module1";
String module1_1 = "module1 [1]";
doReturn(mock(Repository.class)).when(repositoryService).getRepositoryFromSpace(any(Space.class), eq(module1));
WorkspaceProject project1 = mock(WorkspaceProject.class);
doReturn(module1).when(project1).getName();
List<WorkspaceProject> projects = new ArrayList<>();
projects.add(project1);
projects.add(project1);
doReturn(projects).when(projectService).getAllWorkspaceProjectsByName(any(), eq(module1));
doReturn(module1_1).when(projectService).createFreshProjectName(any(), eq(module1));
service.setupExamples(exampleOrganizationalUnit, exampleProjects);
verify(projectScreenService).save(any(), modelCapture.capture(), any());
final ProjectScreenModel model = modelCapture.getValue();
assertEquals(module1_1, model.getPOM().getName());
}
use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.
the class SettingsPresenter method setupSection.
Promise<Object> setupSection(final ProjectScreenModel model, final Section section) {
return promises.resolve().then(ignore -> section.setup(model)).catch_(e -> {
sections.remove(section);
notificationEvent.fire(new NotificationEvent(getSectionSetupErrorMessage(section), WARNING));
return promises.reject(e);
}).then(i -> {
section.getMenuItem().setup(section, this);
resetDirtyIndicator(section);
return promises.resolve();
}).catch_(e -> {
DomGlobal.console.info(e);
return promises.resolve();
});
}
Aggregations