Ejemplo n.º 1
0
 @Test
 public void testGetItem() throws Exception{
     ListView view = listView("foo");
     FreeStyleProject job1 = j.createFreeStyleProject("free");
     MatrixProject job2 = j.createMatrixProject("matrix");
     FreeStyleProject job3 = j.createFreeStyleProject("not-included");
     view.jobNames.add(job2.getDisplayName());
     view.jobNames.add(job1.getDisplayName());
     assertEquals("View should return job " + job1.getDisplayName(),job1,  view.getItem("free"));
     assertNotNull("View should return null.", view.getItem("not-included"));
 }
Ejemplo n.º 2
0
  @Test
  public void nonSensitiveParameters() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdb =
        new ParametersDefinitionProperty(
            new StringParameterDefinition("string", "defaultValue", "string description"));
    project.addProperty(pdb);

    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);

    FreeStyleBuild build = project.scheduleBuild2(0).get();
    Set<String> sensitiveVars = build.getSensitiveBuildVariables();

    assertNotNull(sensitiveVars);
    assertFalse(sensitiveVars.contains("string"));
  }
Ejemplo n.º 3
0
  @Test
  @Issue("JENKINS-11543")
  public void unicodeParametersArePresetCorrectly() throws Exception {
    final FreeStyleProject p = j.createFreeStyleProject();
    ParametersDefinitionProperty pdb =
        new ParametersDefinitionProperty(
            new StringParameterDefinition("sname:a¶‱ﻷ", "svalue:a¶‱ﻷ", "sdesc:a¶‱ﻷ"),
            new FileParameterDefinition("fname:a¶‱ﻷ", "fdesc:a¶‱ﻷ"));
    p.addProperty(pdb);

    WebClient wc = j.createWebClient();
    wc.setThrowExceptionOnFailingStatusCode(false); // Ignore 405
    HtmlPage page = wc.getPage(p, "build");

    // java.lang.IllegalArgumentException: No such parameter definition: <gibberish>.
    wc.setThrowExceptionOnFailingStatusCode(true);
    final HtmlForm form = page.getFormByName("parameters");
    form.submit(form.getButtonByCaption("Build"));
  }
Ejemplo n.º 4
0
  @Test
  public void choiceWithLTGT() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdp =
        new ParametersDefinitionProperty(
            new ChoiceParameterDefinition("choice", "Choice 1\nChoice <2>", "choice description"));
    project.addProperty(pdp);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);

    WebClient wc = j.createWebClient();
    wc.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec");
    HtmlForm form = page.getFormByName("parameters");

    HtmlElement element =
        (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']");
    assertNotNull(element);
    assertEquals(
        "choice description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    assertEquals(
        "choice",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
    HtmlOption opt =
        (HtmlOption) element.selectSingleNode("td/div/select/option[@value='Choice <2>']");
    assertNotNull(opt);
    assertEquals("Choice <2>", opt.asText());
    opt.setSelected(true);

    j.submit(form);
    Queue.Item q = j.jenkins.getQueue().getItem(project);
    if (q != null) q.getFuture().get();
    else Thread.sleep(1000);

    assertNotNull(builder.getEnvVars());
    assertEquals("Choice <2>", builder.getEnvVars().get("CHOICE"));
  }
Ejemplo n.º 5
0
  @Test
  @Issue("JENKINS-3539")
  public void fileParameterNotSet() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdp =
        new ParametersDefinitionProperty(new FileParameterDefinition("filename", "description"));
    project.addProperty(pdp);

    WebClient wc = j.createWebClient();
    wc.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec");
    HtmlForm form = page.getFormByName("parameters");

    j.submit(form);
    Queue.Item q = j.jenkins.getQueue().getItem(project);
    if (q != null) q.getFuture().get();
    else Thread.sleep(1000);

    assertFalse("file must not exist", project.getSomeWorkspace().child("filename").exists());
  }
Ejemplo n.º 6
0
    @Test
    @Issue("JENKINS-21474")
    public void testGetComputersNPE() throws Exception {
        ListView view = listView("aView");
        view.filterExecutors = true;

        DumbSlave dedicatedSlave = j.createOnlineSlave();
        dedicatedSlave.setMode(Mode.EXCLUSIVE);
        view.add(j.createFreeStyleProject());

        FreeStyleProject tiedJob = j.createFreeStyleProject();
        tiedJob.setAssignedNode(dedicatedSlave);
        view.add(tiedJob);

        DumbSlave notIncludedSlave = j.createOnlineSlave();
        notIncludedSlave.setMode(Mode.EXCLUSIVE);

        assertContainsNodes(view, j.jenkins, dedicatedSlave);
        assertNotContainsNodes(view, notIncludedSlave);
    }
Ejemplo n.º 7
0
    @Test
    public void testGetQueueItems() throws IOException, Exception{
        ListView view1 = listView("view1");
        view1.filterQueue = true;
        ListView view2 = listView("view2");
        view2.filterQueue = true;

        FreeStyleProject inView1 = j.createFreeStyleProject("in-view1");
        inView1.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view1.add(inView1);

        MatrixProject inView2 = j.createMatrixProject("in-view2");
        inView2.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view2.add(inView2);

        FreeStyleProject notInView = j.createFreeStyleProject("not-in-view");
        notInView.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));

        FreeStyleProject inBothViews = j.createFreeStyleProject("in-both-views");
        inBothViews.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view1.add(inBothViews);
        view2.add(inBothViews);

        Queue.getInstance().schedule(notInView, 0);
        Queue.getInstance().schedule(inView1, 0);
        Queue.getInstance().schedule(inView2, 0);
        Queue.getInstance().schedule(inBothViews, 0);

        Thread.sleep(1000);

        assertContainsItems(view1, inView1, inBothViews);
        assertNotContainsItems(view1, notInView, inView2);
        assertContainsItems(view2, inView2, inBothViews);
        assertNotContainsItems(view2, notInView, inView1);
    }
Ejemplo n.º 8
0
 @Test
 public void testSave() throws Exception{
     ListView view = listView("foo");
     FreeStyleProject job = j.createFreeStyleProject("free");
     view.jobNames.add("free");
     view.save();
     j.jenkins.doReload();
     //wait until all configuration are reloaded
     if(j.jenkins.servletContext.getAttribute("app") instanceof HudsonIsLoading){
         Thread.sleep(500);
     }
     assertTrue("View does not contains job free after load.", j.jenkins.getView(view.getDisplayName()).contains(j.jenkins.getItem(job.getName())));       
 }
Ejemplo n.º 9
0
    @Test
    public void testGetComputers() throws IOException, Exception{
        ListView view1 = listView("view1");
        ListView view2 = listView("view2");
        ListView view3 = listView("view3");
        view1.filterExecutors=true;
        view2.filterExecutors=true;
        view3.filterExecutors=true;

        Slave slave0 = j.createOnlineSlave(j.jenkins.getLabel("label0"));
        Slave slave1 = j.createOnlineSlave(j.jenkins.getLabel("label1"));
        Slave slave2 = j.createOnlineSlave(j.jenkins.getLabel("label2"));
        Slave slave3 = j.createOnlineSlave(j.jenkins.getLabel("label0"));
        Slave slave4 = j.createOnlineSlave(j.jenkins.getLabel("label4"));

        FreeStyleProject freestyleJob = j.createFreeStyleProject("free");
        view1.add(freestyleJob);
        freestyleJob.setAssignedLabel(j.jenkins.getLabel("label0||label2"));

        MatrixProject matrixJob = j.createMatrixProject("matrix");
        view1.add(matrixJob);
        matrixJob.setAxes(new AxisList(
                new LabelAxis("label", Arrays.asList("label1"))
        ));

        FreeStyleProject noLabelJob = j.createFreeStyleProject("not-assigned-label");
        view3.add(noLabelJob);
        noLabelJob.setAssignedLabel(null);

        FreeStyleProject foreignJob = j.createFreeStyleProject("in-other-view");
        view2.add(foreignJob);
        foreignJob.setAssignedLabel(j.jenkins.getLabel("label0||label1"));

        // contains all slaves having labels associated with freestyleJob or matrixJob
        assertContainsNodes(view1, slave0, slave1, slave2, slave3);
        assertNotContainsNodes(view1, slave4);

        // contains all slaves having labels associated with foreignJob
        assertContainsNodes(view2, slave0, slave1, slave3);
        assertNotContainsNodes(view2, slave2, slave4);

        // contains all slaves as it contains noLabelJob that can run everywhere
        assertContainsNodes(view3, slave0, slave1, slave2, slave3, slave4);
    }
Ejemplo n.º 10
0
  @Test
  public void parameterTypes() throws Exception {
    FreeStyleProject otherProject = j.createFreeStyleProject();
    otherProject.scheduleBuild2(0).get();

    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdp =
        new ParametersDefinitionProperty(
            new StringParameterDefinition("string", "defaultValue", "string description"),
            new BooleanParameterDefinition("boolean", true, "boolean description"),
            new ChoiceParameterDefinition("choice", "Choice 1\nChoice 2", "choice description"),
            new RunParameterDefinition("run", otherProject.getName(), "run description", null));
    project.addProperty(pdp);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);

    WebClient wc = j.createWebClient();
    wc.setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = wc.goTo("job/" + project.getName() + "/build?delay=0sec");

    HtmlForm form = page.getFormByName("parameters");

    HtmlElement element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='string']");
    assertNotNull(element);
    assertEquals(
        "string description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());

    HtmlTextInput stringParameterInput =
        (HtmlTextInput) element.selectSingleNode(".//input[@name='value']");
    assertEquals("defaultValue", stringParameterInput.getAttribute("value"));
    assertEquals(
        "string",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());
    stringParameterInput.setAttribute("value", "newValue");

    element = (HtmlElement) form.selectSingleNode("//tr[td/div/input/@value='boolean']");
    assertNotNull(element);
    assertEquals(
        "boolean description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    Object o = element.selectSingleNode(".//input[@name='value']");
    System.out.println(o);
    HtmlCheckBoxInput booleanParameterInput = (HtmlCheckBoxInput) o;
    assertEquals(true, booleanParameterInput.isChecked());
    assertEquals(
        "boolean",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());

    element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='choice']");
    assertNotNull(element);
    assertEquals(
        "choice description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    assertEquals(
        "choice",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());

    element = (HtmlElement) form.selectSingleNode(".//tr[td/div/input/@value='run']");
    assertNotNull(element);
    assertEquals(
        "run description",
        ((HtmlElement)
                element
                    .getNextSibling()
                    .getNextSibling()
                    .selectSingleNode("td[@class='setting-description']"))
            .getTextContent());
    assertEquals(
        "run",
        ((HtmlElement) element.selectSingleNode("td[@class='setting-name']")).getTextContent());

    j.submit(form);
    Queue.Item q = j.jenkins.getQueue().getItem(project);
    if (q != null) q.getFuture().get();
    else Thread.sleep(1000);

    assertEquals("newValue", builder.getEnvVars().get("STRING"));
    assertEquals("true", builder.getEnvVars().get("BOOLEAN"));
    assertEquals("Choice 1", builder.getEnvVars().get("CHOICE"));
    assertEquals(
        j.jenkins.getRootUrl() + otherProject.getLastBuild().getUrl(),
        builder.getEnvVars().get("RUN"));
  }