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());
}
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());
}
Aggregations