Search in sources :

Example 16 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project support-core-plugin by jenkinsci.

the class SupportActionTest method takeSnapshotAndMakeSureSomethingHappens.

/**
 * Integration test that simulates the user action of clicking the button to generate the bundle.
 *
 * <p>
 * If any warning is reported to j.u.l logger, treat that as a sign of failure, because
 * support-core plugin works darn hard to try to generate something in the presence of failing
 * {@link Component} impls.
 */
@Test
public void takeSnapshotAndMakeSureSomethingHappens() throws Exception {
    rule.createSlave("slave1", "test", null).getComputer().connect(false).get();
    rule.createSlave("slave2", "test", null).getComputer().connect(false).get();
    RingBufferLogHandler checker = new RingBufferLogHandler();
    Logger logger = Logger.getLogger(SupportPlugin.class.getPackage().getName());
    logger.addHandler(checker);
    try {
        WebClient wc = rule.createWebClient();
        HtmlPage p = wc.goTo(root.getUrlName());
        HtmlForm form = p.getFormByName("bundle-contents");
        HtmlButton submit = (HtmlButton) form.getHtmlElementsByTagName("button").get(0);
        Page zip = submit.click();
        File zipFile = File.createTempFile("test", "zip");
        IOUtils.copy(zip.getWebResponse().getContentAsStream(), zipFile);
        ZipFile z = new ZipFile(zipFile);
        // check the presence of files
        // TODO: emit some log entries and see if it gets captured here
        assertNotNull(z.getEntry("about.md"));
        assertNotNull(z.getEntry("nodes.md"));
        assertNotNull(z.getEntry("nodes/master/thread-dump.txt"));
        if (SystemPlatform.LINUX == SystemPlatform.current()) {
            List<String> files = Arrays.asList("proc/swaps.txt", "proc/cpuinfo.txt", "proc/mounts.txt", "proc/system-uptime.txt", "proc/net/rpc/nfs.txt", "proc/net/rpc/nfsd.txt", "proc/meminfo.txt", "proc/self/status.txt", "proc/self/cmdline", "proc/self/environ", "proc/self/limits.txt", "proc/self/mountstats.txt", "sysctl.txt", "dmesg.txt", "userid.txt", "dmi.txt");
            for (String file : files) {
                assertNotNull(file + " was not found in the bundle", z.getEntry("nodes/master/" + file));
            }
        }
    } finally {
        logger.removeHandler(checker);
        for (LogRecord r : checker.getView()) {
            if (r.getLevel().intValue() >= Level.WARNING.intValue()) {
                Throwable thrown = r.getThrown();
                if (thrown != null)
                    thrown.printStackTrace(System.err);
                fail(r.getMessage());
            }
        }
    }
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) RingBufferLogHandler(hudson.util.RingBufferLogHandler) Logger(java.util.logging.Logger) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) ZipFile(java.util.zip.ZipFile) LogRecord(java.util.logging.LogRecord) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 17 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project shiro by apache.

the class ContainerIntegrationIT method logIn.

@Test
public void logIn() throws FailingHttpStatusCodeException, IOException, InterruptedException {
    HtmlPage page = webClient.getPage(getBaseUri() + "s/login");
    HtmlForm form = page.getFormByName("loginForm");
    form.<HtmlInput>getInputByName("username").setValueAttribute("admin");
    form.<HtmlInput>getInputByName("password").setValueAttribute("admin");
    page = form.<HtmlInput>getInputByValue("Login").click();
    // This'll throw an expection if not logged in
    page.getAnchorByHref("/s/logout");
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) Test(org.junit.Test)

Example 18 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project shiro by apache.

the class ContainerIntegrationIT method logInAndRememberMe.

@Test
public void logInAndRememberMe() throws Exception {
    HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
    HtmlForm form = page.getFormByName("loginform");
    form.<HtmlInput>getInputByName("username").setValueAttribute("root");
    form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
    HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe");
    checkbox.setChecked(true);
    page = form.<HtmlInput>getInputByName("submit").click();
    jetty.stop();
    jetty.start();
    page = webClient.getPage(getBaseUri());
    // page.getAnchorByHref("/logout");
    WebAssert.assertLinkPresentWithText(page, "Log out");
    page = page.getAnchorByHref("/account").click();
    // login page should be shown again - user remembered but not authenticated
    WebAssert.assertFormPresent(page, "loginform");
}
Also used : HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) Test(org.junit.Test)

Example 19 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project promoted-builds-plugin by jenkinsci.

the class ManualConditionTest method testManualPromotionProcessViaWebClient.

@Test
public void testManualPromotionProcessViaWebClient() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    ManualCondition condition = new ManualCondition();
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
    foo.conditions.add(condition);
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertNull(b1.getAction(ManualApproval.class));
    HtmlPage page = j.createWebClient().getPage(b1, "promotion");
    // Approve Promotion
    List<HtmlForm> forms = getFormsByName(page, "approve");
    assertFalse(forms.isEmpty());
    assertEquals(1, forms.size());
    HtmlForm form = forms.get(0);
    List<HtmlElement> parameters = getFormParameters(form);
    assertEquals(parameters.size(), condition.getParameterDefinitions().size());
    for (HtmlElement param : parameters) {
        HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
        v.setAttribute("value", v.getAttribute("value") + "1");
    }
    submit(forms.get(0));
    ManualApproval approval = b1.getAction(ManualApproval.class);
    assertNotNull(approval);
    SortedMap<Integer, Promotion> builds = foo.getBuildsAsMap();
    assertNotNull(builds);
    assertEquals(1, builds.size());
    // Re-Execute approved promotion
    page = j.createWebClient().getPage(b1, "promotion");
    forms = getFormsByName(page, "build");
    assertFalse(forms.isEmpty());
    assertEquals(1, forms.size());
    form = forms.get(0);
    parameters = getFormParameters(form);
    assertEquals(parameters.size(), condition.getParameterDefinitions().size());
    for (HtmlElement param : parameters) {
        HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
        v.setAttribute("value", v.getAttribute("value") + "2");
    }
    submit(form);
    builds = foo.getBuildsAsMap();
    assertEquals(2, builds.size());
    List<ManualApproval> actions = b1.getActions(ManualApproval.class);
    assertEquals(1, actions.size());
    PromotedBuildAction buildActions = b1.getAction(PromotedBuildAction.class);
    int buildIndex = 1;
    String valueSufix = "1";
    List<Promotion> promotions = new ArrayList<Promotion>();
    promotions.addAll(builds.values());
    Collections.reverse(promotions);
    for (Promotion build : promotions) {
        List<ParameterDefinition> values = build.getParameterDefinitionsWithValue();
        assertEquals(values.size(), condition.getParameterDefinitions().size());
        for (ParameterDefinition v : values) {
            assertTrue(v instanceof StringParameterDefinition);
            String pvalue = ((StringParameterDefinition) v).getDefaultValue();
            assertTrue(pvalue.endsWith(valueSufix));
        }
        buildIndex++;
        valueSufix += buildIndex;
    }
    for (Status status : buildActions.getPromotions()) {
        assertNotNull(status.getLast() != null);
        List<ParameterDefinition> values = status.getLast().getParameterDefinitionsWithValue();
        assertEquals(values.size(), condition.getParameterDefinitions().size());
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) ArrayList(java.util.ArrayList) FreeStyleBuild(hudson.model.FreeStyleBuild) Promotion(hudson.plugins.promoted_builds.Promotion) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Example 20 with HtmlForm

use of com.gargoylesoftware.htmlunit.html.HtmlForm in project promoted-builds-plugin by jenkinsci.

the class ManualConditionInheritanceTest method testManualPromotionProcessViaWebClient.

@Test
public void testManualPromotionProcessViaWebClient() throws Exception {
    InheritanceProjectsPair inheritanceProjectsPair = j.createInheritanceProjectDerivedWithBase();
    ExtensionList<Descriptor> list = Jenkins.get().getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(inheritanceProjectsPair.getBase());
    inheritanceProjectsPair.getDerived().addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    ManualCondition condition = new ManualCondition();
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
    foo.conditions.add(condition);
    InheritanceBuild b1 = j.assertBuildStatusSuccess(inheritanceProjectsPair.getDerived().scheduleBuild2(0));
    assertNull(b1.getAction(ManualApproval.class));
    HtmlPage page = j.createWebClient().getPage(b1, "promotion");
    // Approve Promotion
    List<HtmlForm> forms = getFormsByName(page, "approve");
    assertFalse(forms.isEmpty());
    assertEquals(1, forms.size());
    HtmlForm form = forms.get(0);
    List<HtmlElement> parameters = getFormParameters(form);
    assertEquals(parameters.size(), condition.getParameterDefinitions().size());
    for (HtmlElement param : parameters) {
        HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
        v.setAttribute("value", v.getAttribute("value") + "1");
    }
    j.submit(forms.get(0));
    j.waitUntilNoActivity();
    // We cannot assume that the process will contain builds because the process added to base project is different to the one in derived.
    final JobPropertyImpl jobProperty = inheritanceProjectsPair.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    assertNotNull("derived jobProperty is null", jobProperty);
    final PromotionProcess fooDerived = jobProperty.getItem("foo");
    ManualApproval approval = b1.getAction(ManualApproval.class);
    assertNotNull(approval);
    SortedMap<Integer, Promotion> builds = fooDerived.getBuildsAsMap();
    assertNotNull(builds);
    assertEquals(1, builds.size());
    // Re-Execute approved promotion
    page = j.createWebClient().getPage(b1, "promotion");
    forms = getFormsByName(page, "build");
    assertFalse(forms.isEmpty());
    assertEquals(1, forms.size());
    form = forms.get(0);
    parameters = getFormParameters(form);
    assertEquals(parameters.size(), condition.getParameterDefinitions().size());
    for (HtmlElement param : parameters) {
        HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
        v.setAttribute("value", v.getAttribute("value") + "2");
    }
    j.submit(form);
    j.waitUntilNoActivity();
    final JobPropertyImpl jobProperty2 = inheritanceProjectsPair.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                  because that version of the plugin uses inheritance only for certain predefined cases: 
                  -specific methods on the call stack
                  -url paths.
                  This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
                 */
    IMode.INHERIT_FORCED);
    assertNotNull("derived jobProperty is null", jobProperty2);
    final PromotionProcess fooDerived2 = jobProperty2.getItem("foo");
    builds = fooDerived2.getBuildsAsMap();
    assertEquals(2, builds.size());
    List<ManualApproval> actions = b1.getActions(ManualApproval.class);
    assertEquals(1, actions.size());
    PromotedBuildAction buildActions = b1.getAction(PromotedBuildAction.class);
    int buildIndex = 1;
    String valueSufix = "1";
    List<Promotion> promotions = new ArrayList<Promotion>();
    promotions.addAll(builds.values());
    Collections.reverse(promotions);
    for (Promotion build : promotions) {
        List<ParameterDefinition> values = build.getParameterDefinitionsWithValue();
        assertEquals(values.size(), condition.getParameterDefinitions().size());
        for (ParameterDefinition v : values) {
            assertTrue(v instanceof StringParameterDefinition);
            String pvalue = ((StringParameterDefinition) v).getDefaultValue();
            assertTrue(pvalue.endsWith(valueSufix));
        }
        buildIndex++;
        valueSufix += buildIndex;
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) ArrayList(java.util.ArrayList) Promotion(hudson.plugins.promoted_builds.Promotion) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Aggregations

HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)21 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)20 Test (org.junit.Test)14 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)7 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)5 WebClient (com.gargoylesoftware.htmlunit.WebClient)4 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)4 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)4 Page (com.gargoylesoftware.htmlunit.Page)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 Descriptor (hudson.model.Descriptor)3 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)3 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)3 Issue (org.jvnet.hudson.test.Issue)3 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)2 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)2 HtmlDivision (com.gargoylesoftware.htmlunit.html.HtmlDivision)2