Search in sources :

Example 11 with Request

use of org.opennms.protocols.xml.config.Request 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)

Example 12 with Request

use of org.opennms.protocols.xml.config.Request in project opennms by OpenNMS.

the class ContentTest method testXmlContent.

/**
     * Test XML content.
     *
     * @throws Exception the exception
     */
@Test
public void testXmlContent() 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/xml'><![CDATA[\n" + "    <person><firstName>Alejandro</firstName><lastName>Galue</lastName></person>\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/xml", request.getContent().getType());
    String subXml = request.getContent().getData();
    Assert.assertNotNull(subXml);
    Person p = JaxbUtils.unmarshal(Person.class, subXml);
    Assert.assertEquals("Alejandro", p.getFirstName());
}
Also used : Request(org.opennms.protocols.xml.config.Request) Test(org.junit.Test)

Aggregations

Request (org.opennms.protocols.xml.config.Request)12 Test (org.junit.Test)6 XmlSource (org.opennms.protocols.xml.config.XmlSource)4 DateTime (org.joda.time.DateTime)3 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)3 CollectionException (org.opennms.netmgt.collection.api.CollectionException)3 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2 Sftp3gppUrlConnection (org.opennms.protocols.sftp.Sftp3gppUrlConnection)2 Content (org.opennms.protocols.xml.config.Content)2 VTDNav (com.ximpleware.VTDNav)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 JSONObject (net.sf.json.JSONObject)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 FormFields (org.opennms.protocols.http.FormFields)1