use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class SourceServiceImpl method getModules.
@Override
public Collection<Module> getModules(final Space space, final String repositoryAlias, final String branchName) {
checkNotNull("repositoryAlias", repositoryAlias);
checkNotNull("branchName", branchName);
final Repository repository = repositoryService.getRepositoryFromSpace(space, repositoryAlias);
if (repository == null) {
return new ArrayList<>();
} else {
final Optional<Branch> branch = repository.getBranch(branchName);
if (branch.isPresent()) {
return moduleService.getAllModules(branch.get());
} else {
return new ArrayList<>();
}
}
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class SourceServiceImpl method getBranches.
@Override
public Collection<String> getBranches(final Space space, final String repositoryName) {
checkNotNull("repositoryName", repositoryName);
final Repository repository = repositoryService.getRepositoryFromSpace(space, repositoryName);
return repository != null ? toBranchNames(repository.getBranches()) : new ArrayList<>();
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class SourceServiceImplTest method testProjects.
@Test
public void testProjects() {
final Repository repository = mock(Repository.class);
final Branch branch = new Branch(BRANCH_NAME, mock(Path.class));
doReturn(Optional.of(branch)).when(repository).getBranch(eq(BRANCH_NAME));
@SuppressWarnings("unchecked") final Set<Module> modules = mock(Set.class);
when(repositoryService.getRepositoryFromSpace(SPACE, REPO_NAME)).thenReturn(repository);
when(moduleService.getAllModules(branch)).thenReturn(modules);
final Collection<Module> result = service.getModules(SPACE, REPO_NAME, BRANCH_NAME);
assertEquals(modules, result);
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class KieMultipleDocumentEditorTest method testOnRepositoryRemoved.
@Test
public void testOnRepositoryRemoved() {
final Repository repository = mock(Repository.class);
when(workbenchContext.getActiveWorkspaceProject()).thenReturn(Optional.of(new WorkspaceProject(mock(OrganizationalUnit.class), repository, mock(Branch.class), mock(Module.class))));
editor.setupMenuBar();
editor.onRepositoryRemoved(new RepositoryRemovedEvent(repository));
verify(editor, times(1)).enableMenus(eq(false));
verify(editor, times(4)).enableMenuItem(eq(false), any(MenuItems.class));
verify(saveMenuItem, times(1)).setEnabled(eq(false));
verify(versionManagerMenuItem, times(1)).setEnabled(eq(false));
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ModuleSaverTest method testDuplicatedChildInManagedRepositoryPrevention.
/**
* This test checks that when we have a managed repository and the user tries to create a module "module1" in the
* given repository, and a module "module1" already exists. Then the parent pom.xml for the managed repository
* must remain untouched. i.e. If the module "module1" already exists then the parent pom.xml shouldn't be modified.
* In this way the parent pom.xml remains consistent with the already existing structure.
*/
@Test
public void testDuplicatedChildInManagedRepositoryPrevention() throws URISyntaxException, IOException {
final POM parentPom = mock(POM.class);
final POM newPOM = mock(POM.class);
final Repository repository = mock(Repository.class);
final String baseURL = "/";
final File test = File.createTempFile("test", Long.toString(System.nanoTime()));
final Path repositoryRootPath = paths.convert(fs.getPath(test.toURI()));
FileAlreadyExistsException fileExistsException = null;
when(repository.getDefaultBranch()).thenReturn(Optional.of(new Branch("master", repositoryRootPath)));
// name for the module we are trying to re-create over an existing one.
when(newPOM.getName()).thenReturn("existingModule");
// path that will be calculated for looking for the parent pom.xml for the managed repository. (the parent pom.xml
// lies basically in the root of the repository by definition.)
final org.uberfire.java.nio.file.Path parentPomNioPath = paths.convert(repositoryRootPath).resolve("pom.xml");
final Path parentPomVFSPath = paths.convert(parentPomNioPath);
// path that will be calculated for saving the module pom.xml for the module that are about to be created.
final org.uberfire.java.nio.file.Path moduleNioPath = paths.convert(repositoryRootPath).resolve("existingModule").resolve("pom.xml");
when(pomService.load(parentPomVFSPath)).thenReturn(parentPom);
// emulate the module already exists
when(ioService.exists(any())).thenReturn(true);
try {
saver.save(Paths.convert(moduleNioPath), newPOM, baseURL);
} catch (FileAlreadyExistsException e) {
fileExistsException = e;
}
// The file already exists must have been thrown, since the module already exists.
assertNotNull(fileExistsException);
// And also the parent pom must have never been updated/modified.
verify(pomService, never()).save(eq(parentPomVFSPath), any(POM.class), any(Metadata.class), any(String.class));
}
Aggregations