Petals-BC-REST 2.5.0+

compared with
Current by Christophe DENEUX
on Feb 21, 2024 15:44.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (1)

View Page History
* {{assertJBIRequestMultiPart}}: The result of the transformation from JBI to a HTTP request is expected as a given HTTP URI and a HTTP multi-part request similar to the given parts.

h3. Assertion 'assertJBIRequestMultiPart'

This assertion validates the transformation of the given JBI request into the given HTTP *multi-part* request.

The parameters of this assertion are:
* {{expectedURI}}: The expected URI of the generated HTTP request,
* {{expectedFormParts}}: The form parts of the generated HTTP request,
* {{opUnderTest}}: The service operation under test generating the HTTP request. The configuration of this service operation is given in the service unit JBI descriptor,
* {{mep}}: The message exchange pattern with which the JBI request send to the service operation under test,
* {{inXMLPayloadResourceName}}: Name of the resource containing the XML payload of the JBI request sent to the service operation under test,
* {{inAttachments}}: Attachments of the JBI request sent to the service operation under test,
* {{uriParameterValues}}: Values of URI parameters in expected HTTP request. Can be {{null}} if not used in generation of the HTTP request.

Example:
{code}
@ServiceOperationUnderTestExtension(
operation = @ServiceOperationName(
namespace = NAMESPACE, name = "archive"),
placeholders = { @Placeholder(
name = "api-base.url", value = API_BASE_URL) },
suJbiDescriptorResourceName = RESOURCES_HOME + "jbi.xml"
)
public static ServiceOperationUnderTest OPERATION_ARCHIVE_UNDER_TEST;

@Test
public void assertJBIRequestMultipartFormData_nominal() throws Exception {

final String filename = "first.txt";
final String fileContent = "This is a text!";
final ByteArrayDataSource fileSource = new ByteArrayDataSource(new ByteArrayInputStream(fileContent.getBytes()),
ContentType.TEXT_PLAIN.getMimeType());
fileSource.setName(filename);

final FormBodyPart expectedPartFile = FormBodyPartBuilder.create()
.setName("file")
.setBody(new InputStreamBody(new ByteArrayInputStream(fileContent.getBytes()), ContentType.TEXT_PLAIN, filename))
.build();
final FormBodyPart expectedPartDuration = FormBodyPartBuilder.create()
.setName("duration")
.setBody(new StringBody("P2Y6M5DT12H35M30S", ContentType.TEXT_PLAIN))
.build();

assertJBIRequestMultiPart(
URI.create(API_BASE_URL + "/item/" + FILENAME),
new FormBodyPart[] {
expectedPartFile,
expectedPartDuration },
OPERATION_ARCHIVE_UNDER_TEST,
Message.MEPConstants.ROBUST_IN_ONLY_PATTERN,
RESOURCES_HOME + "request.xml",
new JUnitRestJBIAttachment[] {
new JUnitRestJBIAttachment(filename, new DataHandler(fileSource)) });
}
{code}

h3. Example

{code:lang=java}
import static org.ow2.petals.binding.rest.junit.Assert.assertJBIFault;