MessageSelectorBuilder { public Map<String, String> toKeyValueMap() { Map<String, String> valueMap = new HashMap<String, String>(); String[] tokens; if (selectorString.contains(" AND")) { String[] chunks = selectorString.split(" AND"); for (String chunk : chunks) { tokens = escapeEqualsFromXpathNodeTest(chunk).split("="); valueMap.put(unescapeEqualsFromXpathNodeTest(tokens[0].trim()), tokens[1].trim().substring(1, tokens[1].trim().length() -1)); } } else { tokens = escapeEqualsFromXpathNodeTest(selectorString).split("="); valueMap.put(unescapeEqualsFromXpathNodeTest(tokens[0].trim()), tokens[1].trim().substring(1, tokens[1].trim().length() -1)); } return valueMap; } MessageSelectorBuilder(String selectorString); static String build(String messageSelector, Map<String, Object> messageSelectorMap, TestContext context); static MessageSelectorBuilder withString(String selectorString); static MessageSelectorBuilder fromKeyValueMap(Map<String, Object> valueMap); Map<String, String> toKeyValueMap(); String build();  }
@Test public void testToKeyValueMap() { Map<String, String> headerMap = MessageSelectorBuilder.withString("foo = 'bar'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 1L); Assert.assertTrue(headerMap.containsKey("foo")); Assert.assertEquals(headerMap.get("foo"), "bar"); headerMap = MessageSelectorBuilder.withString("foo = 'bar' AND operation = 'foo'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 2L); Assert.assertTrue(headerMap.containsKey("foo")); Assert.assertEquals(headerMap.get("foo"), "bar"); Assert.assertTrue(headerMap.containsKey("operation")); Assert.assertEquals(headerMap.get("operation"), "foo"); headerMap = MessageSelectorBuilder.withString("foo='bar' AND operation='foo'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 2L); Assert.assertTrue(headerMap.containsKey("foo")); Assert.assertEquals(headerMap.get("foo"), "bar"); Assert.assertTrue(headerMap.containsKey("operation")); Assert.assertEquals(headerMap.get("operation"), "foo"); headerMap = MessageSelectorBuilder.withString("foo='bar' AND operation='foo' AND foobar='true'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 3L); Assert.assertTrue(headerMap.containsKey("foo")); Assert.assertEquals(headerMap.get("foo"), "bar"); Assert.assertTrue(headerMap.containsKey("operation")); Assert.assertEquals(headerMap.get("operation"), "foo"); Assert.assertTrue(headerMap.containsKey("foobar")); Assert.assertEquals(headerMap.get("foobar"), "true"); headerMap = MessageSelectorBuilder.withString("A='Avalue' AND B='Bvalue' AND N='Nvalue'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 3L); Assert.assertTrue(headerMap.containsKey("A")); Assert.assertEquals(headerMap.get("A"), "Avalue"); Assert.assertTrue(headerMap.containsKey("B")); Assert.assertEquals(headerMap.get("B"), "Bvalue"); Assert.assertTrue(headerMap.containsKey("N")); Assert.assertEquals(headerMap.get("N"), "Nvalue"); headerMap = MessageSelectorBuilder.withString("foo='OPERAND' AND bar='ANDROID'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 2L); Assert.assertTrue(headerMap.containsKey("foo")); Assert.assertEquals(headerMap.get("foo"), "OPERAND"); Assert.assertTrue(headerMap.containsKey("bar")); Assert.assertEquals(headerMap.get("bar"), "ANDROID"); headerMap = MessageSelectorBuilder.withString("foo='ANDROID'").toKeyValueMap(); Assert.assertEquals(headerMap.size(), 1L); Assert.assertTrue(headerMap.containsKey("foo")); Assert.assertEquals(headerMap.get("foo"), "ANDROID"); headerMap = MessageSelectorBuilder.withString("xpath: Assert.assertEquals(headerMap.size(), 2L); Assert.assertTrue(headerMap.containsKey("xpath: Assert.assertEquals(headerMap.get("xpath: Assert.assertTrue(headerMap.containsKey("operation")); Assert.assertEquals(headerMap.get("operation"), "foo"); }