Search in sources :

Example 1 with FormFields

use of org.opennms.protocols.http.FormFields in project opennms by OpenNMS.

the class ContentTest method testFormUrlencodedContent.

/**
     * Test Form Urlencoded content.
     *
     * @throws Exception the exception
     */
@Test
public void testFormUrlencodedContent() throws Exception {
    String xml = "<request method='POST'>\n" + "  <parameter name='retries' value='3'/>\n" + "  <parameter name='timeout' value='5000'/>\n" + "  <header name='User-Agent' value='Chrome'/>\n" + "  <header name='Host' value='{nodeLabel}'/>\n" + "  <content type='application/x-www-form-urlencoded'><![CDATA[\n" + "    <form-fields>\n" + "      <form-field name='firstName'>Alejandro</form-field>\n" + "      <form-field name='lastName'>Galue</form-field>\n" + "    </form-fields>\n" + "  ]]></content>\n" + "</request>";
    Request request = JaxbUtils.unmarshal(Request.class, xml);
    Assert.assertNotNull(request);
    Assert.assertEquals("Chrome", request.getHeaders().get(0).getValue());
    Assert.assertEquals("3", request.getParameters().get(0).getValue());
    Assert.assertEquals("application/x-www-form-urlencoded", request.getContent().getType());
    FormFields fields = JaxbUtils.unmarshal(FormFields.class, request.getContent().getData());
    Assert.assertNotNull(fields);
    Assert.assertNotNull(fields.getEntity());
    Assert.assertEquals("Alejandro", fields.get(0).getValue());
}
Also used : FormFields(org.opennms.protocols.http.FormFields) Request(org.opennms.protocols.xml.config.Request) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 FormFields (org.opennms.protocols.http.FormFields)1 Request (org.opennms.protocols.xml.config.Request)1