Search in sources :

Example 11 with ProjectScreenModel

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));
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) GAV(org.guvnor.common.services.project.model.GAV) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 12 with ProjectScreenModel

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));
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 13 with ProjectScreenModel

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;
}
Also used : Path(org.uberfire.backend.vfs.Path) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)

Example 14 with ProjectScreenModel

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());
}
Also used : Space(org.uberfire.spaces.Space) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 15 with ProjectScreenModel

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();
    });
}
Also used : ConcurrentChangePopup.newConcurrentUpdate(org.uberfire.ext.widgets.common.client.common.ConcurrentChangePopup.newConcurrentUpdate) HasBusyIndicator(org.uberfire.ext.widgets.common.client.common.HasBusyIndicator) Promises(org.uberfire.client.promise.Promises) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) ListPresenter(org.kie.workbench.common.screens.library.client.settings.util.ListPresenter) HashMap(java.util.HashMap) SavePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.SavePopUpPresenter) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Promise(elemental2.promise.Promise) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) UberElementalListItem(org.kie.workbench.common.screens.library.client.settings.util.UberElementalListItem) IsElement(org.jboss.errai.ui.client.local.api.elemental2.IsElement) ERROR(org.uberfire.workbench.events.NotificationEvent.NotificationType.ERROR) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) Observes(javax.enterprise.event.Observes) ProjectScreenService(org.kie.workbench.common.screens.projecteditor.service.ProjectScreenService) Customizable(org.uberfire.annotations.Customizable) DefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.DefaultErrorCallback) Event(javax.enterprise.event.Event) ListItemPresenter(org.kie.workbench.common.screens.library.client.settings.util.ListItemPresenter) DomGlobal(elemental2.dom.DomGlobal) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) WARNING(org.uberfire.workbench.events.NotificationEvent.NotificationType.WARNING) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) Message(org.jboss.errai.bus.client.api.messaging.Message) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) OnOpen(org.uberfire.lifecycle.OnOpen) Dependent(javax.enterprise.context.Dependent) ConflictingRepositoriesPopup(org.guvnor.common.services.project.client.repositories.ConflictingRepositoriesPopup) ObservablePath(org.uberfire.backend.vfs.ObservablePath) SUCCESS(org.uberfire.workbench.events.NotificationEvent.NotificationType.SUCCESS) Caller(org.jboss.errai.common.client.api.Caller) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UberElemental(org.uberfire.client.mvp.UberElemental) NotificationEvent(org.uberfire.workbench.events.NotificationEvent)

Aggregations

ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)31 Test (org.junit.Test)28 ModuleRepositories (org.guvnor.common.services.project.model.ModuleRepositories)9 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)9 POM (org.guvnor.common.services.project.model.POM)8 GAVAlreadyExistsException (org.guvnor.common.services.project.service.GAVAlreadyExistsException)6 Path (org.uberfire.backend.vfs.Path)6 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)5 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)5 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)5 FileSystem (org.uberfire.java.nio.file.FileSystem)5 GAV (org.guvnor.common.services.project.model.GAV)4 ArrayList (java.util.ArrayList)3 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)3 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)3 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)3 WhiteList (org.kie.workbench.common.services.shared.whitelist.WhiteList)3 DomGlobal (elemental2.dom.DomGlobal)1 HTMLElement (elemental2.dom.HTMLElement)1 Promise (elemental2.promise.Promise)1