Petals-BC-REST 2.5.0+

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

Changes (6)

View Page History
public void requestWithMetadata() throws Exception {

assertJBIRequestJSON("reset-metadatas-by-json-with-metadatas-expected-request.json", OPERATION_UNDER_TEST,
assertJBIRequestJSON(API_BASE_URL + "/library/" + LIBRARY_ID + "/document/" + DOCUMENT_ID,
"reset-metadatas-by-json-with-metadatas-expected-request.json", OPERATION_UNDER_TEST,
MEPConstants.IN_OUT_PATTERN, "reset-metadatas-by-json-with-metadatas-request.xml");
}
public void requestWithMetadata() throws Exception {

assertJBIRequestXML("reset-metadatas-by-xml-with-metadatas-expected-request.xml", OPERATION_UNDER_TEST,
assertJBIRequestXML(API_BASE_URL + "/library/" + LIBRARY_ID + "/document/" + DOCUMENT_ID,
"reset-metadatas-by-xml-with-metadatas-expected-request.xml", OPERATION_UNDER_TEST,
MEPConstants.IN_OUT_PATTERN, "reset-metadatas-by-xml-with-metadatas-request.xml");
}
{code}

h3. Assertion 'assertJBIRequestForm'

This assertion validates the transformation of the given JBI request into the given HTTP request with *URL-encoded form data".

The parameters of this assertion are:
* {{expectedURI}}: The expected URI of the generated HTTP request,
* {{expectedHttpBodyResourceName}}: Name of the resource containing the expected HTTP request body,
* {{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,

Example:
{code}
@ServiceOperationUnderTestExtension(
operation = @ServiceOperationName(
namespace = NAMESPACE, name = "archive-form-data"),
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 assertJBIRequestFormData_nominal() throws Exception {

assertJBIRequestForm(
URI.create(API_BASE_URL + "/item/" + FILENAME),
"archive-form-data-expected-request.txt"
OPERATION_ARCHIVE_UNDER_TEST,
Message.MEPConstants.ROBUST_IN_ONLY_PATTERN,
RESOURCES_HOME + "request.xml");
}
{code}

h3. Assertion 'assertJBIRequestMultiPart'

{code}

h3. Example

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

@ClassRule
public static final ServiceOperationUnderTest OPERATION_UNDER_TEST = new ServiceOperationUnderTest(
OP_GET_METADATA_BY_JSON);

@Test
public void nominal() throws Exception {
assertJBIOutResponse("get-metadata-expected-nominal-response.xml", OPERATION_UNDER_TEST,
HttpStatus.SC_OK, null, "get-metadata-nominal-http-body.json",
MediaType.APPLICATION_JSON_TYPE, null);
}

@Test
public void nometadata() throws Exception {
assertJBIOutResponse("get-metadata-expected-no-metadata-response.xml", OPERATION_UNDER_TEST,
HttpStatus.SC_OK, null, "get-metadata-no-metadata-http-body.json",
MediaType.APPLICATION_JSON_TYPE, null);
}

@Test
public void unexistingDocument() throws Exception {

assertJBIFault("get-metadata-expected-fault-unexisting-document.xml", OPERATION_UNDER_TEST,
HttpStatus.SC_NOT_FOUND, null, null, null, "get-metadata-by-json-request.xml", null);
}
}
{code}

In the service unit JBI descriptor, the response transformations are described for each operation. The JUnit rule {{ServiceOperationUnderTest}} represents one of these operations, and the response transformation processing is the same than the one of the component. This JUnit rule is used to execute the transformation on a given HTTP response through assertions {{assertJBIOutResponse}} or {{assertJBIFault}}. For each assertion, the transformation result is compared to the content of the given resource. Following part of the HTTP response used as input of the transformation can be set:
* the HTTP status,
* a resource name containing the HTTP body,
* the content type of the HTTP body,
* a resource name containing the JBI IN message payload,
* URI parameters.

See the Javadoc for more details on parameters.

h1. Know problems