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);
}
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"));
}
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"));
}
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();
}
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();
}
Aggregations