use of io.jenkins.blueocean.rest.Reachable in project blueocean-plugin by jenkinsci.
the class RunSearch method collectRuns.
private static List<BlueRun> collectRuns(Iterator<? extends Run> runIterator, final Link parent, int start, int limit) {
List<BlueRun> runs = new ArrayList<>();
// Skip up to the start
int skipCount = start;
while (runIterator.hasNext()) {
if (skipCount > 0) {
runIterator.next();
skipCount--;
} else {
BlueRun run = BlueRunFactory.getRun(runIterator.next(), new Reachable() {
@Override
public Link getLink() {
return parent;
}
});
if (run != null) {
runs.add(run);
}
}
if (runs.size() >= limit) {
return runs;
}
}
return runs;
}
use of io.jenkins.blueocean.rest.Reachable in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method testOrganizationFolderFactoryNoPermissionsFolder.
@Test(expected = ServiceException.ForbiddenException.class)
public void testOrganizationFolderFactoryNoPermissionsFolder() throws Exception {
List<OrganizationFolderPipelineImpl.OrganizationFolderFactory> organizationFolderFactoryList = ExtensionList.lookup(OrganizationFolderPipelineImpl.OrganizationFolderFactory.class);
OrganizationFolderFactoryTestImpl organizationFolderFactoryTest = ((ExtensionList<OrganizationFolderPipelineImpl.OrganizationFolderFactory>) organizationFolderFactoryList).get(OrganizationFolderFactoryTestImpl.class);
assertNotNull(organizationFolderFactoryTest);
OrganizationFolderPipelineImpl folderPipeline = organizationFolderFactoryTest.getFolder(orgFolder, new Reachable() {
@Override
public Link getLink() {
return organization.getLink().rel("/pipelines/");
}
}, mockOrganization());
assertNotNull(folderPipeline);
assertNotNull(folderPipeline.getQueue());
assertNotNull(folderPipeline.getQueue().iterator());
// Make sure the user does not have permissions to that folder
PowerMockito.when(orgFolder.getACL()).thenReturn(new ACL() {
@Override
public boolean hasPermission(Authentication arg0, Permission arg1) {
return false;
}
});
ScmResourceImpl scmResource = new ScmResourceImpl(orgFolder, folderPipeline);
StaplerRequest staplerRequest = PowerMockito.mock(StaplerRequest.class);
assertEquals("hello", scmResource.getContent(staplerRequest));
}
use of io.jenkins.blueocean.rest.Reachable in project blueocean-plugin by jenkinsci.
the class ChangeSetResourceTest method testChangeSet.
@Test
public void testChangeSet() {
Reachable reachable = mock(Reachable.class);
when(reachable.getLink()).thenReturn(new Link("/foo/bar"));
User user = mock(User.class);
when(user.getId()).thenReturn("vivek");
ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
when(entry.getAuthor()).thenReturn(user);
when(entry.getTimestamp()).thenReturn(System.currentTimeMillis());
when(entry.getCommitId()).thenReturn("12345");
when(entry.getMsg()).thenReturn("test changeset");
when(entry.getAffectedPaths()).thenReturn(Collections.singleton("/foo/bar"));
ChangeSetResource changeSetResource = new ChangeSetResource(new OrganizationImpl("testorg", mock(Folder.class)), entry, reachable);
assertEquals(user.getId(), changeSetResource.getAuthor().getId());
assertEquals(entry.getCommitId(), changeSetResource.getCommitId());
assertEquals(entry.getMsg(), changeSetResource.getMsg());
}
use of io.jenkins.blueocean.rest.Reachable in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method testOrgFolderRun.
@Test
@WithoutJenkins
public void testOrgFolderRun() {
OrganizationFolderPipelineImpl organizationFolder = new OrganizationFolderPipelineImpl(mockOrganization(), orgFolder, new Link("/a/b/")) {
};
OrganizationFolderRunImpl organizationFolderRun = new OrganizationFolderRunImpl(organizationFolder, new Reachable() {
@Override
public Link getLink() {
return new Link("/a/b/");
}
});
assertEquals(orgFolder.getName(), organizationFolderRun.getPipeline());
assertEquals(organization.getName(), organizationFolderRun.getOrganization());
assertNotNull(organizationFolder.getRuns());
}
use of io.jenkins.blueocean.rest.Reachable in project blueocean-plugin by jenkinsci.
the class FavoritesStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
User jenkinsUser = User.current();
if (jenkinsUser != null) {
BlueOrganization organization = IterableUtils.getFirst(OrganizationFactory.getInstance().list(), null);
if (organization != null) {
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
// don't need this list when at pipeline pages
if (pipelineFullName != null) {
return null;
}
UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
if (favoritesContainer != null) {
JSONArray favorites = new JSONArray();
// Limit the number of favorites to return to a sane amount
Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);
while (favoritesIterator.hasNext()) {
Reachable favorite = favoritesIterator.next();
try {
favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
return null;
}
}
return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
}
}
}
// Don't preload any data on the page.
return null;
}
Aggregations