use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class ValidateMediatorTest method testMultipleKeys.
/**
* Test with multiple keys including static and dynamic keys
*
* @param num number from 0 to 1
* @throws Exception Exception in case of an error in tests
*/
private void testMultipleKeys(int num) throws Exception {
String xsdKeyValue = null;
String path;
SynapseXPath xpath;
// create a validate mediator
ValidateMediator validate = new ValidateMediator();
// default source, xsdFile, and state of key (dynamic or static)
String source = "";
String xsdFile = "";
boolean isDynamicKey = true;
// based on source, different xsdFiles can be used
if (num == 0) {
source = VALID_ENVELOPE;
xsdKeyValue = "xsd-key";
isDynamicKey = false;
xsdFile = "validate";
} else if (num == 1) {
source = DYNAMIC_KEY_ENVELOPE;
// xsdFile = "dynamic_key1.xsd";
xsdKeyValue = "DynamicXsdKey";
isDynamicKey = true;
xsdFile = "validate3";
}
if (isDynamicKey) {
// set the schema url using dynamic key (Xpath)
path = "//m0:CheckPriceRequest/m0:" + xsdKeyValue;
xpath = new SynapseXPath(path);
xpath.addNamespace("m0", "http://services.samples/xsd");
validate.setSchemaKeys(createKeyListFromDynamicKey(xpath));
} else {
// set the schema url using static key
validate.setSchemaKeys(createKeyListFromStaticKey(xsdKeyValue));
}
MessageContext synCtx = new TestMessageContextBuilder().setRequireAxis2MessageContext(true).addFileEntry(xsdKeyValue, "./../../repository/conf/sample/resources/validate/" + xsdFile + ".xsd").setBodyFromString(source).build();
test(validate, synCtx, false);
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class ValidateMediatorTest method createXPath.
private SynapseXPath createXPath(String expression) throws JaxenException {
SynapseXPath xpath = new SynapseXPath(expression);
xpath.addNamespace("m0", "http://services.samples/xsd");
xpath.addNamespace("m1", "http://services.samples/xsd2");
return xpath;
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class RecipientListEndpointTest method testSendToDynamicMembers.
/**
* Test on Sending messages to a dynamic EP based on an expression
*
* @throws Exception on test failure
*/
@Test
public void testSendToDynamicMembers() throws Exception {
// perform init
Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(2);
recipientListEndpoint.init(synapseEnvironment);
Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext());
// add dynamic EPs
Value dynamicEPs = new Value(new SynapseXPath("//endpoints"));
recipientListEndpoint.setDynamicEnpointSet(dynamicEPs);
// test send message
String samplePayload = "<test><endpoints>http://localhost:9000/services/SimpleStockQuoteService," + "http://localhost:9001/services/SimpleStockQuoteService" + "</endpoints><body>wso2</body></test>";
Axis2MessageContext messageContext = getMessageContext(samplePayload);
// message will be sent to EP using this env (which is mocked and do nothing)
messageContext.setEnvironment(synapseEnvironment);
// messageContext.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService"));
recipientListEndpoint.sendMessage(messageContext);
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class AnnotatedCommandMediatorTest method testNamspaces.
public void testNamspaces() throws Exception {
AnnotatedCommandMediator m = new AnnotatedCommandMediator();
m.setCommand(AnnotatedCommand.class);
SynapseXPath ax = m.afterFields.get(AnnotatedCommand.class.getDeclaredField("ReadAndUpdateField"));
assertEquals(1, ax.getNamespaces().size());
assertEquals("http://myns", ax.getNamespaces().values().iterator().next());
assertEquals("myns", ax.getNamespaces().keySet().iterator().next());
ax = m.afterFields.get(AnnotatedCommand.class.getDeclaredField("nsTest1"));
assertEquals(2, ax.getNamespaces().size());
assertTrue(ax.getNamespaces().keySet().contains("myns"));
assertTrue(ax.getNamespaces().keySet().contains("ns"));
assertTrue(ax.getNamespaces().values().contains("http://myns"));
assertTrue(ax.getNamespaces().values().contains("http://ns"));
ax = m.afterFields.get(AnnotatedCommand.class.getDeclaredField("nsTest2"));
assertEquals(2, ax.getNamespaces().size());
assertTrue(ax.getNamespaces().keySet().contains("myns"));
assertTrue(ax.getNamespaces().keySet().contains("xns"));
assertTrue(ax.getNamespaces().values().contains("http://myns"));
assertTrue(ax.getNamespaces().values().contains("http://xns"));
}
use of org.apache.synapse.util.xpath.SynapseXPath in project wso2-synapse by wso2.
the class FilterMediatorTest method testFilterConditionWithThenElseKey.
public void testFilterConditionWithThenElseKey() throws Exception {
setFilterConditionPassed(false);
// create a new filter mediator
FilterMediator filter = new FilterMediator();
// set source xpath condition to //symbol
SynapseXPath source = new SynapseXPath("//wsx:symbol");
source.addNamespace("wsx", "http://www.webserviceX.NET/");
filter.setSource(source);
// set regex to MSFT
Pattern regex = Pattern.compile("MSFT");
filter.setRegex(regex);
MessageContext msgCtx = TestUtils.getTestContext(REQ);
SequenceMediator seq = new SequenceMediator();
seq.setName("refSeq");
seq.addChild(testMediator);
msgCtx.getConfiguration().addSequence("refSeq", testMediator);
filter.setElseKey("refSeq");
// test validate mediator, with static enveope
filter.mediate(msgCtx);
assertTrue(filterConditionPassed);
}
Aggregations