use of org.guvnor.common.services.project.model.MavenRepositoryMetadata 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.MavenRepositoryMetadata 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.MavenRepositoryMetadata 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.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.
the class ValidationItemPresenterTest method testSetup.
@Test
public void testSetup() {
final ModuleRepositories.ModuleRepository projectRepository = mock(ModuleRepositories.ModuleRepository.class);
final ValidationPresenter parentPresenter = mock(ValidationPresenter.class);
doReturn(new MavenRepositoryMetadata("test", "https://test.url", MavenRepositorySource.LOCAL)).when(projectRepository).getMetadata();
validationItemPresenter.setup(projectRepository, parentPresenter);
verify(view).init(eq(validationItemPresenter));
verify(view).setInclude(anyBoolean());
verify(view).setId(any());
verify(view).setUrl(any());
verify(view).setSource(any());
}
use of org.guvnor.common.services.project.model.MavenRepositoryMetadata in project kie-wb-common by kiegroup.
the class PomEditorServiceImplTest method testSaveNonClashingGAVChangeToGAV.
@Test
public void testSaveNonClashingGAVChangeToGAV() {
final Set<ModuleRepositories.ModuleRepository> moduleRepositoriesMetadata = new HashSet<ModuleRepositories.ModuleRepository>();
final ModuleRepositories moduleRepositories = new ModuleRepositories(moduleRepositoriesMetadata);
when(moduleRepositoriesService.load(moduleRepositoriesPath)).thenReturn(moduleRepositories);
final ArgumentCaptor<MavenRepositoryMetadata> resolvedRepositoriesCaptor = ArgumentCaptor.forClass(MavenRepositoryMetadata.class);
when(repositoryResolver.getRepositoriesResolvingArtifact(eq(pomXml), resolvedRepositoriesCaptor.capture())).thenReturn(Collections.EMPTY_SET);
when(pom.getGav()).thenReturn(new GAV("groupId", "artifactId", "0.0.2"));
service.save(pomPath, pomXml, metaData, comment, DeploymentMode.VALIDATED);
verify(moduleService, times(1)).resolveModule(pomPath);
verify(moduleRepositoriesService, times(1)).load(moduleRepositoriesPath);
verify(repositoryResolver, times(1)).getRepositoriesResolvingArtifact(eq(pomXml));
final List<MavenRepositoryMetadata> resolvedRepositories = resolvedRepositoriesCaptor.getAllValues();
assertNotNull(resolvedRepositories);
assertEquals(0, resolvedRepositories.size());
verify(ioService, times(1)).startBatch(any(FileSystem.class));
verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), eq(pomXml), eq(attributes), any(CommentedOption.class));
verify(ioService, times(1)).endBatch();
}
Aggregations