use of org.guvnor.common.services.project.model.ModuleRepositories 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.guvnor.common.services.project.model.ModuleRepositories 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();
}
use of org.guvnor.common.services.project.model.ModuleRepositories in project kie-wb-common by kiegroup.
the class ProjectScreenServiceImplTest method setup.
@Before
public void setup() {
projectImports = new ProjectImports();
moduleRepositories = new ModuleRepositories();
loader = new ProjectScreenModelLoader(moduleService, pomService, metadataService, kModuleService, importsService, repositoriesService, whiteListService) {
@Override
protected boolean fileExists(final Path path) {
return true;
}
};
saver = new ProjectScreenModelSaver(pomService, kModuleService, importsService, repositoriesService, whiteListService, ioService, moduleService, repositoryResolver, commentedOptionFactory, pomModelCache);
service = new ProjectScreenServiceImpl(projectService, repositoryService, moduleService, loader, saver, repositoryCopier, pomService, metadataService);
when(module.getKModuleXMLPath()).thenReturn(pathToKieModule);
when(module.getImportsPath()).thenReturn(pathToModuleImports);
when(module.getRepositoriesPath()).thenReturn(pathToModuleRepositories);
when(module.getPom()).thenReturn(pom);
when(pathToPom.toURI()).thenReturn("default://pom.xml");
when(pomService.load(eq(pathToPom))).thenReturn(pom);
when(kModuleService.load(eq(pathToKieModule))).thenReturn(kmodule);
when(importsService.load(eq(pathToModuleImports))).thenReturn(projectImports);
when(repositoriesService.load(eq(pathToModuleRepositories))).thenReturn(moduleRepositories);
when(moduleService.resolveModule(eq(pathToPom))).thenReturn(module);
when(metadataService.getMetadata(eq(pathToPom))).thenReturn(pomMetaData);
when(metadataService.getMetadata(eq(pathToKieModule))).thenReturn(kmoduleMetaData);
when(metadataService.getMetadata(eq(pathToModuleImports))).thenReturn(projectImportsMetaData);
}
use of org.guvnor.common.services.project.model.ModuleRepositories 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.model.ModuleRepositories 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));
}
Aggregations