Skip to content

Commit

Permalink
add serializer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chathuranga-jayanath-99 committed Dec 8, 2024
1 parent be72bef commit ffb50b7
Showing 1 changed file with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,78 @@ public void test() throws Exception {
OMElement serializedResponse = HTTPEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue("Endpoint not serialized!", compare(serializedResponse, inputElement));
}

public void testCreateEndpointDefinitionWithErrorHandling() throws Exception {

String inputXml = "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" +
"<http method=\"GET\" uri-template=\"http://localhost:3000/banks\">" +
"<timeout>" +
"<duration>1000</duration>" +
"<responseAction>discard</responseAction>" +
"</timeout>" +
"<suspendOnFailure>" +
"<errorCodes>403</errorCodes>" +
"<progressionFactor>1</progressionFactor>" +
"</suspendOnFailure>" +
"</http>" +
"</endpoint>";
OMElement inputElement = AXIOMUtil.stringToOM(inputXml);
HTTPEndpoint endpoint = (HTTPEndpoint) HTTPEndpointFactory.getEndpointFromElement(inputElement, true, null);
OMElement serializedResponse = HTTPEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue("Endpoint definition with error handling not serialized!", compare(serializedResponse, inputElement));
}

public void testCreateEndpointDefinitionWithCompleteErrorHandling() throws Exception {

String inputXml = "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" +
"<http method=\"GET\" uri-template=\"http://localhost:3000/banks\">" +
"<timeout>" +
"<duration>200</duration>" +
"<responseAction>discard</responseAction>" +
"</timeout>" +
"<suspendOnFailure>" +
"<errorCodes>403</errorCodes>" +
"<initialDuration>10</initialDuration>" +
"<maximumDuration>10</maximumDuration>" +
"<progressionFactor>2</progressionFactor>" +
"</suspendOnFailure>" +
"<markForSuspension>" +
"<errorCodes>304</errorCodes>"+
"<retriesBeforeSuspension>10</retriesBeforeSuspension>" +
"<retryDelay>5</retryDelay>" +
"</markForSuspension>" +
"</http>" +
"</endpoint>";
OMElement inputElement = AXIOMUtil.stringToOM(inputXml);
HTTPEndpoint endpoint = (HTTPEndpoint) HTTPEndpointFactory.getEndpointFromElement(inputElement, true, null);
OMElement serializedResponse = HTTPEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue("Endpoint definition with complete error handling not serialized!", compare(serializedResponse, inputElement));
}

public void testCreateEndpointDefinitionWithDynamicErrorHandling() throws Exception {

String inputXml = "<endpoint xmlns=\"http://ws.apache.org/ns/synapse\">" +
"<http method=\"GET\" uri-template=\"http://localhost:3000/banks\">" +
"<timeout>" +
"<duration>{get-property('timeoutDuration')}</duration>" +
"<responseAction>{get-property('timeoutAction')}</responseAction>" +
"</timeout>" +
"<suspendOnFailure>" +
"<errorCodes>{get-property('suspendErrorCodes')}</errorCodes>" +
"<initialDuration>{get-property('suspendInitialDuration')}</initialDuration>" +
"<maximumDuration>{get-property('suspendMaximumDuration')}</maximumDuration>" +
"<progressionFactor>{get-property('suspendProgressionFactor')}</progressionFactor>" +
"</suspendOnFailure>" +
"<markForSuspension>" +
"<errorCodes>{get-property('retryErrorCodes')}</errorCodes>"+
"<retriesBeforeSuspension>{get-property('retryCount')}</retriesBeforeSuspension>" +
"<retryDelay>{get-property('retryDelay')}</retryDelay>" +
"</markForSuspension>" +
"</http>" +
"</endpoint>";
OMElement inputElement = AXIOMUtil.stringToOM(inputXml);
HTTPEndpoint endpoint = (HTTPEndpoint) HTTPEndpointFactory.getEndpointFromElement(inputElement, true, null);
OMElement serializedResponse = HTTPEndpointSerializer.getElementFromEndpoint(endpoint);
assertTrue("Endpoint definition with dynamic error handling not serialized!", compare(serializedResponse, inputElement));
}
}

0 comments on commit ffb50b7

Please sign in to comment.