Search in sources :

Example 6 with ProjectScreenModel

use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.

the class ProjectScreenModelSaverTest method checkPOMSaveInvalidatesPomModelCache.

@Test
public void checkPOMSaveInvalidatesPomModelCache() {
    // See https://issues.jboss.org/browse/RHBRMS-2822
    // Saving the pom.xml (eventually) triggers an InvalidateDMOProjectCacheEvent once VFS's WatchService
    // has observed the file change after the batch has been committed. The InvalidateDMOProjectCacheEvent then
    // invalidates the PomModelCache. The PomModelCache is used to find the Project's GAV when the Project is
    // "Built (& Deployed)" and if it's content is stale can lead to the generated KJAR containing the
    // wrong GAV. Therefore invalidate the PomModelCache as soon as the save starts.
    final ProjectScreenModel model = new ProjectScreenModel();
    final Metadata pomMetaData = new Metadata();
    final POM pom = new POM();
    model.setPOM(pom);
    model.setPOMMetaData(pomMetaData);
    KieModule module = mock(KieModule.class);
    when(moduleService.resolveModule(pathToPom)).thenReturn(module);
    saver.save(pathToPom, model, DeploymentMode.FORCED, "message");
    verify(pomModelCache).invalidateCache(module);
}
Also used : Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 7 with ProjectScreenModel

use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.

the class ProjectScreenModelSaverTest method testImportsSave.

@Test
public void testImportsSave() throws Exception {
    final ProjectScreenModel model = new ProjectScreenModel();
    final ProjectImports projectImports = new ProjectImports();
    model.setProjectImports(projectImports);
    final Path pathToImports = mock(Path.class);
    model.setPathToImports(pathToImports);
    final Metadata metadata = new Metadata();
    model.setProjectImportsMetaData(metadata);
    saver.save(pathToPom, model, DeploymentMode.FORCED, "message imports");
    verify(importsService).save(eq(pathToImports), eq(projectImports), eq(metadata), eq("message imports"));
}
Also used : Path(org.uberfire.backend.vfs.Path) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 8 with ProjectScreenModel

use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.

the class ProjectScreenModelSaverTest method testRepositoriesSave.

@Test
public void testRepositoriesSave() throws Exception {
    final ProjectScreenModel model = new ProjectScreenModel();
    final ModuleRepositories moduleRepositories = new ModuleRepositories();
    model.setRepositories(moduleRepositories);
    final Path pathToRepositories = mock(Path.class);
    model.setPathToRepositories(pathToRepositories);
    saver.save(pathToPom, model, DeploymentMode.FORCED, "message repositories");
    verify(repositoriesService).save(eq(pathToRepositories), eq(moduleRepositories), eq("message repositories"));
}
Also used : Path(org.uberfire.backend.vfs.Path) ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 9 with ProjectScreenModel

use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveNonClashingGAVNoChangeToGAV.

@Test
public void testSaveNonClashingGAVNoChangeToGAV() {
    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 String comment = "comment";
    service.save(pathToPom, model, comment);
    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();
}
Also used : CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) Test(org.junit.Test)

Example 10 with ProjectScreenModel

use of org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel in project kie-wb-common by kiegroup.

the class ProjectScreenServiceImplTest method testSaveClashingGAVFilteredRepositoryChangeToGAV.

@Test()
public void testSaveClashingGAVFilteredRepositoryChangeToGAV() {
    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(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, times(1)).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();
}
Also used : ModuleRepositories(org.guvnor.common.services.project.model.ModuleRepositories) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) POM(org.guvnor.common.services.project.model.POM) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) FileSystem(org.uberfire.java.nio.file.FileSystem) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) GAV(org.guvnor.common.services.project.model.GAV) Test(org.junit.Test)

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