Search in sources :

Example 76 with StaplerRequest

use of org.kohsuke.stapler.StaplerRequest in project blueocean-plugin by jenkinsci.

the class ContainerFilter method filterNames.

private static String[] filterNames() {
    StaplerRequest req = Stapler.getCurrentRequest();
    if (req == null) {
        return new String[0];
    }
    String itemFilter = req.getParameter("filter");
    if (itemFilter == null) {
        return new String[0];
    }
    return itemFilter.split(",");
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest)

Example 77 with StaplerRequest

use of org.kohsuke.stapler.StaplerRequest in project blueocean-plugin by jenkinsci.

the class FavoriteContainerImpl method iterator.

@Override
public Iterator<BlueFavorite> iterator() {
    StaplerRequest request = Stapler.getCurrentRequest();
    int start = 0;
    int limit = PagedResponse.DEFAULT_LIMIT;
    if (request != null) {
        String startParam = request.getParameter("start");
        if (StringUtils.isNotBlank(startParam)) {
            start = Integer.parseInt(startParam);
        }
        String limitParam = request.getParameter("limit");
        if (StringUtils.isNotBlank(limitParam)) {
            limit = Integer.parseInt(limitParam);
        }
    }
    return iterator(start, limit);
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest)

Example 78 with StaplerRequest

use of org.kohsuke.stapler.StaplerRequest in project hudson-2.x by hudson.

the class CascadingUtilTest method testBuildExternalProperties.

@Test
@PrepareForTest({ Hudson.class, StaplerRequest.class })
public void testBuildExternalProperties() throws Exception {
    Job job = new FreeStyleProjectMock("job");
    StaplerRequest req = createMock(StaplerRequest.class);
    String javadocArchiverKey = "hudson-tasks-JavadocArchiver";
    JSONObject archiver = new JSONObject();
    archiver.put("javadoc_dir", "dir");
    archiver.put("keep_all", true);
    JSONObject json = new JSONObject();
    json.put(javadocArchiverKey, archiver);
    Hudson hudson = createMock(Hudson.class);
    Descriptor<Publisher> javadocDescriptor = new JavadocArchiver.DescriptorImpl();
    expect(hudson.getDescriptorOrDie(JavadocArchiver.class)).andReturn(javadocDescriptor);
    JavadocArchiver javadocArchiver = new JavadocArchiver("dir", true);
    expect(req.bindJSON(JavadocArchiver.class, archiver)).andReturn(javadocArchiver).anyTimes();
    List<Descriptor<Publisher>> descriptors = new ArrayList<Descriptor<Publisher>>();
    descriptors.add(javadocDescriptor);
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replay(Hudson.class, hudson, req);
    assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
    CascadingUtil.buildExternalProperties(req, archiver, descriptors, job);
    assertNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
    CascadingUtil.buildExternalProperties(req, json, descriptors, job);
    assertNotNull(CascadingUtil.getExternalProjectProperty(job, javadocArchiverKey).getValue());
    verifyAll();
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) Hudson(hudson.model.Hudson) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ArrayList(java.util.ArrayList) Publisher(hudson.tasks.Publisher) JSONObject(net.sf.json.JSONObject) Descriptor(hudson.model.Descriptor) JavadocArchiver(hudson.tasks.JavadocArchiver) Job(hudson.model.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 79 with StaplerRequest

use of org.kohsuke.stapler.StaplerRequest in project support-core-plugin by jenkinsci.

the class ReverseProxyTest method addContents_NoCurrentRequest.

@Test
public void addContents_NoCurrentRequest() {
    subject = new ReverseProxy() {

        @Override
        protected StaplerRequest getCurrentRequest() {
            return null;
        }
    };
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Container container = createContainer(baos);
    subject.addContents(container);
    for (String header : FORWARDED_HEADERS) {
        assertThat(baos.toString(), containsString(expectedMessage(header, ReverseProxy.Trilean.UNKNOWN)));
    }
}
Also used : Container(com.cloudbees.jenkins.support.api.Container) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

StaplerRequest (org.kohsuke.stapler.StaplerRequest)79 Test (org.junit.Test)45 MultiBranchProject (jenkins.branch.MultiBranchProject)28 JSONObject (net.sf.json.JSONObject)20 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)18 ServiceException (io.jenkins.blueocean.commons.ServiceException)17 BufferedReader (java.io.BufferedReader)16 StringReader (java.io.StringReader)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 User (hudson.model.User)14 Mailer (hudson.tasks.Mailer)13 StaplerResponse (org.kohsuke.stapler.StaplerResponse)8 File (java.io.File)7 BitbucketScmSaveFileRequest (io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketScmSaveFileRequest)6 ScmFile (io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Nonnull (javax.annotation.Nonnull)5 Item (hudson.model.Item)4 ArrayList (java.util.ArrayList)4